コード例 #1
0
ファイル: test__utils.py プロジェクト: Supriya30201/gskube
 def test_get_entity_no_use_direct_get(self):
     # test we are defaulting to the search_<resource> methods
     # if the use_direct_get flag is set to False(default).
     uuid = uuid4().hex
     resource = 'network'
     func = 'search_%ss' % resource
     filters = {}
     with mock.patch.object(self.cloud, func) as search:
         _utils._get_entity(self.cloud, resource, uuid, filters)
         search.assert_called_once_with(uuid, filters)
コード例 #2
0
 def test_get_entity_no_use_direct_get(self):
     # test we are defaulting to the search_<resource> methods
     # if the use_direct_get flag is set to False(default).
     uuid = uuid4().hex
     resource = 'network'
     func = 'search_%ss' % resource
     filters = {}
     with mock.patch.object(self.cloud, func) as search:
         _utils._get_entity(self.cloud, resource, uuid, filters)
         search.assert_called_once_with(uuid, filters)
コード例 #3
0
 def test_get_entity_pass_uuid(self):
     uuid = uuid4().hex
     self.cloud.use_direct_get = True
     resources = ['flavor', 'image', 'volume', 'network',
                  'subnet', 'port', 'floating_ip', 'security_group']
     for r in resources:
         f = 'get_%s_by_id' % r
         with mock.patch.object(self.cloud, f) as get:
             _utils._get_entity(self.cloud, r, uuid, {})
             get.assert_called_once_with(uuid)
コード例 #4
0
ファイル: test__utils.py プロジェクト: nickpfeil/Cellar
 def test_get_entity_pass_uuid(self):
     uuid = uuid4().hex
     self.cloud.use_direct_get = True
     resources = ['flavor', 'image', 'volume', 'network',
                  'subnet', 'port', 'floating_ip', 'security_group']
     for r in resources:
         f = 'get_%s_by_id' % r
         with mock.patch.object(self.cloud, f) as get:
             _utils._get_entity(self.cloud, r, uuid, {})
             get.assert_called_once_with(uuid)
コード例 #5
0
ファイル: test__utils.py プロジェクト: Supriya30201/gskube
 def test_get_entity_no_uuid_like(self):
     # test we are defaulting to the search_<resource> methods
     # if the name_or_id param is a name(string) but not a uuid.
     self.cloud.use_direct_get = True
     name = 'name_no_uuid'
     resource = 'network'
     func = 'search_%ss' % resource
     filters = {}
     with mock.patch.object(self.cloud, func) as search:
         _utils._get_entity(self.cloud, resource, name, filters)
         search.assert_called_once_with(name, filters)
コード例 #6
0
 def test_get_entity_no_uuid_like(self):
     # test we are defaulting to the search_<resource> methods
     # if the name_or_id param is a name(string) but not a uuid.
     self.cloud.use_direct_get = True
     name = 'name_no_uuid'
     resource = 'network'
     func = 'search_%ss' % resource
     filters = {}
     with mock.patch.object(self.cloud, func) as search:
         _utils._get_entity(self.cloud, resource, name, filters)
         search.assert_called_once_with(name, filters)
コード例 #7
0
 def test_get_entity_pass_search_methods(self):
     self.cloud.use_direct_get = True
     resources = ['flavor', 'image', 'volume', 'network',
                  'subnet', 'port', 'floating_ip', 'security_group']
     filters = {}
     name = 'name_no_uuid'
     for r in resources:
         f = 'search_%ss' % r
         with mock.patch.object(self.cloud, f) as search:
             _utils._get_entity(self.cloud, r, name, {})
             search.assert_called_once_with(name, filters)
コード例 #8
0
ファイル: test__utils.py プロジェクト: nickpfeil/Cellar
 def test_get_entity_pass_search_methods(self):
     self.cloud.use_direct_get = True
     resources = ['flavor', 'image', 'volume', 'network',
                  'subnet', 'port', 'floating_ip', 'security_group']
     filters = {}
     name = 'name_no_uuid'
     for r in resources:
         f = 'search_%ss' % r
         with mock.patch.object(self.cloud, f) as search:
             _utils._get_entity(self.cloud, r, name, {})
             search.assert_called_once_with(name, filters)
