diff options
author | spisarski <s.pisarski@cablelabs.com> | 2017-08-03 10:57:49 -0600 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2017-08-03 10:57:49 -0600 |
commit | a5c556141ec9123422a5f372545219b5bb0a59ee (patch) | |
tree | c8aa014fb9e1ac137447bef5450845c909189873 /snaps/openstack/utils/neutron_utils.py | |
parent | 3688eb42266a2a96a16eb140eebf6f86a7bc126b (diff) |
Refactored port retrieval to include PortSettigs.
Refactored neutron_utils#get_port_by_name to get_port while
adding in a port_settings object for more robust query options.
JIRA: SNAPS-162
Change-Id: I01222ad344224db94615859448ad05d8d5bc0c30
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils/neutron_utils.py')
-rw-r--r-- | snaps/openstack/utils/neutron_utils.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py index 061bc56..5789e17 100644 --- a/snaps/openstack/utils/neutron_utils.py +++ b/snaps/openstack/utils/neutron_utils.py @@ -307,18 +307,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 |