def convert_vm_mob_ref_to_attr_hash(vm_mob_ref)
return nil unless vm_mob_ref
props = vm_mob_ref.collect!(*ATTR_TO_PROP.values.uniq)
Hash[ATTR_TO_PROP.map { |k,v| [k.to_s, props[v]] }].tap do |attrs|
attrs['id'] ||= vm_mob_ref._ref
attrs['mo_ref'] = vm_mob_ref._ref
if attrs['hypervisor'].kind_of?(RbVmomi::VIM::HostSystem)
begin
host = attrs['hypervisor']
attrs['datacenter'] = parent_attribute(host.path, :datacenter)[1]
attrs['cluster'] = parent_attribute(host.path, :cluster)[1]
attrs['hypervisor'] = host.name
attrs['resource_pool'] = (vm_mob_ref.resourcePool || host.resourcePool).name rescue nil
rescue
attrs['hypervisor'] = nil
end
end
attrs['mac_addresses'] = vm_mob_ref.macs rescue nil
attrs['path'] = "/"+vm_mob_ref.parent.path.map(&:last).join('/') rescue nil
attrs['relative_path'] = (attrs['path'].split('/').reject {|e| e.empty?} - ["Datacenters", attrs['datacenter'], "vm"]).join("/") rescue nil
end
end