VMware: Add utility method to retrieve remote objects
Added a utility method that can retrieve the properties of objects that are within a parent object in the vCenter server. With existing utility methods, this is not possible without making multiple api calls. This patch partially re-adds the changes reverted by change-id Ia3a6e3f502282d44473d4908f68d71a97167e85f. Change-Id: I9a461b2cdde906d4f25af513b4c0410b35e82209
This commit is contained in:
parent
d5c60434ab
commit
8205093350
@ -40,6 +40,12 @@ def _fake_get_object_properties_missing(vim, collector, mobj,
|
||||
|
||||
class VMwareVIMUtilTestCase(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(VMwareVIMUtilTestCase, self).setUp()
|
||||
fake.reset(vc=True)
|
||||
self.vim = fake.FakeVim()
|
||||
self.vim._login()
|
||||
|
||||
def test_get_dynamic_properties_missing(self):
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'nova.virt.vmwareapi.vim_util.get_object_properties',
|
||||
@ -97,3 +103,15 @@ class VMwareVIMUtilTestCase(test.NoDBTestCase):
|
||||
res = vim_util.get_dynamic_properties('fake-vim', 'fake-obj',
|
||||
'fake-type', 'fake-property')
|
||||
self.assertEqual({}, res)
|
||||
|
||||
def test_get_inner_objects(self):
|
||||
property = ['summary.name']
|
||||
# Get the fake datastores directly from the cluster
|
||||
cluster_refs = fake._get_object_refs('ClusterComputeResource')
|
||||
cluster = fake._get_object(cluster_refs[0])
|
||||
expected_ds = cluster.datastore.ManagedObjectReference
|
||||
# Get the fake datastores using inner objects utility method
|
||||
result = vim_util.get_inner_objects(
|
||||
self.vim, cluster_refs[0], 'datastore', 'Datastore', property)
|
||||
datastores = [oc.obj for oc in result.objects]
|
||||
self.assertEqual(expected_ds, datastores)
|
||||
|
@ -1245,11 +1245,27 @@ class FakeVim(object):
|
||||
for obj in objs:
|
||||
try:
|
||||
obj_ref = obj.obj
|
||||
# This means that we are doing a search for the managed
|
||||
# data objects of the type in the inventory
|
||||
if obj_ref == "RootFolder":
|
||||
# This means that we are retrieving props for all managed
|
||||
# data objects of the specified 'type' in the entire
|
||||
# inventory. This gets invoked by vim_util.get_objects.
|
||||
mdo_refs = _db_content[type]
|
||||
elif obj_ref.type != type:
|
||||
# This means that we are retrieving props for the managed
|
||||
# data objects in the parent object's 'path' property.
|
||||
# This gets invoked by vim_util.get_inner_objects
|
||||
# eg. obj_ref = <ManagedObjectReference of a cluster>
|
||||
# type = 'DataStore'
|
||||
# path = 'datastore'
|
||||
# the above will retrieve all datastores in the given
|
||||
# cluster.
|
||||
parent_mdo = _db_content[obj_ref.type][obj_ref]
|
||||
path = obj.selectSet[0].path
|
||||
mdo_refs = parent_mdo.get(path).ManagedObjectReference
|
||||
else:
|
||||
# This means that we are retrieving props of the given
|
||||
# managed data object. This gets invoked by
|
||||
# vim_util.get_properties_for_a_collection_of_objects.
|
||||
mdo_refs = [obj_ref]
|
||||
|
||||
for mdo_ref in mdo_refs:
|
||||
|
@ -217,6 +217,26 @@ def get_objects(vim, type, properties_to_collect=None, all=False):
|
||||
specSet=[property_filter_spec], options=options)
|
||||
|
||||
|
||||
def get_inner_objects(vim, base_obj, path, inner_type,
|
||||
properties_to_collect=None, all=False):
|
||||
"""Gets the list of inner objects of the type specified."""
|
||||
client_factory = vim.client.factory
|
||||
base_type = base_obj._type
|
||||
traversal_spec = build_traversal_spec(client_factory, 'inner', base_type,
|
||||
path, False, [])
|
||||
object_spec = build_object_spec(client_factory, base_obj, [traversal_spec])
|
||||
property_spec = build_property_spec(client_factory, type=inner_type,
|
||||
properties_to_collect=properties_to_collect,
|
||||
all_properties=all)
|
||||
property_filter_spec = build_property_filter_spec(client_factory,
|
||||
[property_spec], [object_spec])
|
||||
options = client_factory.create('ns0:RetrieveOptions')
|
||||
options.maxObjects = CONF.vmware.maximum_objects
|
||||
return vim.RetrievePropertiesEx(
|
||||
vim.get_service_content().propertyCollector,
|
||||
specSet=[property_filter_spec], options=options)
|
||||
|
||||
|
||||
def cancel_retrieve(vim, token):
|
||||
"""Cancels the retrieve operation."""
|
||||
return vim.CancelRetrievePropertiesEx(
|
||||
|
Loading…
Reference in New Issue
Block a user