diff options
Diffstat (limited to 'openstackclient/network/common.py')
| -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'] |
