diff options
| author | Jenkins <jenkins@review.openstack.org> | 2015-12-09 04:14:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2015-12-09 04:14:47 +0000 |
| commit | 805e8f89c93eef398f50659d3471454de466e686 (patch) | |
| tree | 6a5b0809114cdb2b75bcfa5b6ef081231ef2fbb7 /openstackclient/network/common.py | |
| parent | 766354990d29b6859d23894e12e1ef0c45620797 (diff) | |
| parent | 4be716eb27752d715ea1140b76e4a03907edd87f (diff) | |
| download | python-openstackclient-805e8f89c93eef398f50659d3471454de466e686.tar.gz | |
Merge "Migrate network client to SDK."
Diffstat (limited to 'openstackclient/network/common.py')
| -rw-r--r-- | openstackclient/network/common.py | 24 |
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 |