コード例 #9
0
    def get_stack(self, name_or_id, filters=None, resolve_outputs=True):
        """Get exactly one stack.

        :param name_or_id: Name or ID of the desired stack.
        :param filters: a dict containing additional filters to use. e.g.
                {'stack_status': 'CREATE_COMPLETE'}
        :param resolve_outputs: If True, then outputs for this
                stack will be resolved

        :returns: a ``munch.Munch`` containing the stack description

        :raises: ``OpenStackCloudException`` if something goes wrong during the
            OpenStack API call or if multiple matches are found.
        """
        def _search_one_stack(name_or_id=None, filters=None):
            # stack names are mandatory and enforced unique in the project
            # so a StackGet can always be used for name or ID.
            try:
                stack = self.orchestration.find_stack(
                    name_or_id,
                    ignore_missing=False,
                    resolve_outputs=resolve_outputs)
                if stack.status == 'DELETE_COMPLETE':
                    return []
            except exc.OpenStackCloudURINotFound:
                return []
            stack = self._normalize_stack(stack)
            return _utils._filter_list([stack], name_or_id, filters)

        return _utils._get_entity(self, _search_one_stack, name_or_id, filters)
コード例 #10
0
    def get_security_group(self, name_or_id, filters=None):
        """Get a security group by name or ID.

        :param name_or_id: Name or ID of the security group.
        :param filters:
            A dictionary of meta data to use for further filtering. Elements
            of this dictionary may, themselves, be dictionaries. Example::

                {
                  'last_name': 'Smith',
                  'other': {
                      'gender': 'Female'
                  }
                }

            OR
            A string containing a jmespath expression for further filtering.
            Example:: "[?last_name==`Smith`] | [?other.gender]==`Female`]"

        :returns: A security group ``munch.Munch`` or None if no matching
                  security group is found.

        """
        return _utils._get_entity(
            self, 'security_group', name_or_id, filters)
コード例 #11
0
    def get_coe_cluster(self, name_or_id, filters=None):
        """Get a COE cluster by name or ID.

        :param name_or_id: Name or ID of the cluster.
        :param filters:
            A dictionary of meta data to use for further filtering. Elements
            of this dictionary may, themselves, be dictionaries. Example::

                {
                  'last_name': 'Smith',
                  'other': {
                      'gender': 'Female'
                  }
                }

            OR
            A string containing a jmespath expression for further filtering.
            Example:: "[?last_name==`Smith`] | [?other.gender]==`Female`]"

        :returns: A cluster dict or None if no matching cluster is found.
        """
        return _utils._get_entity(self,
                                  'coe_cluster',
                                  name_or_id,
                                  filters=filters)
コード例 #12
0
    def get_stack(self, name_or_id, filters=None, resolve_outputs=True):
        """Get exactly one stack.

        :param name_or_id: Name or ID of the desired stack.
        :param filters: a dict containing additional filters to use. e.g.
                {'stack_status': 'CREATE_COMPLETE'}
        :param resolve_outputs: If True, then outputs for this
                stack will be resolved

        :returns: a ``munch.Munch`` containing the stack description

        :raises: ``OpenStackCloudException`` if something goes wrong during the
            OpenStack API call or if multiple matches are found.
        """

        def _search_one_stack(name_or_id=None, filters=None):
            # stack names are mandatory and enforced unique in the project
            # so a StackGet can always be used for name or ID.
            try:
                stack = self.orchestration.find_stack(
                    name_or_id,
                    ignore_missing=False,
                    resolve_outputs=resolve_outputs)
                if stack.status == 'DELETE_COMPLETE':
                    return []
            except exc.OpenStackCloudURINotFound:
                return []
            stack = self._normalize_stack(stack)
            return _utils._filter_list([stack], name_or_id, filters)

        return _utils._get_entity(
            self, _search_one_stack, name_or_id, filters)
