From 4be716eb27752d715ea1140b76e4a03907edd87f Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Fri, 4 Dec 2015 16:30:10 +0800 Subject: 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 Co-Authored-By: Tang Chen --- openstackclient/network/common.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'openstackclient/network/common.py') 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 -- cgit v1.2.1