diff options
| author | Terry Howe <terrylhowe@gmail.com> | 2014-03-12 11:51:17 -0600 |
|---|---|---|
| committer | Terry Howe <terrylhowe@gmail.com> | 2014-03-28 12:33:58 -0600 |
| commit | bea6e6ac23e893a85f4b0a49bab52934aca86726 (patch) | |
| tree | 56b5da09e3a9c068b7b1e9bdf3cc08ef02e693f9 /openstackclient/identity/common.py | |
| parent | cf8506d2bdbde02a731afb16a839e0660b71a89b (diff) | |
| download | python-openstackclient-bea6e6ac23e893a85f4b0a49bab52934aca86726.tar.gz | |
Make endpoint commands more consistent
Make endpoints more consistent across create, show, etc
* Make the name option required for create
* Use a common function to fetch services by id, name or type
* Have show work by endpoint id or by service id, type or name
* Have show display all the fields by default
* Remove capability to filter queries by attribute value pairs
Change-Id: Idaa4b8d930ba859fd62de777e44a10b1ed58c79b
Partial-Bug: #1184012
Diffstat (limited to 'openstackclient/identity/common.py')
| -rw-r--r-- | openstackclient/identity/common.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/openstackclient/identity/common.py b/openstackclient/identity/common.py new file mode 100644 index 00000000..6aeaa3c3 --- /dev/null +++ b/openstackclient/identity/common.py @@ -0,0 +1,38 @@ +# Copyright 2012-2013 OpenStack Foundation +# +# 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. +# + +"""Common identity code""" + +from keystoneclient import exceptions as identity_exc +from openstackclient.common import exceptions +from openstackclient.common import utils + + +def find_service(identity_client, name_type_or_id): + """Find a service by id, name or type.""" + + try: + # search for the usual ID or name + return utils.find_resource(identity_client.services, name_type_or_id) + except exceptions.CommandError: + try: + # search for service type + return identity_client.services.find(type=name_type_or_id) + # FIXME(dtroyer): This exception should eventually come from + # common client exceptions + except identity_exc.NotFound: + msg = ("No service with a type, name or ID of '%s' exists." + % name_type_or_id) + raise exceptions.CommandError(msg) |
