X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=snaps%2Fopenstack%2Futils%2Flaunch_utils.py;h=49d41e79602d9a29592e37d3eb44f4e896477651;hb=4edc3d87392cf78c3f046217543fb76380413306;hp=abf04b58b78baf394a27fabca974b1646f870091;hpb=fd6271827bbd82fca4b5b7939da404809e82ae64;p=snaps.git diff --git a/snaps/openstack/utils/launch_utils.py b/snaps/openstack/utils/launch_utils.py index abf04b5..49d41e7 100644 --- a/snaps/openstack/utils/launch_utils.py +++ b/snaps/openstack/utils/launch_utils.py @@ -21,6 +21,7 @@ import socket import struct import os +import time from keystoneauth1.exceptions import Unauthorized from snaps.config.flavor import FlavorConfig @@ -47,7 +48,7 @@ from snaps.openstack.create_user import OpenStackUser from snaps.openstack.create_volume import OpenStackVolume from snaps.openstack.create_volume_type import OpenStackVolumeType from snaps.openstack.os_credentials import OSCreds, ProxySettings -from snaps.openstack.utils import deploy_utils, neutron_utils +from snaps.openstack.utils import deploy_utils, neutron_utils, keystone_utils from snaps.provisioning import ansible_utils logger = logging.getLogger('lanuch_utils') @@ -117,7 +118,7 @@ def launch_config(config, tmplt_file, deploy, clean, clean_image): users_dict) creators.append(vol_type_dict) - # Create volume types + # Create volumes vol_dict = __create_instances( os_creds_dict, OpenStackVolume, VolumeConfig, os_config.get('volumes'), 'volume', clean, users_dict) @@ -306,6 +307,8 @@ def __create_instances(os_creds_dict, creator_class, config_class, config, creator.create() out[inst_config['name']] = creator + else: + raise Exception('Unable to instantiate creator') logger.info('Initialized configured %ss', config_key) @@ -461,14 +464,24 @@ def __apply_ansible_playbook(ansible_config, os_creds, vm_dict, image_dict, retval = ansible_utils.apply_playbook( ansible_config['playbook_location'], floating_ips, remote_user, - private_key_filepath, + ssh_priv_key_file_path=private_key_filepath, variables=variables, proxy_setting=proxy_settings) if retval != 0: # Not a fatal type of event - logger.warning( - 'Unable to apply playbook found at location - %s', + raise Exception( + 'Error applying playbook found at location - %s', ansible_config.get('playbook_location')) + elif ansible_config.get('post_processing'): + post_proc_config = ansible_config['post_processing'] + if 'sleep' in post_proc_config: + time.sleep(post_proc_config['sleep']) + if 'reboot' in post_proc_config: + for vm_name in post_proc_config['reboot']: + if vm_name in vm_dict: + logger.info('Rebooting VM - %s', vm_name) + vm_dict[vm_name].reboot() + return retval @@ -664,6 +677,12 @@ def __get_network_variable_value(var_config_values, networks_dict): return subnet.gateway_ip if 'ip_range' == var_config_values['value']: return subnet.start + ' ' + subnet.end + if 'ip_range_start' == var_config_values['value']: + return subnet.start + if 'ip_range_end' == var_config_values['value']: + return subnet.end + if 'cidr' == var_config_values['value']: + return subnet.cidr if 'cidr_ip' == var_config_values['value']: cidr_split = subnet.cidr.split('/') return cidr_split[0] @@ -696,18 +715,22 @@ def __get_router_variable_value(var_config_values, routers_dict, os_creds): if router_creator: if 'external_fixed_ip' == var_config_values.get('attr'): - neutron = neutron_utils.neutron_client(os_creds) - ext_nets = neutron_utils.get_external_networks(neutron) - - subnet_name = var_config_values.get('subnet_name') - - for ext_net in ext_nets: - for subnet in ext_net.subnets: - if subnet_name == subnet.name: - router = router_creator.get_router() - for fixed_ips in router.external_fixed_ips: - if subnet.id == fixed_ips['subnet_id']: - return fixed_ips['ip_address'] + session = keystone_utils.keystone_session(os_creds) + neutron = neutron_utils.neutron_client(os_creds, session) + try: + ext_nets = neutron_utils.get_external_networks(neutron) + + subnet_name = var_config_values.get('subnet_name') + + for ext_net in ext_nets: + for subnet in ext_net.subnets: + if subnet_name == subnet.name: + router = router_creator.get_router() + for fixed_ips in router.external_fixed_ips: + if subnet.id == fixed_ips['subnet_id']: + return fixed_ips['ip_address'] + finally: + keystone_utils.close_session(session) def __get_vm_port_variable_value(var_config_values, vm_dict):