From a065dd09e4e649186710435f93a1ad0734601476 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Mon, 7 Jul 2014 06:11:58 -0600 Subject: Allow network find to use alternate name Add the name_attr to the network find method so it can search for things like floating_ip_address for floating IP addresses rather than just id. Change-Id: I827e3745b06397a54555d1286e477bf2e05bf789 --- openstackclient/network/common.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'openstackclient/network') diff --git a/openstackclient/network/common.py b/openstackclient/network/common.py index 5ba44f7b..bd6203bd 100644 --- a/openstackclient/network/common.py +++ b/openstackclient/network/common.py @@ -14,20 +14,22 @@ from openstackclient.common import exceptions -def find(client, resource, resources, name_or_id): +def find(client, resource, resources, name_or_id, name_attr='name'): """Find a network resource :param client: network client :param resource: name of the resource :param resources: plural name of resource :param name_or_id: name or id of resource user is looking for + :param name_attr: key to the name attribute for the resource For example: n = find(netclient, 'network', 'networks', 'matrix') """ list_method = getattr(client, "list_%s" % resources) # Search for by name - data = list_method(name=name_or_id, fields='id') + kwargs = {name_attr: name_or_id, 'fields': 'id'} + data = list_method(**kwargs) info = data[resources] if len(info) == 1: return info[0]['id'] -- cgit v1.2.1