diff options
Diffstat (limited to 'nova/virt/vmwareapi/vm_util.py')
-rw-r--r-- | nova/virt/vmwareapi/vm_util.py | 142 |
1 files changed, 5 insertions, 137 deletions
diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index cbeea889e5..f6e3e7adf2 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -30,7 +30,6 @@ from nova.openstack.common import log as logging from nova.openstack.common import units from nova import utils from nova.virt.vmwareapi import constants -from nova.virt.vmwareapi import ds_util from nova.virt.vmwareapi import error_util from nova.virt.vmwareapi import vim_util @@ -689,6 +688,11 @@ def _get_allocated_vnc_ports(session): return vnc_ports +# NOTE(mdbooth): this convenience function is temporarily duplicated in +# ds_util. The correct fix is to handle paginated results as they are returned +# from the relevant vim_util function. However, vim_util is currently +# effectively deprecated as we migrate to oslo.vmware. This duplication will be +# removed when we fix it properly in oslo.vmware. def _get_token(results): """Get the token from the property results.""" return getattr(results, 'token', None) @@ -1011,142 +1015,6 @@ def propset_dict(propset): return dict([(prop.name, prop.val) for prop in propset]) -def _select_datastore(data_stores, best_match, datastore_regex=None): - """Find the most preferable datastore in a given RetrieveResult object. - - :param data_stores: a RetrieveResult object from vSphere API call - :param best_match: the current best match for datastore - :param datastore_regex: an optional regular expression to match names - :return: datastore_ref, datastore_name, capacity, freespace - """ - - # data_stores is actually a RetrieveResult object from vSphere API call - for obj_content in data_stores.objects: - # the propset attribute "need not be set" by returning API - if not hasattr(obj_content, 'propSet'): - continue - - propdict = propset_dict(obj_content.propSet) - # Local storage identifier vSphere doesn't support CIFS or - # vfat for datastores, therefore filtered - ds_type = propdict['summary.type'] - ds_name = propdict['summary.name'] - if ((ds_type == 'VMFS' or ds_type == 'NFS') and - propdict.get('summary.accessible')): - if datastore_regex is None or datastore_regex.match(ds_name): - new_ds = ds_util.Datastore( - ref=obj_content.obj, - name=ds_name, - capacity=propdict['summary.capacity'], - freespace=propdict['summary.freeSpace']) - # favor datastores with more free space - if (best_match is None or - new_ds.freespace > best_match.freespace): - best_match = new_ds - - return best_match - - -def get_datastore(session, cluster=None, host=None, datastore_regex=None): - """Get the datastore list and choose the most preferable one.""" - if cluster is None and host is None: - data_stores = session._call_method(vim_util, "get_objects", - "Datastore", ["summary.type", "summary.name", - "summary.capacity", "summary.freeSpace", - "summary.accessible"]) - else: - if cluster is not None: - datastore_ret = session._call_method( - vim_util, - "get_dynamic_property", cluster, - "ClusterComputeResource", "datastore") - else: - datastore_ret = session._call_method( - vim_util, - "get_dynamic_property", host, - "HostSystem", "datastore") - - if not datastore_ret: - raise exception.DatastoreNotFound() - data_store_mors = datastore_ret.ManagedObjectReference - data_stores = session._call_method(vim_util, - "get_properties_for_a_collection_of_objects", - "Datastore", data_store_mors, - ["summary.type", "summary.name", - "summary.capacity", "summary.freeSpace", - "summary.accessible"]) - best_match = None - while data_stores: - best_match = _select_datastore(data_stores, best_match, - datastore_regex) - token = _get_token(data_stores) - if not token: - break - data_stores = session._call_method(vim_util, - "continue_to_get_objects", - token) - if best_match: - return best_match - if datastore_regex: - raise exception.DatastoreNotFound( - _("Datastore regex %s did not match any datastores") - % datastore_regex.pattern) - else: - raise exception.DatastoreNotFound() - - -def _get_allowed_datastores(data_stores, datastore_regex, allowed_types): - allowed = [] - for obj_content in data_stores.objects: - # the propset attribute "need not be set" by returning API - if not hasattr(obj_content, 'propSet'): - continue - - propdict = propset_dict(obj_content.propSet) - # Local storage identifier vSphere doesn't support CIFS or - # vfat for datastores, therefore filtered - ds_type = propdict['summary.type'] - ds_name = propdict['summary.name'] - if (propdict['summary.accessible'] and ds_type in allowed_types): - if datastore_regex is None or datastore_regex.match(ds_name): - allowed.append({'ref': obj_content.obj, 'name': ds_name}) - - return allowed - - -def get_available_datastores(session, cluster=None, datastore_regex=None): - """Get the datastore list and choose the first local storage.""" - if cluster: - mobj = cluster - resource_type = "ClusterComputeResource" - else: - mobj = get_host_ref(session) - resource_type = "HostSystem" - ds = session._call_method(vim_util, "get_dynamic_property", mobj, - resource_type, "datastore") - if not ds: - return [] - data_store_mors = ds.ManagedObjectReference - # NOTE(garyk): use utility method to retrieve remote objects - data_stores = session._call_method(vim_util, - "get_properties_for_a_collection_of_objects", - "Datastore", data_store_mors, - ["summary.type", "summary.name", "summary.accessible"]) - - allowed = [] - while data_stores: - allowed.extend(_get_allowed_datastores(data_stores, datastore_regex, - ['VMFS', 'NFS'])) - token = _get_token(data_stores) - if not token: - break - - data_stores = session._call_method(vim_util, - "continue_to_get_objects", - token) - return allowed - - def get_vmdk_backed_disk_uuid(hardware_devices, volume_uuid): if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice": hardware_devices = hardware_devices.VirtualDevice |