summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-02-16 14:41:25 -0700
committerspisarski <s.pisarski@cablelabs.com>2017-02-17 09:28:45 -0700
commitc9394852bc178e318eecaff20e1d440af39efd0a (patch)
tree963fd075a576d244cda3afc3f4cf7d5a74a12eab
parent57777f3df521553a06cd01a3861b415d2905ceca (diff)
Added the ability to create custom flavors with the deploy_venv.py application.
JIRA: SNAPS-3 CableLabs JIRA SNAPS-155 Change-Id: Ic1c07b7d75e04578495cb2f2881798da4c2571a2 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--snaps/deploy_venv.py72
1 files changed, 55 insertions, 17 deletions
diff --git a/snaps/deploy_venv.py b/snaps/deploy_venv.py
index 05851e2..10e444f 100644
--- a/snaps/deploy_venv.py
+++ b/snaps/deploy_venv.py
@@ -21,15 +21,16 @@ import logging
import os
import re
-import file_utils
-from snaps.openstack.create_keypairs import KeypairSettings
-from snaps.openstack.create_router import RouterSettings
-from snaps.openstack.os_credentials import OSCreds, ProxySettings
+from snaps import file_utils
+from snaps.openstack.create_flavor import FlavorSettings, OpenStackFlavor
from snaps.openstack.create_image import ImageSettings
from snaps.openstack.create_instance import VmInstanceSettings
from snaps.openstack.create_network import PortSettings, NetworkSettings
-from snaps.provisioning import ansible_utils
+from snaps.openstack.create_router import RouterSettings
+from snaps.openstack.create_keypairs import KeypairSettings
+from snaps.openstack.os_credentials import OSCreds, ProxySettings
from snaps.openstack.utils import deploy_utils
+from snaps.provisioning import ansible_utils
__author__ = 'spisarski'
@@ -71,6 +72,34 @@ def __parse_ports_config(config):
return out
+def __create_flavors(os_conn_config, flavors_config, cleanup=False):
+ """
+ Returns a dictionary of flavors where the key is the image name and the value is the image object
+ :param os_conn_config: The OpenStack connection credentials
+ :param flavors_config: The list of image configurations
+ :param cleanup: Denotes whether or not this is being called for cleanup or not
+ :return: dictionary
+ """
+ flavors = {}
+
+ if flavors_config:
+ try:
+ for flavor_config_dict in flavors_config:
+ flavor_config = flavor_config_dict.get('flavor')
+ if flavor_config and flavor_config.get('name'):
+ flavor_creator = OpenStackFlavor(__get_os_credentials(os_conn_config),
+ FlavorSettings(flavor_config))
+ flavor_creator.create(cleanup=cleanup)
+ flavors[flavor_config['name']] = flavor_creator
+ except Exception as e:
+ for key, flavor_creator in flavors.iteritems():
+ flavor_creator.clean()
+ raise e
+ logger.info('Created configured flavors')
+
+ return flavors
+
+
def __create_images(os_conn_config, images_config, cleanup=False):
"""
Returns a dictionary of images where the key is the image name and the value is the image object
@@ -288,17 +317,20 @@ def __get_connection_info(ansible_config, vm_dict):
proxy_settings = None
for host in hosts:
vm = vm_dict.get(host)
- fip = vm.get_floating_ip()
- if vm and fip:
- remote_user = vm.get_image_user()
-
+ if vm:
+ fip = vm.get_floating_ip()
if fip:
- floating_ips.append(fip.ip)
- else:
- raise Exception('Could not find floating IP for VM - ' + vm.name)
+ remote_user = vm.get_image_user()
+
+ if fip:
+ floating_ips.append(fip.ip)
+ else:
+ raise Exception('Could not find floating IP for VM - ' + vm.name)
- private_key_filepath = vm.keypair_settings.private_filepath
- proxy_settings = vm.get_os_creds().proxy_settings
+ private_key_filepath = vm.keypair_settings.private_filepath
+ proxy_settings = vm.get_os_creds().proxy_settings
+ else:
+ logger.error('Could not locate VM with name - ' + host)
return remote_user, floating_ips, private_key_filepath, proxy_settings
return None
@@ -447,6 +479,10 @@ def main(arguments):
try:
os_conn_config = os_config.get('connection')
+ # Create flavors
+ flavor_dict = __create_flavors(os_conn_config, os_config.get('flavors'),
+ arguments.clean is not ARG_NOT_SET)
+
# Create images
image_dict = __create_images(os_conn_config, os_config.get('images'),
arguments.clean is not ARG_NOT_SET)
@@ -469,14 +505,14 @@ def main(arguments):
logger.info('Completed creating/retrieving all configured instances')
except Exception as e:
logger.error('Unexpected error deploying environment. Rolling back due to - ' + e.message)
- __cleanup(vm_dict, keypairs_dict, router_dict, network_dict, image_dict, True)
+ __cleanup(vm_dict, keypairs_dict, router_dict, network_dict, image_dict, flavor_dict, True)
raise e
# Must enter either block
if arguments.clean is not ARG_NOT_SET:
# Cleanup Environment
- __cleanup(vm_dict, keypairs_dict, router_dict, network_dict, image_dict,
+ __cleanup(vm_dict, keypairs_dict, router_dict, network_dict, image_dict, flavor_dict,
arguments.clean_image is not ARG_NOT_SET)
elif arguments.deploy is not ARG_NOT_SET:
logger.info('Configuring NICs where required')
@@ -496,7 +532,7 @@ def main(arguments):
exit(0)
-def __cleanup(vm_dict, keypairs_dict, router_dict, network_dict, image_dict, clean_image=False):
+def __cleanup(vm_dict, keypairs_dict, router_dict, network_dict, image_dict, flavor_dict, clean_image=False):
for key, vm_inst in vm_dict.iteritems():
vm_inst.clean()
for key, kp_inst in keypairs_dict.iteritems():
@@ -508,6 +544,8 @@ def __cleanup(vm_dict, keypairs_dict, router_dict, network_dict, image_dict, cle
if clean_image:
for key, image_inst in image_dict.iteritems():
image_inst.clean()
+ for key, flavor_inst in flavor_dict.iteritems():
+ flavor_inst.clean()
if __name__ == '__main__':