Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions examples/dcs/list_restore_records.py
Original file line number Diff line number Diff line change
@@ -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')
Comment thread
vineet-pruthi marked this conversation as resolved.


instance = 'instance_id'
for rr in conn.dcs.restore_records(instance):
print(rr)
12 changes: 4 additions & 8 deletions otcextensions/sdk/dcs/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 34 additions & 3 deletions otcextensions/sdk/dcs/v1/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down