summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/create_stack.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-08-09 14:17:26 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-08-09 14:37:41 -0600
commit2b9b2d64c5be98405aaaf98db58f06b35b8af983 (patch)
tree7eac6cb5a5182371b5602e53bb613234c5eff11c /snaps/openstack/create_stack.py
parent430905e7f76e4a074167a49ca2bfbf727eebcefd (diff)
SNAPS Stack creators can now return SNAPS network creators.
As Heat Stacks are responsible for spawning objects in OpenStack, the class OpenStackHeatStack which is responsible for applying and managing the state of a stack now can retrieve OpenStackNetwork objects for the networks created in the stack for clients who would like to query the networks and subnets or update them outside of Heat. JIRA: SNAPS-171 Change-Id: I9bf0b81d4f7bfeb1b6392f345022c7d9a57d0415 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/create_stack.py')
-rw-r--r--snaps/openstack/create_stack.py76
1 files changed, 68 insertions, 8 deletions
diff --git a/snaps/openstack/create_stack.py b/snaps/openstack/create_stack.py
index 41cc725..454cb18 100644
--- a/snaps/openstack/create_stack.py
+++ b/snaps/openstack/create_stack.py
@@ -17,7 +17,10 @@ import logging
import time
from heatclient.exc import HTTPNotFound
-from snaps.openstack.utils import heat_utils
+
+from snaps.openstack.create_network import (
+ OpenStackNetwork, NetworkSettings, SubnetSettings)
+from snaps.openstack.utils import heat_utils, neutron_utils
__author__ = 'spisarski'
@@ -51,7 +54,11 @@ class OpenStackHeatStack:
"""
Creates the heat stack in OpenStack if it does not already exist and
returns the domain Stack object
- :param cleanup: Denotes whether or not this is being called for cleanup
+ :param cleanup: When true, this object is initialized only via queries,
+ else objects will be created when the queries return
+ None. The name of this parameter should be changed to
+ something like 'readonly' as the same goes with all of
+ the other creator classes.
:return: The OpenStack Stack object
"""
self.__heat_cli = heat_utils.heat_client(self.__os_creds)
@@ -132,6 +139,65 @@ class OpenStackHeatStack:
return self._stack_status_check(STATUS_CREATE_COMPLETE, block, timeout,
poll_interval)
+ def get_network_creators(self):
+ """
+ Returns a list of network creator objects as configured by the heat
+ template
+ :return: list() of OpenStackNetwork objects
+ """
+
+ neutron = neutron_utils.neutron_client(self.__os_creds)
+
+ out = list()
+ stack_networks = heat_utils.get_stack_networks(
+ self.__heat_cli, neutron, self.__stack)
+
+ for stack_network in stack_networks:
+ net_settings = self.__create_network_settings(
+ neutron, stack_network)
+ net_creator = OpenStackNetwork(self.__os_creds, net_settings)
+ out.append(net_creator)
+ net_creator.create(cleanup=True)
+
+ return out
+
+ def __create_network_settings(self, neutron, network):
+ """
+ Returns a NetworkSettings object
+ :param neutron: the neutron client
+ :param network: a SNAPS-OO Network domain object
+ :return:
+ """
+ return NetworkSettings(
+ name=network.name, network_type=network.type,
+ subnet_settings=self.__create_subnet_settings(neutron, network))
+
+ def __create_subnet_settings(self, neutron, network):
+ """
+ Returns a list of SubnetSettings objects for a given network
+ :param neutron: the OpenStack neutron client
+ :param network: the SNAPS-OO Network domain object
+ :return: a list
+ """
+ out = list()
+
+ subnets = neutron_utils.get_subnets_by_network(neutron, network)
+ for subnet in subnets:
+ kwargs = dict()
+ kwargs['cidr'] = subnet.cidr
+ kwargs['ip_version'] = subnet.ip_version
+ kwargs['name'] = subnet.name
+ kwargs['start'] = subnet.start
+ kwargs['end'] = subnet.end
+ kwargs['gateway_ip'] = subnet.gateway_ip
+ kwargs['enable_dhcp'] = subnet.enable_dhcp
+ kwargs['dns_nameservers'] = subnet.dns_nameservers
+ kwargs['host_routes'] = subnet.host_routes
+ kwargs['ipv6_ra_mode'] = subnet.ipv6_ra_mode
+ kwargs['ipv6_address_mode'] = subnet.ipv6_address_mode
+ out.append(SubnetSettings(**kwargs))
+ return out
+
def _stack_status_check(self, expected_status_code, block, timeout,
poll_interval):
"""
@@ -228,14 +294,8 @@ class StackSettingsError(Exception):
Exception to be thrown when an stack settings are incorrect
"""
- def __init__(self, message):
- Exception.__init__(self, message)
-
class StackCreationError(Exception):
"""
Exception to be thrown when an stack cannot be created
"""
-
- def __init__(self, message):
- Exception.__init__(self, message)