コード例 #13
0
    def get_security_group(self, name_or_id, filters=None):
        """Get a security group by name or ID.

        :param name_or_id: Name or ID of the security group.
        :param filters:
            A dictionary of meta data to use for further filtering. Elements
            of this dictionary may, themselves, be dictionaries. Example::

                {
                  'last_name': 'Smith',
                  'other': {
                      'gender': 'Female'
                  }
                }

            OR
            A string containing a jmespath expression for further filtering.
            Example:: "[?last_name==`Smith`] | [?other.gender]==`Female`]"

        :returns: A security group ``munch.Munch`` or None if no matching
                  security group is found.

        """
        return _utils._get_entity(
            self, 'security_group', name_or_id, filters)
コード例 #14
0
    def get_volume_backup(self, name_or_id, filters=None):
        """Get a volume backup by name or ID.

        :returns: A backup ``munch.Munch`` or None if no matching backup is
                  found.
        """
        return _utils._get_entity(self, 'volume_backup', name_or_id, filters)
コード例 #15
0
    def get_volume_backup(self, name_or_id, filters=None):
        """Get a volume backup by name or ID.

        :returns: A backup ``munch.Munch`` or None if no matching backup is
                  found.
        """
        return _utils._get_entity(self, 'volume_backup', name_or_id,
                                  filters)
コード例 #16
0
    def get_zone(self, name_or_id, filters=None):
        """Get a zone by name or ID.

        :param name_or_id: Name or ID of the zone
        :param filters:
            A dictionary of meta data to use for further filtering
            OR
            A string containing a jmespath expression for further filtering.
            Example:: "[?last_name==`Smith`] | [?other.gender]==`Female`]"

        :returns:  A zone dict or None if no matching zone is found.

        """
        return _utils._get_entity(self, 'zone', name_or_id, filters)
コード例 #17
0
 def get_host(self, name_or_id, filters=None, expand=True):
     if expand:
         func = self.search_hosts
     else:
         func = functools.partial(self.search_hosts, expand=False)
     return _utils._get_entity(self, func, name_or_id, filters)
コード例 #18
0
ファイル: inventory.py プロジェクト: ctrlaltdel/neutrinator
 def get_host(self, name_or_id, filters=None, expand=True):
     if expand:
         func = self.search_hosts
     else:
         func = functools.partial(self.search_hosts, expand=False)
     return _utils._get_entity(self, func, name_or_id, filters)
コード例 #19
0
ファイル: _clustering.py プロジェクト: williamwang0/MusicGen
 def get_cluster_policy(self, name_or_id, filters=None):
     return _utils._get_entity(
         self, 'cluster_policie', name_or_id, filters)
コード例 #20
0
ファイル: _clustering.py プロジェクト: williamwang0/MusicGen
 def get_cluster_receiver(self, name_or_id, filters=None):
     return _utils._get_entity(
         self, 'cluster_receiver', name_or_id, filters)
コード例 #21
0
ファイル: _clustering.py プロジェクト: williamwang0/MusicGen
 def get_cluster(self, name_or_id, filters=None):
     return _utils._get_entity(
         cloud=self, resource='cluster',
         name_or_id=name_or_id, filters=filters)
コード例 #22
0
 def test_get_entity_pass_object(self):
     obj = mock.Mock(id=uuid4().hex)
     self.cloud.use_direct_get = True
     self.assertEqual(obj, _utils._get_entity(self.cloud, '', obj, {}))
コード例 #23
0
 def test_get_entity_pass_dict(self):
     d = dict(id=uuid4().hex)
     self.cloud.use_direct_get = True
     self.assertEqual(d, _utils._get_entity(self.cloud, '', d, {}))
コード例 #24
0
ファイル: test__utils.py プロジェクト: Supriya30201/gskube
 def test_get_entity_pass_object(self):
     obj = mock.Mock(id=uuid4().hex)
     self.cloud.use_direct_get = True
     self.assertEqual(obj, _utils._get_entity(self.cloud, '', obj, {}))
コード例 #25
0
ファイル: test__utils.py プロジェクト: ctrlaltdel/neutrinator
 def test_get_entity_pass_dict(self):
     d = dict(id=uuid4().hex)
     self.cloud.use_direct_get = True
     self.assertEqual(d, _utils._get_entity(self.cloud, '', d, {}))