summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/create_instance.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-13 14:34:01 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-13 14:34:01 -0600
commitde6536ff2ba4faa1a3d4ed27e93d692cae20e5d2 (patch)
tree659107105d40072d6da40d6db94c60a21171976d /snaps/openstack/create_instance.py
parentb490e8dc9fb01c6f9c44dd9a585ca1a1ae00bf19 (diff)
Created domain classes for networks and subnets.
Created Network and Subnet domain classes so neutron_utils.py functions returning these types of objects will not be leaking out implementation details as each API version can change these data structures which is now being handled by the SNAPS neutron utility. JIRA: SNAPS-113 Change-Id: Id95dd0f8c2618c20a1a73a428abb95686dfa8251 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/create_instance.py')
-rw-r--r--snaps/openstack/create_instance.py35
1 files changed, 12 insertions, 23 deletions
diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py
index 08e90c1..9aaf127 100644
--- a/snaps/openstack/create_instance.py
+++ b/snaps/openstack/create_instance.py
@@ -195,7 +195,7 @@ class OpenStackVmInstance:
self.__neutron,
router.external_gateway_info['network_id'])
if network:
- return network['network']['name']
+ return network.name
return None
def clean(self):
@@ -263,27 +263,16 @@ class OpenStackVmInstance:
ports = list()
for port_setting in port_settings:
- # First check to see if network already has this port
- # TODO/FIXME - this could potentially cause problems if another
- # port with the same name exists
- # VM has the same network/port name pair
- found = False
-
- # TODO/FIXME - should we not be iterating on ports for the specific
- # network in question as unique port names
- # seem to only be important by network
- existing_ports = self.__neutron.list_ports()['ports']
- for existing_port in existing_ports:
- if existing_port['name'] == port_setting.name:
- ports.append((port_setting.name, {'port': existing_port}))
- found = True
- break
-
- if not found and not cleanup:
- ports.append((port_setting.name,
- neutron_utils.create_port(self.__neutron,
- self.__os_creds,
- port_setting)))
+ port = neutron_utils.get_port_by_name(self.__neutron,
+ port_setting.name)
+ if port:
+ ports.append((port_setting.name, {'port': port}))
+ elif not cleanup:
+ # Exception will be raised when port with same name already
+ # exists
+ ports.append(
+ (port_setting.name, neutron_utils.create_port(
+ self.__neutron, self.__os_creds, port_setting)))
return ports
@@ -372,7 +361,7 @@ class OpenStackVmInstance:
subnet_name)
return None
for fixed_ip in port.ips:
- if fixed_ip['subnet_id'] == subnet['subnet']['id']:
+ if fixed_ip['subnet_id'] == subnet.id:
return fixed_ip['ip_address']
else:
if port.ips and len(port.ips) > 0: