diff --git a/examples/dcs/list_restore_records.py b/examples/dcs/list_restore_records.py index dd70fa558..b93d9185e 100644 --- a/examples/dcs/list_restore_records.py +++ b/examples/dcs/list_restore_records.py @@ -1,24 +1,24 @@ -#!/usr/bin/env python3 -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -List all Restore Records of a Distributed Message Service instance -""" -import openstack - -openstack.enable_logging(True) -conn = openstack.connect(cloud='otc') - - -instance = 'instance_id' -for rr in conn.dcs.restore_records(instance): - print(rr) +#!/usr/bin/env python3 +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" +List all Restore Records of a Distributed Message Service instance +""" +import openstack + +openstack.enable_logging(True) +conn = openstack.connect(cloud='otc') + + +instance = 'instance_id' +for rr in conn.dcs.restore_records(instance): + print(rr) diff --git a/otcextensions/sdk/dcs/v1/_proxy.py b/otcextensions/sdk/dcs/v1/_proxy.py index 86d5ec72b..d58c54227 100644 --- a/otcextensions/sdk/dcs/v1/_proxy.py +++ b/otcextensions/sdk/dcs/v1/_proxy.py @@ -72,14 +72,10 @@ def update_instance(self, instance, **attrs): :returns: The updated instance :rtype: :class:`~otcextensions.sdk.dcs.v1.instance.Instance` """ - res = self._get_resource(_instance.Instance, instance, **attrs) - res = res.update( - self, - has_body=False - ) - # NOTE: unfortunately we need to refetch object, since update - # does not return it - return self._get(_instance.Instance, res) + # Update method does not return the instance object which needs to be + # fetched additionally in return statement. + self._update(_instance.Instance, instance, **attrs) + return self._get(_instance.Instance, instance) def delete_instance(self, instance, ignore_missing=True): """Delete an instance diff --git a/otcextensions/sdk/dcs/v1/instance.py b/otcextensions/sdk/dcs/v1/instance.py index 143ea085e..1eee6c4ad 100644 --- a/otcextensions/sdk/dcs/v1/instance.py +++ b/otcextensions/sdk/dcs/v1/instance.py @@ -121,22 +121,53 @@ class Instance(resource.Resource): @classmethod def find(cls, session, name_or_id, ignore_missing=True, **params): + """Find a resource by its name or id. + + :param session: The session to use for making this request. + :type session: :class:`~keystoneauth1.adapter.Adapter` + :param name_or_id: This resource's identifier, if needed by + the request. The default is ``None``. + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be + raised when the resource does not exist. + When set to ``True``, None will be returned when + attempting to find a nonexistent resource. + :param dict params: Any additional parameters to be passed into + underlying methods, such as to + :meth:`~openstack.resource.Resource.existing` + in order to pass on URI parameters. + + :return: The :class:`Resource` object matching the given name or id + or None if nothing matches. + :raises: :class:`openstack.exceptions.DuplicateResource` if more + than one resource is found for this request. + :raises: :class:`openstack.exceptions.ResourceNotFound` if nothing + is found and ignore_missing is ``False``. + """ + session = cls._get_session(session) + # Try to short-circuit by looking directly for a matching ID. try: match = cls.existing( id=name_or_id, + connection=session._get_connection(), **params) - return match.get(session) + return match.fetch(session, **params) + + # Ecosystems: + # Add additional Exceptions to avoid abort of find method except (exceptions.NotFoundException, exceptions.HttpException, exceptions.MethodNotSupported, exceptions.BadRequestException): session.log.warn('Please specify instance ID if known for ' 'better performance') + if ('name' in cls._query_mapping._mapping.keys() + and 'name' not in params): + params['name'] = name_or_id + data = cls.list(session, **params) result = cls._get_one_match(name_or_id, data) - # Update result with URL parameters if result is not None: - result._update(**params) return result if ignore_missing: diff --git a/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py b/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py index e002084ca..eb7025c54 100644 --- a/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py +++ b/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py @@ -80,14 +80,6 @@ def test_update_instance(self): 'VALUE', a='b' ) - self.sot.update.assert_called_with( - self.proxy, - has_body=False - ) - self.proxy._get.assert_called_with( - _instance.Instance, - self.sot - ) def test_extend_instance(self): self.sot = _instance.Instance()