1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[vsphere|compute] Bulk fetch all managed views VM properties

This commit is contained in:
Tejas Ravindra Mandke 2013-03-31 09:43:06 -07:00 committed by Jeff McCune
parent 81b3242335
commit 88de0d008f
2 changed files with 18 additions and 8 deletions

View file

@ -74,6 +74,8 @@ module Fog
:id => 'config.instanceUuid',
:name => 'name',
:uuid => 'config.uuid',
:template => 'config.template',
:parent => 'parent',
:hostname => 'summary.guest.hostName',
:operatingsystem => 'summary.guest.guestFullName',
:ipaddress => 'guest.ipAddress',
@ -88,6 +90,11 @@ module Fog
:guest_id => 'summary.guest.guestId',
}
def convert_vm_view_to_attr_hash(vms)
vms = @connection.serviceContent.propertyCollector.collectMultiple(vms,*ATTR_TO_PROP.values.uniq)
vms.map { |vm| props_to_attr_hash(*vm) }
end
# Utility method to convert a VMware managed object into an attribute hash.
# This should only really be necessary for the real class.
# This method is expected to be called by the request methods
@ -96,6 +103,10 @@ module Fog
return nil unless vm_mob_ref
props = vm_mob_ref.collect!(*ATTR_TO_PROP.values.uniq)
props_to_attr_hash vm_mob_ref, props
end
def props_to_attr_hash vm_mob_ref, props
# NOTE: Object.tap is in 1.8.7 and later.
# Here we create the hash object that this method returns, but first we need
# to add a few more attributes that require additional calls to the vSphere
@ -125,11 +136,10 @@ module Fog
# cloning, a call to the macs method will throw and NoMethodError
attrs['mac_addresses'] = vm_mob_ref.macs rescue nil
# Rescue nil to catch testing while vm_mob_ref isn't reaL??
attrs['path'] = "/"+vm_mob_ref.parent.path.map(&:last).join('/') rescue nil
attrs['path'] = "/"+attrs['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
# returns the parent object based on a type
# provides both real RbVmomi object and its name.
# e.g.

View file

@ -35,12 +35,12 @@ module Fog
:recursive => true
}).view
end.flatten
# remove all template based virtual machines
vms.delete_if { |v| v.config.template }
vms.map do |vm_mob|
convert_vm_mob_ref_to_attr_hash(vm_mob)
end
vms = convert_vm_view_to_attr_hash(vms)
# remove all template based virtual machines
vms.delete_if { |v| v['template'] }
vms
end
def get_folder_path(folder, root = nil)