diff options
author | spisarski <s.pisarski@cablelabs.com> | 2017-07-12 11:14:57 -0600 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2017-07-13 08:05:14 -0600 |
commit | e6326cd5e826d19e4dd2b096c17aff35da1757b3 (patch) | |
tree | f86cbf32d0660cddc802b7cd381afe264ee78033 /snaps/openstack/utils | |
parent | f5f0f1cbcb757a9229a92c3a7f4ea400db11dd07 (diff) |
Created domain class for ports.
Create Port domain class so neutron_utils.py functions returning
port objects will not be leaking out implementation details as each
API version can change these data structures and this should all be
handled by the SNAPS neutron utility.
JIRA: SNAPS-118
Change-Id: If031a094a9da284e2838691c3b3490359f710c61
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils')
-rw-r--r-- | snaps/openstack/utils/neutron_utils.py | 19 | ||||
-rw-r--r-- | snaps/openstack/utils/nova_utils.py | 2 | ||||
-rw-r--r-- | snaps/openstack/utils/tests/neutron_utils_tests.py | 2 |
3 files changed, 14 insertions, 9 deletions
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py index 0dfc61a..e1bed66 100644 --- a/snaps/openstack/utils/neutron_utils.py +++ b/snaps/openstack/utils/neutron_utils.py @@ -17,7 +17,7 @@ import logging from neutronclient.common.exceptions import NotFound from neutronclient.neutron.client import Client -from snaps.domain.network import SecurityGroup, SecurityGroupRule +from snaps.domain.network import Port, SecurityGroup, SecurityGroupRule from snaps.domain.vm_inst import FloatingIp from snaps.openstack.utils import keystone_utils @@ -280,23 +280,27 @@ def create_port(neutron, os_creds, port_settings): :param neutron: the client :param os_creds: the OpenStack credentials :param port_settings: the settings object for port configuration - :return: the port object + :return: the SNAPS-OO Port domain object """ json_body = port_settings.dict_for_neutron(neutron, os_creds) logger.info('Creating port for network with name - %s', port_settings.network_name) - return neutron.create_port(body=json_body) + os_port = neutron.create_port(body=json_body)['port'] + return Port(name=os_port['name'], id=os_port['id'], + ips=os_port['fixed_ips'], + mac_address=os_port['mac_address'], + allowed_address_pairs=os_port['allowed_address_pairs']) def delete_port(neutron, port): """ Removes an OpenStack port :param neutron: the client - :param port: the port object + :param port: the SNAPS-OO Port domain object :return: """ - logger.info('Deleting port with name ' + port['port']['name']) - neutron.delete_port(port['port']['id']) + logger.info('Deleting port with name ' + port.name) + neutron.delete_port(port.id) def get_port_by_name(neutron, port_name): @@ -309,7 +313,8 @@ def get_port_by_name(neutron, port_name): ports = neutron.list_ports(**{'name': port_name}) for port in ports['ports']: if port['name'] == port_name: - return {'port': port} + return Port(name=port['name'], id=port['id'], + ips=port['fixed_ips'], mac_address=port['mac_address']) return None diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py index ccbf3c4..1ced4d7 100644 --- a/snaps/openstack/utils/nova_utils.py +++ b/snaps/openstack/utils/nova_utils.py @@ -69,7 +69,7 @@ def create_server(nova, neutron, glance, instance_settings, image_settings, nics = [] for port in ports: kv = dict() - kv['port-id'] = port['port']['id'] + kv['port-id'] = port.id nics.append(kv) logger.info('Creating VM with name - ' + instance_settings.name) diff --git a/snaps/openstack/utils/tests/neutron_utils_tests.py b/snaps/openstack/utils/tests/neutron_utils_tests.py index 516628b..0080b57 100644 --- a/snaps/openstack/utils/tests/neutron_utils_tests.py +++ b/snaps/openstack/utils/tests/neutron_utils_tests.py @@ -901,6 +901,6 @@ def validate_port(neutron, port_obj, this_port_name): ports = neutron.list_ports() for port, port_insts in ports.items(): for inst in port_insts: - if inst['id'] == port_obj['port']['id']: + if inst['id'] == port_obj.id: return inst['name'] == this_port_name return False |