diff options
| author | Terry Howe <terrylhowe@gmail.com> | 2014-07-07 06:11:58 -0600 |
|---|---|---|
| committer | Terry Howe <terrylhowe@gmail.com> | 2014-07-07 06:11:58 -0600 |
| commit | a065dd09e4e649186710435f93a1ad0734601476 (patch) | |
| tree | e6d8cd58a4286abb84bda0c4a1d8bbeb5d4004f5 /openstackclient/network | |
| parent | b157dc937e95b7334b0c1816b6b165d080fc3be6 (diff) | |
| download | python-openstackclient-a065dd09e4e649186710435f93a1ad0734601476.tar.gz | |
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
Diffstat (limited to 'openstackclient/network')
| -rw-r--r-- | openstackclient/network/common.py | 6 |
1 files changed, 4 insertions, 2 deletions
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'] |
