summaryrefslogtreecommitdiffstats
path: root/snaps/openstack
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-12 11:14:57 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-13 08:05:14 -0600
commite6326cd5e826d19e4dd2b096c17aff35da1757b3 (patch)
treef86cbf32d0660cddc802b7cd381afe264ee78033 /snaps/openstack
parentf5f0f1cbcb757a9229a92c3a7f4ea400db11dd07 (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')
-rw-r--r--snaps/openstack/create_instance.py17
-rw-r--r--snaps/openstack/tests/create_instance_tests.py8
-rw-r--r--snaps/openstack/utils/neutron_utils.py19
-rw-r--r--snaps/openstack/utils/nova_utils.py2
-rw-r--r--snaps/openstack/utils/tests/neutron_utils_tests.py2
5 files changed, 25 insertions, 23 deletions
diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py
index 99ab87c..c970a31 100644
--- a/snaps/openstack/create_instance.py
+++ b/snaps/openstack/create_instance.py
@@ -298,13 +298,13 @@ class OpenStackVmInstance:
if subnet:
# Take IP of subnet if there is one configured on which to place
# the floating IP
- for fixed_ip in port['port']['fixed_ips']:
+ for fixed_ip in port.fixed_ips:
if fixed_ip['subnet_id'] == subnet['subnet']['id']:
ip = fixed_ip['ip_address']
break
else:
# Simply take the first
- ip = port['port']['fixed_ips'][0]['ip_address']
+ ip = port.ips[0]['ip_address']
if ip:
count = timeout / poll_interval
@@ -363,7 +363,6 @@ class OpenStackVmInstance:
"""
port = self.get_port_by_name(port_name)
if port:
- port_dict = port['port']
if subnet_name:
subnet = neutron_utils.get_subnet_by_name(self.__neutron,
subnet_name)
@@ -372,13 +371,12 @@ class OpenStackVmInstance:
'not be located with name - %s',
subnet_name)
return None
- for fixed_ip in port_dict['fixed_ips']:
+ for fixed_ip in port.ips:
if fixed_ip['subnet_id'] == subnet['subnet']['id']:
return fixed_ip['ip_address']
else:
- fixed_ips = port_dict['fixed_ips']
- if fixed_ips and len(fixed_ips) > 0:
- return fixed_ips[0]['ip_address']
+ if port.ips and len(port.ips) > 0:
+ return port.ips[0]['ip_address']
return None
def get_port_mac(self, port_name):
@@ -392,8 +390,7 @@ class OpenStackVmInstance:
"""
port = self.get_port_by_name(port_name)
if port:
- port_dict = port['port']
- return port_dict['mac_address']
+ return port.mac_address
return None
def get_port_by_name(self, port_name):
@@ -450,7 +447,7 @@ class OpenStackVmInstance:
:param ip: The IP on which to apply the playbook.
:return: the return value from ansible
"""
- port_ip = port['port']['fixed_ips'][0]['ip_address']
+ port_ip = port.ips[0]['ip_address']
variables = {
'floating_ip': ip,
'nic_name': nic_name,
diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py
index dc8d79b..a13a38c 100644
--- a/snaps/openstack/tests/create_instance_tests.py
+++ b/snaps/openstack/tests/create_instance_tests.py
@@ -988,10 +988,10 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase):
port = self.inst_creator.get_port_by_name(port_settings.name)
self.assertIsNotNone(port)
- self.assertIsNotNone(port['port'].get('allowed_address_pairs'))
- self.assertEqual(1, len(port['port']['allowed_address_pairs']))
- validation_utils.objects_equivalent(pair, port['port'][
- 'allowed_address_pairs'][0])
+ self.assertIsNotNone(port.allowed_address_pairs)
+ self.assertEqual(1, len(port.allowed_address_pairs))
+ validation_utils.objects_equivalent(pair,
+ port.allowed_address_pairs[0])
def test_set_allowed_address_pairs_bad_mac(self):
"""
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