Esempio n. 1
0
 def _filter_by_profile(self, datastores, profile_id):
     """Filter out input datastores that do not match the given profile."""
     cf = self._session.pbm.client.factory
     hubs = pbm.convert_datastores_to_hubs(cf, datastores)
     filtered_hubs = pbm.filter_hubs_by_profile(self._session, hubs,
                                                profile_id)
     return pbm.filter_datastores_by_hubs(filtered_hubs, datastores)
Esempio n. 2
0
 def _filter_by_profile(self, datastores, profile_id):
     """Filter out input datastores that do not match the given profile."""
     cf = self._session.pbm.client.factory
     hubs = pbm.convert_datastores_to_hubs(cf, datastores)
     hubs = pbm.filter_hubs_by_profile(self._session, hubs, profile_id)
     hub_ids = [hub.hubId for hub in hubs]
     return {k: v for k, v in datastores.items() if k.value in hub_ids}
Esempio n. 3
0
 def _filter_by_profile(self, datastores, profile_id):
     """Filter out input datastores that do not match the given profile."""
     cf = self._session.pbm.client.factory
     hubs = pbm.convert_datastores_to_hubs(cf, datastores)
     filtered_hubs = pbm.filter_hubs_by_profile(self._session, hubs,
                                                profile_id)
     return pbm.filter_datastores_by_hubs(filtered_hubs, datastores)
Esempio n. 4
0
 def _filter_by_profile(self, datastores, profile_id):
     """Filter out input datastores that do not match the given profile."""
     cf = self._session.pbm.client.factory
     hubs = pbm.convert_datastores_to_hubs(cf, datastores)
     hubs = pbm.filter_hubs_by_profile(self._session, hubs, profile_id)
     hub_ids = [hub.hubId for hub in hubs]
     return {k: v for k, v in datastores.items() if k.value in hub_ids}
Esempio n. 5
0
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]
Esempio n. 6
0
    def test_convert_datastores_to_hubs(self):
        ds_values = []
        datastores = []
        for i in range(0, 10):
            value = "ds-%d" % i
            ds_values.append(value)
            datastores.append(self._create_datastore(value))

        pbm_client_factory = mock.Mock()
        pbm_client_factory.create.side_effect = lambda *args: mock.Mock()
        hubs = pbm.convert_datastores_to_hubs(pbm_client_factory, datastores)
        self.assertEqual(len(datastores), len(hubs))
        hub_ids = [hub.hubId for hub in hubs]
        self.assertEqual(set(ds_values), set(hub_ids))
Esempio n. 7
0
    def test_convert_datastores_to_hubs(self):
        ds_values = []
        datastores = []
        for i in range(0, 10):
            value = "ds-%d" % i
            ds_values.append(value)
            datastores.append(self._create_datastore(value))

        pbm_client_factory = mock.Mock()
        pbm_client_factory.create.side_effect = lambda *args: mock.Mock()
        hubs = pbm.convert_datastores_to_hubs(pbm_client_factory, datastores)
        self.assertEqual(len(datastores), len(hubs))
        hub_ids = [hub.hubId for hub in hubs]
        self.assertEqual(set(ds_values), set(hub_ids))
Esempio n. 8
0
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)
Esempio n. 9
0
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)