summaryrefslogtreecommitdiff
path: root/openstackclient/network/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/network/common.py')
-rw-r--r--openstackclient/network/common.py24
1 files changed, 3 insertions, 21 deletions
diff --git a/openstackclient/network/common.py b/openstackclient/network/common.py
index 31faef25..7b3f8a62 100644
--- a/openstackclient/network/common.py
+++ b/openstackclient/network/common.py
@@ -11,8 +11,6 @@
# under the License.
#
-from openstackclient.common import exceptions
-
def find(client, resource, resources, name_or_id, name_attr='name'):
"""Find a network resource
@@ -26,22 +24,6 @@ def find(client, resource, resources, name_or_id, name_attr='name'):
For example:
n = find(netclient, 'network', 'networks', 'matrix')
"""
- list_method = getattr(client, "list_%s" % resources)
-
- # Search by name
- kwargs = {name_attr: name_or_id, 'fields': 'id'}
- data = list_method(**kwargs)
- info = data[resources]
- if len(info) == 1:
- return info[0]['id']
- if len(info) > 1:
- msg = "More than one %s exists with the name '%s'."
- raise exceptions.CommandError(msg % (resource, name_or_id))
-
- # Search by id
- data = list_method(id=name_or_id, fields='id')
- info = data[resources]
- if len(info) == 1:
- return info[0]['id']
- msg = "No %s with a name or ID of '%s' exists." % (resource, name_or_id)
- raise exceptions.CommandError(msg)
+ list_method = getattr(client, "find_%s" % resource)
+ data = list_method(name_or_id, ignore_missing=False)
+ return data.id