0
我在ruby中製作了一個腳本,該腳本使用帶有霧寶石的Vsphere API從VM中檢索信息。從具有霧中Vsphere的VM中檢索runtimeInfo(Ruby)
我想在Vsphere API中訪問VirtualMachine:VirtualMachineRuntimeInfo:runtime。
我的問題是,要訪問此資源我需要檢索VM對象。我必須在get_virtual_machine.rb文件中使用方法「get_vm_ref」,但它使用受保護的方法。
我用猴子補丁來使用這個保護功能,但我想知道是否有另一種方式(一種正確的方法)來做到這一點?
我還沒有找到另一種方式在vsphere lib從VM檢索runtimeInfo。
這裏是我的代碼:
#Load credentials
config_par1 = YAML.load_file('config_par1.yml')
#Connexion
vsphere = Fog::Compute.new(config_par1.merge({:provider => 'Vsphere'}))
#Retrieve VM id
vm_id = vsphere.list_virtual_machines.first['id']
#Here is the problem, I use a protected method in Fog to access runtimeInfo
vm = vsphere.get_vm_ref(vm_id)
#Examples
maxCpu = vm.runtime.maxCpuUsage
maxMemory = vm.runtime.maxMemoryUsage