Class: VcenterLib::VmConverter
- Inherits:
-
Object
- Object
- VcenterLib::VmConverter
- Includes:
- Logging
- Defined in:
- lib/vcenter_lib/vm_converter.rb
Overview
convert VMware managed object into a simple hash
Constant Summary collapse
- ATTRIBUTES =
[ 'name', 'config.annotation', 'config.cpuHotAddEnabled', 'config.instanceUuid', 'config.firmware', 'config.memoryHotAddEnabled', 'config.template', 'config.uuid', 'config.hardware.numCoresPerSocket', 'config.hardware.numCPU', 'config.hardware.memoryMB', 'config.guestFullName', 'config.guestId', 'config.version', 'guest.guestState', 'guest.ipAddress', 'guest.toolsStatus', 'guest.toolsVersionStatus', 'overallStatus', 'runtime.bootTime', 'runtime.connectionState', 'runtime.maxCpuUsage', 'runtime.maxMemoryUsage', 'runtime.powerState', 'summary.config.numEthernetCards', 'summary.config.numVirtualDisks', 'summary.guest.guestFullName', 'summary.guest.hostName', 'runtime.host', # 'resourcePool', # 'parent', # 'summary.quickStats', # summary: 'summary', # storage: 'storage', # devices: 'config.hardware.device', ].freeze
Instance Method Summary collapse
-
#initialize(vcenter) ⇒ VmConverter
constructor
A new instance of VmConverter.
-
#vm_mo_to_h(vm_mo, attributes = ATTRIBUTES) ⇒ Object
convert a VMware RbVmomi::VIM::ManagedObject into a simple hash.
- #vm_mos_to_h(vm_mobs, attributes = ATTRIBUTES) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(vcenter) ⇒ VmConverter
Returns a new instance of VmConverter.
49 50 51 |
# File 'lib/vcenter_lib/vm_converter.rb', line 49 def initialize(vcenter) @vcenter = vcenter end |
Instance Method Details
#vm_mo_to_h(vm_mo, attributes = ATTRIBUTES) ⇒ Object
convert a VMware RbVmomi::VIM::ManagedObject into a simple hash.
54 55 56 57 |
# File 'lib/vcenter_lib/vm_converter.rb', line 54 def vm_mo_to_h(vm_mo, attributes = ATTRIBUTES) return nil unless vm_mo props2h(vm_mo.collect!(*attributes)) end |
#vm_mos_to_h(vm_mobs, attributes = ATTRIBUTES) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vcenter_lib/vm_converter.rb', line 59 def vm_mos_to_h(vm_mobs, attributes = ATTRIBUTES) vms = @vcenter.serviceContent.propertyCollector.collectMultiple(vm_mobs, *attributes) hosts = {} # cache already known hosts here vms.map do |_vm, props| extra = {} props.delete_if do |_k, v| if v.is_a? RbVmomi::VIM::HostSystem extra = hosts[v] || {} if extra.empty? # rubocop:disable Style/RescueModifier extra['datacenter'] = attribute(v.path, RbVmomi::VIM::Datacenter) rescue nil extra['cluster'] = attribute(v.path, RbVmomi::VIM::ClusterComputeResource) rescue nil extra['hypervisor'] = v.name rescue nil # rubocop:enable Style/RescueModifier hosts[v] = extra end end end props.merge!(extra) end end |