def get_profile_id(self, profile_name): """Get vCenter profile ID for the given profile name. :param profile_name: profile name :return: vCenter profile ID :raises ProfileNotFoundException: """ if profile_name in self._profile_id_cache: LOG.debug("Returning cached ID for profile: %s.", profile_name) return self._profile_id_cache[profile_name] profile_id = pbm.get_profile_id_by_name(self._session, profile_name) if profile_id is None: LOG.error("Storage profile: %s cannot be found in vCenter.", profile_name) raise vmdk_exceptions.ProfileNotFoundException( storage_profile=profile_name) self._profile_id_cache[profile_name] = profile_id LOG.debug( "Storage profile: %(name)s resolved to vCenter profile ID: " "%(id)s.", { 'name': profile_name, 'id': profile_id }) return profile_id
def _filter_datastores_matching_storage_policy(session, datastores, storage_policy): """Get datastores matching the given storage policy. :param datastores: an iterator over objects of a RetrieveResult :param storage_policy: the storage policy name :return: an iterator to datastores conforming to the given storage policy """ profile_id = pbm.get_profile_id_by_name(session, storage_policy) if not profile_id: LOG.error("Unable to retrieve storage policy with name %s", storage_policy) return factory = session.pbm.client.factory # The hub-id is the moref-value of the datastore ds_mors = [] ref_to_oc = {} for oc in datastores: ds_mors.append(oc.obj) ref_to_oc[vim_util.get_moref_value(oc.obj)] = oc hubs = pbm.convert_datastores_to_hubs(factory, ds_mors) matching_hubs = pbm.filter_hubs_by_profile(session, hubs, profile_id) # Now we have to map back all the matching ones for hub in matching_hubs: yield ref_to_oc[hub.hubId]
def _validate_configuration(self): if CONF.vmware.pbm_enabled: if not CONF.vmware.pbm_default_policy: raise error_util.PbmDefaultPolicyUnspecified() if not pbm.get_profile_id_by_name(self._session, CONF.vmware.pbm_default_policy): raise error_util.PbmDefaultPolicyDoesNotExist() if CONF.vmware.datastore_regex: LOG.warning(_LW("datastore_regex is ignored when PBM is enabled")) self._datastore_regex = None
def _validate_configuration(self): if CONF.vmware.pbm_enabled: if not CONF.vmware.pbm_default_policy: raise error_util.PbmDefaultPolicyUnspecified() if not pbm.get_profile_id_by_name(self._session, CONF.vmware.pbm_default_policy): raise error_util.PbmDefaultPolicyDoesNotExist() if CONF.vmware.datastore_regex: LOG.warning("datastore_regex is ignored when PBM is enabled") self._datastore_regex = None
def test_get_profile_id_by_name_with_invalid_profile(self, get_all_profiles): profiles = [self._create_profile(str(i), 'profile-%d' % i) for i in range(0, 10)] get_all_profiles.return_value = profiles session = mock.Mock() profile_id = pbm.get_profile_id_by_name(session, ('profile-%s' % 11)) self.assertFalse(profile_id) get_all_profiles.assert_called_once_with(session)
def test_get_profile_id_by_name(self, get_all_profiles): profiles = [self._create_profile(str(i), 'profile-%d' % i) for i in range(0, 10)] get_all_profiles.return_value = profiles session = mock.Mock() exp_profile_id = '5' profile_id = pbm.get_profile_id_by_name(session, 'profile-%s' % exp_profile_id) self.assertEqual(exp_profile_id, profile_id) get_all_profiles.assert_called_once_with(session)
def get_profile_id(self, profile_name): """Get vCenter profile ID for the given profile name. :param profile_name: profile name :return: vCenter profile ID :raises: ProfileNotFoundException """ profile_id = pbm.get_profile_id_by_name(self._session, profile_name) if profile_id is None: LOG.error(_LE("Storage profile: %s cannot be found in vCenter."), profile_name) raise vmdk_exceptions.ProfileNotFoundException(storage_profile=profile_name) LOG.debug( "Storage profile: %(name)s resolved to vCenter profile ID: " "%(id)s.", {"name": profile_name, "id": profile_id}, ) return profile_id
def _filter_datastores_matching_storage_policy(session, data_stores, storage_policy): """Get datastores matching the given storage policy. :param data_stores: the list of retrieve result wrapped datastore objects :param storage_policy: the storage policy name :return the list of datastores conforming to the given storage policy """ profile_id = pbm.get_profile_id_by_name(session, storage_policy) if profile_id: factory = session.pbm.client.factory ds_mors = [oc.obj for oc in data_stores.objects] hubs = pbm.convert_datastores_to_hubs(factory, ds_mors) matching_hubs = pbm.filter_hubs_by_profile(session, hubs, profile_id) if matching_hubs: matching_ds = pbm.filter_datastores_by_hubs(matching_hubs, ds_mors) object_contents = [oc for oc in data_stores.objects if oc.obj in matching_ds] data_stores.objects = object_contents return data_stores LOG.error(_LE("Unable to retrieve storage policy with name %s"), storage_policy)
def _filter_datastores_matching_storage_policy(session, data_stores, storage_policy): """Get datastores matching the given storage policy. :param data_stores: the list of retrieve result wrapped datastore objects :param storage_policy: the storage policy name :return: the list of datastores conforming to the given storage policy """ profile_id = pbm.get_profile_id_by_name(session, storage_policy) if profile_id: factory = session.pbm.client.factory ds_mors = [oc.obj for oc in data_stores.objects] hubs = pbm.convert_datastores_to_hubs(factory, ds_mors) matching_hubs = pbm.filter_hubs_by_profile(session, hubs, profile_id) if matching_hubs: matching_ds = pbm.filter_datastores_by_hubs(matching_hubs, ds_mors) object_contents = [ oc for oc in data_stores.objects if oc.obj in matching_ds ] data_stores.objects = object_contents return data_stores LOG.error("Unable to retrieve storage policy with name %s", storage_policy)
def get_profile_id(self, profile_name): """Get vCenter profile ID for the given profile name. :param profile_name: profile name :return: vCenter profile ID :raises ProfileNotFoundException: """ if profile_name in self._profile_id_cache: LOG.debug("Returning cached ID for profile: %s.", profile_name) return self._profile_id_cache[profile_name] profile_id = pbm.get_profile_id_by_name(self._session, profile_name) if profile_id is None: LOG.error("Storage profile: %s cannot be found in vCenter.", profile_name) raise vmdk_exceptions.ProfileNotFoundException( storage_profile=profile_name) self._profile_id_cache[profile_name] = profile_id LOG.debug("Storage profile: %(name)s resolved to vCenter profile ID: " "%(id)s.", {'name': profile_name, 'id': profile_id}) return profile_id