Merge "VMware: Replace get_dynamic_properties with get_object_properties_dict"
This commit is contained in:
@@ -12,28 +12,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from nova import test
|
||||
from nova.tests.unit.virt.vmwareapi import fake
|
||||
from nova.virt.vmwareapi import vim_util
|
||||
|
||||
|
||||
def _fake_get_object_properties(vim, collector, mobj,
|
||||
type, properties):
|
||||
fake_objects = fake.FakeRetrieveResult()
|
||||
fake_objects.add_object(fake.ObjectContent(None))
|
||||
return fake_objects
|
||||
|
||||
|
||||
def _fake_get_object_properties_missing(vim, collector, mobj,
|
||||
type, properties):
|
||||
fake_objects = fake.FakeRetrieveResult()
|
||||
ml = [fake.MissingProperty()]
|
||||
fake_objects.add_object(fake.ObjectContent(None, missing_list=ml))
|
||||
return fake_objects
|
||||
|
||||
|
||||
class VMwareVIMUtilTestCase(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -42,12 +25,6 @@ class VMwareVIMUtilTestCase(test.NoDBTestCase):
|
||||
self.vim = fake.FakeVim()
|
||||
self.vim._login()
|
||||
|
||||
@mock.patch.object(vim_util, 'get_object_properties', return_value=None)
|
||||
def test_get_dynamic_properties_no_objects(self, mock_get_object_props):
|
||||
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
|
||||
|
||||
@@ -94,7 +94,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
respool_resource_usage.overallUsage = 2147483648
|
||||
|
||||
def fake_call_method(*args):
|
||||
if "get_dynamic_properties" in args:
|
||||
if "get_object_properties_dict" in args:
|
||||
return prop_dict
|
||||
elif "get_properties_for_a_collection_of_objects" in args:
|
||||
return fake_objects
|
||||
|
||||
@@ -22,8 +22,6 @@ from oslo_log import log as logging
|
||||
from oslo_vmware import vim_util as vutil
|
||||
import six
|
||||
|
||||
from nova.i18n import _LW
|
||||
|
||||
vmware_opts = cfg.IntOpt('maximum_objects', default=100,
|
||||
help='The maximum number of ObjectContent data '
|
||||
'objects that should be returned in a single '
|
||||
@@ -89,30 +87,6 @@ def get_object_properties(vim, collector, mobj, type, properties):
|
||||
options=options)
|
||||
|
||||
|
||||
def get_dynamic_properties(vim, mobj, type, property_names):
|
||||
"""Gets the specified properties of the Managed Object."""
|
||||
obj_content = get_object_properties(vim, None, mobj, type, property_names)
|
||||
if obj_content is None:
|
||||
return {}
|
||||
if hasattr(obj_content, 'token'):
|
||||
cancel_retrieve(vim, obj_content.token)
|
||||
property_dict = {}
|
||||
if obj_content.objects:
|
||||
if hasattr(obj_content.objects[0], 'propSet'):
|
||||
dynamic_properties = obj_content.objects[0].propSet
|
||||
if dynamic_properties:
|
||||
for prop in dynamic_properties:
|
||||
property_dict[prop.name] = prop.val
|
||||
# The object may have information useful for logging
|
||||
if hasattr(obj_content.objects[0], 'missingSet'):
|
||||
for m in obj_content.objects[0].missingSet:
|
||||
LOG.warning(_LW("Unable to retrieve value for %(path)s "
|
||||
"Reason: %(reason)s"),
|
||||
{'path': m.path,
|
||||
'reason': m.fault.localizedMessage})
|
||||
return property_dict
|
||||
|
||||
|
||||
def get_objects(vim, type, properties_to_collect=None, all=False):
|
||||
"""Gets the list of objects of the type specified."""
|
||||
return vutil.get_objects(vim, type, CONF.vmware.maximum_objects,
|
||||
@@ -141,13 +115,6 @@ def get_inner_objects(vim, base_obj, path, inner_type,
|
||||
specSet=[property_filter_spec], options=options)
|
||||
|
||||
|
||||
def cancel_retrieve(vim, token):
|
||||
"""Cancels the retrieve operation."""
|
||||
return vim.CancelRetrievePropertiesEx(
|
||||
vim.service_content.propertyCollector,
|
||||
token=token)
|
||||
|
||||
|
||||
def get_prop_spec(client_factory, spec_type, properties):
|
||||
"""Builds the Property Spec Object."""
|
||||
prop_spec = client_factory.create('ns0:PropertySpec')
|
||||
|
||||
@@ -1124,8 +1124,9 @@ def get_stats_from_cluster(session, cluster):
|
||||
vcpus = 0
|
||||
mem_info = {'total': 0, 'free': 0}
|
||||
# Get the Host and Resource Pool Managed Object Refs
|
||||
prop_dict = session._call_method(vim_util, "get_dynamic_properties",
|
||||
cluster, "ClusterComputeResource",
|
||||
prop_dict = session._call_method(vutil,
|
||||
"get_object_properties_dict",
|
||||
cluster,
|
||||
["host", "resourcePool"])
|
||||
if prop_dict:
|
||||
host_ret = prop_dict.get('host')
|
||||
|
||||
@@ -26,7 +26,6 @@ from nova.compute import vm_states
|
||||
from nova import exception
|
||||
from nova.i18n import _, _LI, _LW
|
||||
from nova.virt.vmwareapi import constants
|
||||
from nova.virt.vmwareapi import vim_util
|
||||
from nova.virt.vmwareapi import vm_util
|
||||
|
||||
CONF = cfg.CONF
|
||||
@@ -124,9 +123,10 @@ class VMwareVolumeOps(object):
|
||||
lst_properties = ["config.storageDevice.hostBusAdapter",
|
||||
"config.storageDevice.scsiTopology",
|
||||
"config.storageDevice.scsiLun"]
|
||||
prop_dict = self._session._call_method(
|
||||
vim_util, "get_dynamic_properties",
|
||||
host_mor, "HostSystem", lst_properties)
|
||||
prop_dict = self._session._call_method(vutil,
|
||||
"get_object_properties_dict",
|
||||
host_mor,
|
||||
lst_properties)
|
||||
result = (None, None)
|
||||
hbas_ret = None
|
||||
scsi_topology = None
|
||||
|
||||
Reference in New Issue
Block a user