summaryrefslogtreecommitdiff
path: root/oslo_vmware/vim_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'oslo_vmware/vim_util.py')
-rw-r--r--oslo_vmware/vim_util.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/oslo_vmware/vim_util.py b/oslo_vmware/vim_util.py
index fd43ab5..4631d7e 100644
--- a/oslo_vmware/vim_util.py
+++ b/oslo_vmware/vim_util.py
@@ -17,9 +17,15 @@
The VMware API utility module.
"""
+import logging
+
from suds import sudsobject
from oslo.utils import timeutils
+from oslo_vmware._i18n import _LW
+
+
+LOG = logging.getLogger(__name__)
def get_moref(value, type_):
@@ -316,6 +322,36 @@ def get_object_properties(vim, moref, properties_to_collect):
return retrieve_result.objects
+def get_object_properties_dict(vim, moref, properties_to_collect):
+ """Get properties of the given managed object as a dict.
+
+ :param vim: Vim object
+ :param moref: managed object reference
+ :param properties_to_collect: names of the managed object properties to be
+ collected
+ :returns: a dict of properties of the given managed object
+ :raises: VimException, VimFaultException, VimAttributeException,
+ VimSessionOverLoadException, VimConnectionException
+ """
+ obj_contents = get_object_properties(vim, moref, properties_to_collect)
+ if obj_contents is None:
+ return {}
+ property_dict = {}
+ if hasattr(obj_contents[0], 'propSet'):
+ dynamic_properties = obj_contents[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_contents[0], 'missingSet'):
+ for m in obj_contents[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_token(retrieve_result):
"""Get token from result to obtain next set of results.