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