summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils/neutron_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'snaps/openstack/utils/neutron_utils.py')
-rw-r--r--snaps/openstack/utils/neutron_utils.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py
index 6916033..01408fe 100644
--- a/snaps/openstack/utils/neutron_utils.py
+++ b/snaps/openstack/utils/neutron_utils.py
@@ -332,18 +332,32 @@ def delete_port(neutron, port):
neutron.delete_port(port.id)
-def get_port_by_name(neutron, port_name):
+def get_port(neutron, port_settings=None, port_name=None):
"""
- Returns the first port object (dictionary) found with a given name
+ Returns the first port object (dictionary) found for the given query
:param neutron: the client
- :param port_name: the name of the port to retrieve
+ :param port_settings: the PortSettings object used for generating the query
+ :param port_name: if port_settings is None, this name is the value to place
+ into the query
:return: a SNAPS-OO Port domain object
"""
- ports = neutron.list_ports(**{'name': port_name})
+ port_filter = dict()
+
+ if port_settings:
+ port_filter['name'] = port_settings.name
+ if port_settings.admin_state_up:
+ port_filter['admin_state_up'] = port_settings.admin_state_up
+ if port_settings.device_id:
+ port_filter['device_id'] = port_settings.device_id
+ if port_settings.mac_address:
+ port_filter['mac_address'] = port_settings.mac_address
+ elif port_name:
+ port_filter['name'] = port_name
+
+ ports = neutron.list_ports(**port_filter)
for port in ports['ports']:
- if port['name'] == port_name:
- return Port(name=port['name'], id=port['id'],
- ips=port['fixed_ips'], mac_address=port['mac_address'])
+ return Port(name=port['name'], id=port['id'],
+ ips=port['fixed_ips'], mac_address=port['mac_address'])
return None
@@ -372,7 +386,7 @@ def delete_security_group(neutron, sec_grp):
neutron.delete_security_group(sec_grp.id)
-def get_security_group(neutron, name):
+def get_security_group(neutron, name, tenant_id=None):
"""
Returns the first security group object of the given name else None
:param neutron: the client
@@ -381,7 +395,10 @@ def get_security_group(neutron, name):
"""
logger.info('Retrieving security group with name - ' + name)
- groups = neutron.list_security_groups(**{'name': name})
+ filter = {'name': name}
+ if tenant_id:
+ filter['tenant_id'] = tenant_id
+ groups = neutron.list_security_groups(**filter)
for group in groups['security_groups']:
if group['name'] == name:
return SecurityGroup(**group)