
The Oslo libraries have moved all of their code out of the 'oslo' namespace package into per-library packages. The namespace package was retained during kilo for backwards compatibility, but will be removed by the liberty-2 milestone. This change removes the use of the namespace package, replacing it with the new package names. The patches in the libraries will be put on hold until application patches have landed, or L2, whichever comes first. At that point, new versions of the libraries without namespace packages will be released as a major version update. Please merge this patch, or an equivalent, before L2 to avoid problems with those library releases. Blueprint: remove-namespace-packages https://blueprints.launchpad.net/oslo-incubator/+spec/remove-namespace-packages Change-Id: I324a3bd0c468a3e84f633497ad5c0d59c5ccc455
101 lines
3.4 KiB
Python
101 lines
3.4 KiB
Python
#
|
|
# 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.
|
|
|
|
########################################################################
|
|
#
|
|
# THIS MODULE IS DEPRECATED
|
|
#
|
|
# Please refer to
|
|
# https://etherpad.openstack.org/p/kilo-tuskarclient-library-proposals for
|
|
# the discussion leading to this deprecation.
|
|
#
|
|
# We recommend checking out the python-openstacksdk project
|
|
# (https://launchpad.net/python-openstacksdk) instead.
|
|
#
|
|
########################################################################
|
|
|
|
from oslo_utils import encodeutils
|
|
import six
|
|
|
|
from tuskarclient.openstack.common._i18n import _
|
|
from tuskarclient.openstack.common.apiclient import exceptions
|
|
from tuskarclient.openstack.common import uuidutils
|
|
|
|
|
|
def find_resource(manager, name_or_id, **find_args):
|
|
"""Look for resource in a given manager.
|
|
|
|
Used as a helper for the _find_* methods.
|
|
Example:
|
|
|
|
.. code-block:: python
|
|
|
|
def _find_hypervisor(cs, hypervisor):
|
|
#Get a hypervisor by name or ID.
|
|
return cliutils.find_resource(cs.hypervisors, hypervisor)
|
|
"""
|
|
# first try to get entity as integer id
|
|
try:
|
|
return manager.get(int(name_or_id))
|
|
except (TypeError, ValueError, exceptions.NotFound):
|
|
pass
|
|
|
|
# now try to get entity as uuid
|
|
try:
|
|
if six.PY2:
|
|
tmp_id = encodeutils.safe_encode(name_or_id)
|
|
else:
|
|
tmp_id = encodeutils.safe_decode(name_or_id)
|
|
|
|
if uuidutils.is_uuid_like(tmp_id):
|
|
return manager.get(tmp_id)
|
|
except (TypeError, ValueError, exceptions.NotFound):
|
|
pass
|
|
|
|
# for str id which is not uuid
|
|
if getattr(manager, 'is_alphanum_id_allowed', False):
|
|
try:
|
|
return manager.get(name_or_id)
|
|
except exceptions.NotFound:
|
|
pass
|
|
|
|
try:
|
|
try:
|
|
return manager.find(human_id=name_or_id, **find_args)
|
|
except exceptions.NotFound:
|
|
pass
|
|
|
|
# finally try to find entity by name
|
|
try:
|
|
resource = getattr(manager, 'resource_class', None)
|
|
name_attr = resource.NAME_ATTR if resource else 'name'
|
|
kwargs = {name_attr: name_or_id}
|
|
kwargs.update(find_args)
|
|
return manager.find(**kwargs)
|
|
except exceptions.NotFound:
|
|
msg = _("No %(name)s with a name or "
|
|
"ID of '%(name_or_id)s' exists.") % \
|
|
{
|
|
"name": manager.resource_class.__name__.lower(),
|
|
"name_or_id": name_or_id
|
|
}
|
|
raise exceptions.CommandError(msg)
|
|
except exceptions.NoUniqueMatch:
|
|
msg = _("Multiple %(name)s matches found for "
|
|
"'%(name_or_id)s', use an ID to be more specific.") % \
|
|
{
|
|
"name": manager.resource_class.__name__.lower(),
|
|
"name_or_id": name_or_id
|
|
}
|
|
raise exceptions.CommandError(msg)
|