diff options
| author | Tang Chen <tangchen@cn.fujitsu.com> | 2015-12-04 16:30:10 +0800 |
|---|---|---|
| committer | Tang Chen <tangchen@cn.fujitsu.com> | 2015-12-09 09:30:29 +0800 |
| commit | 4be716eb27752d715ea1140b76e4a03907edd87f (patch) | |
| tree | 06284f23536f14b236b1b21fc9a17bd48df36ec2 /openstackclient/network/common.py | |
| parent | 2a2cb4f75d4b83ac821df0d3da0046d24ca5eee0 (diff) | |
| download | python-openstackclient-4be716eb27752d715ea1140b76e4a03907edd87f.tar.gz | |
Migrate network client to SDK.
The previous patches have migrate all network commands to
the new version using sdk. This patch will remove the
temporary method, and implement a new make_client() to
create sdk network client.
And also, find() in openstackclient/network/common.py must
support sdk. The logic of this function will become much
easier than before, so this patch also removes two useless
test cases of find().
This patch will also remove the patched methods in tests.
Change-Id: Ic2f7bca073beb9757172d16f95d9b82c48cbbc12
Implements: blueprint neutron-client
Co-Authored-By: Terry Howe <terrylhowe@gmail.com>
Co-Authored-By: Tang Chen <tangchen@cn.fujitsu.com>
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 |
