2 # Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
3 # and others. All rights reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # This utility makes it easy to create OpenStack objects
25 from keystoneauth1.exceptions import Unauthorized
27 from snaps import file_utils
28 from snaps.config.flavor import FlavorConfig
29 from snaps.config.image import ImageConfig
30 from snaps.config.keypair import KeypairConfig
31 from snaps.config.network import PortConfig, NetworkConfig
32 from snaps.config.project import ProjectConfig
33 from snaps.config.qos import QoSConfig
34 from snaps.config.router import RouterConfig
35 from snaps.config.security_group import SecurityGroupConfig
36 from snaps.config.user import UserConfig
37 from snaps.config.vm_inst import VmInstanceConfig
38 from snaps.config.volume import VolumeConfig
39 from snaps.config.volume_type import VolumeTypeConfig
40 from snaps.openstack.create_flavor import OpenStackFlavor
41 from snaps.openstack.create_image import OpenStackImage
42 from snaps.openstack.create_keypairs import OpenStackKeypair
43 from snaps.openstack.create_network import OpenStackNetwork
44 from snaps.openstack.create_project import OpenStackProject
45 from snaps.openstack.create_qos import OpenStackQoS
46 from snaps.openstack.create_router import OpenStackRouter
47 from snaps.openstack.create_security_group import OpenStackSecurityGroup
48 from snaps.openstack.create_user import OpenStackUser
49 from snaps.openstack.create_volume import OpenStackVolume
50 from snaps.openstack.create_volume_type import OpenStackVolumeType
51 from snaps.openstack.os_credentials import OSCreds, ProxySettings
52 from snaps.openstack.utils import deploy_utils, neutron_utils, keystone_utils
53 from snaps.openstack.utils.nova_utils import RebootType
54 from snaps.provisioning import ansible_utils
56 logger = logging.getLogger('lanuch_utils')
57 DEFAULT_CREDS_KEY = 'admin'
60 def launch_config(config, tmplt_file, deploy, clean, clean_image):
62 Launches all objects and applies any configured ansible playbooks
63 :param config: the environment configuration dict object
64 :param tmplt_file: the path to the SNAPS-OO template file
65 :param deploy: when True deploy
66 :param clean: when True clean
67 :param clean_image: when True clean the image when clean is True
69 os_config = config.get('openstack')
75 networks_dict = dict()
77 os_creds_dict = dict()
80 os_creds_dict = __get_creds_dict(os_config)
83 projects_dict = __create_instances(
84 os_creds_dict, OpenStackProject, ProjectConfig,
85 os_config.get('projects'), 'project', clean)
86 creators.append(projects_dict)
89 users_dict = __create_instances(
90 os_creds_dict, OpenStackUser, UserConfig,
91 os_config.get('users'), 'user', clean)
92 creators.append(users_dict)
94 # Associate new users to projects
96 for project_creator in projects_dict.values():
97 users = project_creator.project_settings.users
98 for user_name in users:
99 user_creator = users_dict.get(user_name)
101 project_creator.assoc_user(
102 user_creator.get_user())
105 flavors_dict = __create_instances(
106 os_creds_dict, OpenStackFlavor, FlavorConfig,
107 os_config.get('flavors'), 'flavor', clean, users_dict)
108 creators.append(flavors_dict)
111 qos_dict = __create_instances(
112 os_creds_dict, OpenStackQoS, QoSConfig,
113 os_config.get('qos_specs'), 'qos_spec', clean, users_dict)
114 creators.append(qos_dict)
116 # Create volume types
117 vol_type_dict = __create_instances(
118 os_creds_dict, OpenStackVolumeType, VolumeTypeConfig,
119 os_config.get('volume_types'), 'volume_type', clean,
121 creators.append(vol_type_dict)
124 vol_dict = __create_instances(
125 os_creds_dict, OpenStackVolume, VolumeConfig,
126 os_config.get('volumes'), 'volume', clean, users_dict)
127 creators.append(vol_dict)
130 images_dict = __create_instances(
131 os_creds_dict, OpenStackImage, ImageConfig,
132 os_config.get('images'), 'image', clean, users_dict)
133 creators.append(images_dict)
136 networks_dict = __create_instances(
137 os_creds_dict, OpenStackNetwork, NetworkConfig,
138 os_config.get('networks'), 'network', clean, users_dict)
139 creators.append(networks_dict)
142 routers_dict = __create_instances(
143 os_creds_dict, OpenStackRouter, RouterConfig,
144 os_config.get('routers'), 'router', clean, users_dict)
145 creators.append(routers_dict)
148 keypairs_dict = __create_instances(
149 os_creds_dict, OpenStackKeypair, KeypairConfig,
150 os_config.get('keypairs'), 'keypair', clean, users_dict)
151 creators.append(keypairs_dict)
153 # Create security groups
154 creators.append(__create_instances(
155 os_creds_dict, OpenStackSecurityGroup,
157 os_config.get('security_groups'), 'security_group', clean,
161 vm_dict = __create_vm_instances(
162 os_creds_dict, users_dict, os_config.get('instances'),
163 images_dict, keypairs_dict, clean)
164 creators.append(vm_dict)
166 'Completed creating/retrieving all configured instances')
168 # Must enter either block
170 # Cleanup Environment
171 __cleanup(creators, clean_image)
174 ansible_config = config.get('ansible')
175 if ansible_config and vm_dict:
176 if not __apply_ansible_playbooks(
177 ansible_config, os_creds_dict, vm_dict, images_dict,
178 flavors_dict, networks_dict, routers_dict, tmplt_file):
179 logger.error("Problem applying ansible playbooks")
182 def __get_creds_dict(os_conn_config):
184 Returns a dict of OSCreds where the key is the creds name.
185 For backwards compatibility, credentials not contained in a list (only
186 one) will be returned with the key of None
187 :param os_conn_config: the credential configuration
188 :return: a dict of OSCreds objects
190 if 'connection' in os_conn_config:
191 return {DEFAULT_CREDS_KEY: __get_os_credentials(os_conn_config)}
192 elif 'connections' in os_conn_config:
194 for os_conn_dict in os_conn_config['connections']:
195 config = os_conn_dict.get('connection')
197 raise Exception('Invalid connection format')
199 name = config.get('name')
201 raise Exception('Connection config requires a name field')
203 out[name] = __get_os_credentials(os_conn_dict)
207 def __get_creds(os_creds_dict, os_user_dict, inst_config):
209 Returns the appropriate credentials
210 :param os_creds_dict: a dictionary of OSCreds objects where the name is the
212 :param os_user_dict: a dictionary of OpenStackUser objects where the name
215 :return: an OSCreds instance or None
217 os_creds = os_creds_dict.get(DEFAULT_CREDS_KEY)
218 if 'os_user' in inst_config:
219 os_user_conf = inst_config['os_user']
220 if 'name' in os_user_conf:
221 user_creator = os_user_dict.get(os_user_conf['name'])
223 return user_creator.get_os_creds(
224 project_name=os_user_conf.get('project_name'))
225 elif 'os_creds_name' in inst_config:
226 if 'os_creds_name' in inst_config:
227 os_creds = os_creds_dict[inst_config['os_creds_name']]
231 def __get_os_credentials(os_conn_config):
233 Returns an object containing all of the information required to access
235 :param os_conn_config: The configuration holding the credentials
236 :return: an OSCreds instance
238 config = os_conn_config.get('connection')
240 raise Exception('Invalid connection configuration')
242 proxy_settings = None
243 http_proxy = config.get('http_proxy')
245 tokens = re.split(':', http_proxy)
246 ssh_proxy_cmd = config.get('ssh_proxy_cmd')
247 proxy_settings = ProxySettings(host=tokens[0], port=tokens[1],
248 ssh_proxy_cmd=ssh_proxy_cmd)
250 if 'proxy_settings' in config:
251 host = config['proxy_settings'].get('host')
252 port = config['proxy_settings'].get('port')
253 if host and host != 'None' and port and port != 'None':
254 proxy_settings = ProxySettings(**config['proxy_settings'])
257 config['proxy_settings'] = proxy_settings
259 if config.get('proxy_settings'):
260 del config['proxy_settings']
262 return OSCreds(**config)
265 def __parse_ports_config(config):
267 Parses the "ports" configuration
268 :param config: The dictionary to parse
269 :return: a list of PortConfig objects
272 for port_config in config:
273 out.append(PortConfig(**port_config.get('port')))
277 def __create_instances(os_creds_dict, creator_class, config_class, config,
278 config_key, cleanup=False, os_users_dict=None):
280 Returns a dictionary of SNAPS creator objects where the key is the name
281 :param os_creds_dict: Dictionary of OSCreds objects where the key is the
283 :param config: The list of configurations for the same type
284 :param config_key: The list of configurations for the same type
285 :param cleanup: Denotes whether or not this is being called for cleanup
291 for config_dict in config:
292 inst_config = config_dict.get(config_key)
294 creds = __get_creds(os_creds_dict, os_users_dict, inst_config)
296 creator = creator_class(
298 config_class(**inst_config))
304 except Unauthorized as e:
306 'Unable to initialize creator [%s] - %s',
311 out[inst_config['name']] = creator
313 raise Exception('Unable to instantiate creator')
315 logger.info('Initialized configured %ss', config_key)
320 def __create_vm_instances(os_creds_dict, os_users_dict, instances_config,
321 image_dict, keypairs_dict, cleanup=False):
323 Returns a dictionary of OpenStackVmInstance objects where the key is the
325 :param os_creds_dict: Dictionary of OSCreds objects where the key is the
327 :param os_users_dict: Dictionary of OpenStackUser objects where the key is
329 :param instances_config: The list of VM instance configurations
330 :param image_dict: A dictionary of images that will probably be used to
331 instantiate the VM instance
332 :param keypairs_dict: A dictionary of keypairs that will probably be used
333 to instantiate the VM instance
334 :param cleanup: Denotes whether or not this is being called for cleanup
340 for instance_config in instances_config:
341 conf = instance_config.get('instance')
344 image_creator = image_dict.get(conf.get('imageName'))
346 instance_settings = VmInstanceConfig(
347 **instance_config['instance'])
348 kp_creator = keypairs_dict.get(
349 conf.get('keypair_name'))
353 'name']] = deploy_utils.create_vm_instance(
355 os_creds_dict, os_users_dict, conf),
357 image_creator.image_settings,
358 keypair_creator=kp_creator,
360 except Unauthorized as e:
362 logger.warn('Unable to initialize VM - %s', e)
365 raise Exception('Image creator instance not found.'
366 ' Cannot instantiate')
369 raise Exception('Image dictionary is None. Cannot '
372 raise Exception('Instance configuration is None. Cannot '
374 logger.info('Created configured instances')
379 def __apply_ansible_playbooks(ansible_configs, os_creds_dict, vm_dict,
380 image_dict, flavor_dict, networks_dict,
381 routers_dict, tmplt_file):
383 Applies ansible playbooks to running VMs with floating IPs
384 :param ansible_configs: a list of Ansible configurations
385 :param os_creds_dict: Dictionary of OSCreds objects where the key is the
387 :param vm_dict: the dictionary of newly instantiated VMs where the name is
389 :param image_dict: the dictionary of newly instantiated images where the
391 :param flavor_dict: the dictionary of newly instantiated flavors where the
393 :param networks_dict: the dictionary of newly instantiated networks where
395 :param routers_dict: the dictionary of newly instantiated routers where
397 :param tmplt_file: the path of the SNAPS-OO template file for setting the
398 CWD so playbook location is relative to the deployment
400 :return: t/f - true if successful
402 logger.info("Applying Ansible Playbooks")
404 # Set CWD so the deployment file's playbook location can leverage
406 orig_cwd = os.getcwd()
407 env_dir = os.path.dirname(tmplt_file)
411 for ansible_config in ansible_configs:
412 # Ensure all hosts are accepting SSH session requests
413 for vm_name in ansible_config['hosts']:
414 vm_inst = vm_dict.get(vm_name)
416 if not vm_inst.vm_ssh_active(block=True):
418 'Timeout waiting for instance to respond to '
422 __apply_ansible_playbook(
423 ansible_config, os_creds_dict, vm_dict, image_dict,
424 flavor_dict, networks_dict, routers_dict)
426 # Return to original directory
432 def __apply_ansible_playbook(ansible_config, os_creds_dict, vm_dict,
433 image_dict, flavor_dict, networks_dict,
436 Applies an Ansible configuration setting
437 :param ansible_config: the configuration settings
438 :param os_creds_dict: dict where the key is the name and value is OSCreds
439 :param vm_dict: the dictionary of newly instantiated VMs where the name is
441 :param image_dict: the dictionary of newly instantiated images where the
443 :param flavor_dict: the dictionary of newly instantiated flavors where the
445 :param networks_dict: the dictionary of newly instantiated networks where
447 :param routers_dict: the dictionary of newly instantiated routers where
451 (remote_user, floating_ips, private_key_filepath,
452 proxy_settings) = __get_connection_info(
453 ansible_config, vm_dict)
455 for key, vm_creator in vm_dict.items():
456 fip = vm_creator.get_floating_ip()
457 if fip and fip.ip in floating_ips:
458 if not vm_creator.cloud_init_complete(block=True):
460 'Cannot apply playbooks as cloud-init has not '
463 variables = __get_variables(
464 ansible_config.get('variables'), os_creds_dict, vm_dict,
465 image_dict, flavor_dict, networks_dict, routers_dict)
467 retval = ansible_utils.apply_playbook(
468 ansible_config['playbook_location'], floating_ips, remote_user,
469 ssh_priv_key_file_path=private_key_filepath,
471 proxy_setting=proxy_settings)
473 # Not a fatal type of event
475 'Error applying playbook found at location - %s',
476 ansible_config.get('playbook_location'))
477 elif ansible_config.get('post_processing'):
478 post_proc_config = ansible_config['post_processing']
479 if 'sleep' in post_proc_config:
480 time.sleep(post_proc_config['sleep'])
481 if 'reboot' in post_proc_config:
482 for vm_name in post_proc_config['reboot']:
483 if vm_name in vm_dict:
484 logger.info('Rebooting VM - %s', vm_name)
485 vm_dict[vm_name].reboot(RebootType.hard)
490 def __get_connection_info(ansible_config, vm_dict):
492 Returns a tuple of data required for connecting to the running VMs
493 (remote_user, [floating_ips], private_key_filepath, proxy_settings)
494 :param ansible_config: the configuration settings
495 :param vm_dict: the dictionary of VMs where the VM name is the key
496 :return: tuple where the first element is the user and the second is a list
497 of floating IPs and the third is the
498 private key file location and the fourth is an instance of the
499 snaps.ProxySettings class
500 (note: in order to work, each of the hosts need to have the same sudo_user
501 and private key file location values)
503 if ansible_config.get('hosts'):
504 hosts = ansible_config['hosts']
506 floating_ips = list()
509 proxy_settings = None
511 vm = vm_dict.get(host)
513 fip = vm.get_floating_ip()
515 remote_user = vm.get_image_user()
518 floating_ips.append(fip.ip)
521 'Could not find floating IP for VM - ' +
524 pk_file = vm.keypair_settings.private_filepath
525 proxy_settings = vm.get_os_creds().proxy_settings
527 logger.error('Could not locate VM with name - ' + host)
529 return remote_user, floating_ips, pk_file, proxy_settings
533 def __get_variables(var_config, os_creds_dict, vm_dict, image_dict,
534 flavor_dict, networks_dict, routers_dict):
536 Returns a dictionary of substitution variables to be used for Ansible
538 :param var_config: the variable configuration settings
539 :param os_creds_dict: dict where the key is the name and value is OSCreds
540 :param vm_dict: the dictionary of newly instantiated VMs where the name is
542 :param image_dict: the dictionary of newly instantiated images where the
544 :param flavor_dict: the dictionary of newly instantiated flavors where the
546 :param networks_dict: the dictionary of newly instantiated networks where
548 :param routers_dict: the dictionary of newly instantiated routers where
550 :return: dictionary or None
552 if var_config and vm_dict and len(vm_dict) > 0:
554 for key, value in var_config.items():
555 value = __get_variable_value(
556 value, os_creds_dict, vm_dict, image_dict, flavor_dict,
557 networks_dict, routers_dict)
559 variables[key] = value
561 "Set Jinga2 variable with key [%s] the value [%s]",
565 'Key - [' + str(key) + '] or Value [' + str(value)
566 + '] must not be None')
571 def __get_variable_value(var_config_values, os_creds_dict, vm_dict, image_dict,
572 flavor_dict, networks_dict, routers_dict):
574 Returns the associated variable value for use by Ansible for substitution
576 :param var_config_values: the configuration dictionary
577 :param os_creds_dict: dict where the key is the name and value is OSCreds
578 :param vm_dict: the dictionary of newly instantiated VMs where the name is
580 :param image_dict: the dictionary of newly instantiated images where the
582 :param flavor_dict: the dictionary of newly instantiated flavors where the
584 :param networks_dict: the dictionary of newly instantiated networks where
586 :param routers_dict: the dictionary of newly instantiated routers where
590 if var_config_values['type'] == 'string':
591 return __get_string_variable_value(var_config_values)
592 if var_config_values['type'] == 'vm-attr':
593 return __get_vm_attr_variable_value(var_config_values, vm_dict)
594 if var_config_values['type'] == 'os_creds':
595 return __get_os_creds_variable_value(var_config_values, os_creds_dict)
596 if var_config_values['type'] == 'os_creds_dict':
597 return str(__get_os_creds_dict(var_config_values, os_creds_dict))
598 if var_config_values['type'] == 'network':
599 return __get_network_variable_value(var_config_values, networks_dict)
600 if var_config_values['type'] == 'router':
601 return __get_router_variable_value(var_config_values, routers_dict,
603 if var_config_values['type'] == 'port':
604 return __get_vm_port_variable_value(var_config_values, vm_dict)
605 if var_config_values['type'] == 'floating_ip':
606 return __get_vm_fip_variable_value(var_config_values, vm_dict)
607 if var_config_values['type'] == 'image':
608 return __get_image_variable_value(var_config_values, image_dict)
609 if var_config_values['type'] == 'flavor':
610 return __get_flavor_variable_value(var_config_values, flavor_dict)
611 if var_config_values['type'] == 'vm-yaml':
612 return __create_yaml(var_config_values, vm_dict)
616 def __get_string_variable_value(var_config_values):
618 Returns the associated string value
619 :param var_config_values: the configuration dictionary
620 :return: the value contained in the dictionary with the key 'value'
622 return var_config_values['value']
625 def __get_vm_attr_variable_value(var_config_values, vm_dict):
627 Returns the associated value contained on a VM instance
628 :param var_config_values: the configuration dictionary
629 :param vm_dict: the dictionary containing all VMs where the key is the VM's
633 vm = vm_dict.get(var_config_values['vm_name'])
635 if var_config_values['value'] == 'floating_ip':
636 return vm.get_floating_ip().ip
637 if var_config_values['value'] == 'image_user':
638 return vm.get_image_user()
641 def __get_os_creds_variable_value(var_config_values, os_creds_dict):
643 Returns the associated OS credentials value
644 :param var_config_values: the configuration dictionary
645 :param os_creds_dict: dict of OpenStack credentials where the key is the
649 if 'creds_name' in var_config_values:
650 os_creds = os_creds_dict.get[var_config_values['creds_name']]
652 os_creds = os_creds_dict.get('admin-creds')
655 if var_config_values['value'] == 'username':
656 logger.info("Returning OS username")
657 return os_creds.username
658 elif var_config_values['value'] == 'password':
659 logger.info("Returning OS password")
660 return os_creds.password
661 elif var_config_values['value'] == 'auth_url':
662 logger.info("Returning OS auth_url")
663 return os_creds.auth_url
664 elif var_config_values['value'] == 'project_name':
665 logger.info("Returning OS project_name")
666 return os_creds.project_name
669 def __get_os_creds_dict(var_config_values, os_creds_dict):
671 Returns the associated OS credentials as a dict
672 :param var_config_values: the configuration dictionary
673 :param os_creds_dict: dict of creds where the key is the username
674 :return: the value dict
676 if 'creds_name' in var_config_values:
677 os_creds = os_creds_dict.get[var_config_values['creds_name']]
679 os_creds = os_creds_dict.get('admin-creds')
681 return os_creds.to_dict()
684 def __get_network_variable_value(var_config_values, networks_dict):
686 Returns the associated network value
687 :param var_config_values: the configuration dictionary
688 :param networks_dict: the dictionary containing all networks where the key
692 net_name = var_config_values.get('network_name')
694 if net_name and networks_dict.get(net_name):
695 network_creator = networks_dict[net_name]
697 if 'subnet_name' in var_config_values:
698 subnet_name = var_config_values.get('subnet_name')
700 for subnet in network_creator.get_network().subnets:
701 if subnet_name == subnet.name:
702 if 'value' in var_config_values:
703 if 'gateway_ip' == var_config_values['value']:
704 return subnet.gateway_ip
705 if 'ip_range' == var_config_values['value']:
706 return subnet.start + ' ' + subnet.end
707 if 'ip_range_start' == var_config_values['value']:
709 if 'ip_range_end' == var_config_values['value']:
711 if 'cidr' == var_config_values['value']:
713 if 'cidr_ip' == var_config_values['value']:
714 cidr_split = subnet.cidr.split('/')
716 if 'netmask' == var_config_values['value']:
717 cidr_split = subnet.cidr.split('/')
718 cidr_bits = 32 - int(cidr_split[1])
719 netmask = socket.inet_ntoa(
721 '!I', (1 << 32) - (1 << cidr_bits)))
723 if 'broadcast_ip' == var_config_values['value']:
724 end_split = subnet.end.split('.')
726 end_split[0] + '.' + end_split[1] + '.'
727 + end_split[2] + '.255')
731 def __get_router_variable_value(var_config_values, routers_dict,
734 Returns the associated network value
735 :param var_config_values: the configuration dictionary
736 :param routers_dict: the dictionary containing all networks where the key
738 :param os_creds_dict: dict of OpenStack credentials where the key is the
742 if 'creds_name' in var_config_values:
743 os_creds = os_creds_dict.get[var_config_values['creds_name']]
745 os_creds = os_creds_dict.get('admin-creds')
747 router_name = var_config_values.get('router_name')
748 router_creator = routers_dict[router_name]
751 if 'external_fixed_ip' == var_config_values.get('attr'):
752 session = keystone_utils.keystone_session(os_creds)
753 neutron = neutron_utils.neutron_client(os_creds, session)
755 ext_nets = neutron_utils.get_external_networks(neutron)
757 subnet_name = var_config_values.get('subnet_name')
759 for ext_net in ext_nets:
760 for subnet in ext_net.subnets:
761 if subnet_name == subnet.name:
762 router = router_creator.get_router()
763 for fixed_ips in router.external_fixed_ips:
764 if subnet.id == fixed_ips['subnet_id']:
765 return fixed_ips['ip_address']
767 keystone_utils.close_session(session)
770 def __get_vm_port_variable_value(var_config_values, vm_dict):
772 Returns the associated OS credentials value
773 :param var_config_values: the configuration dictionary
774 :param vm_dict: the dictionary containing all VMs where the key is the VM's
778 port_name = var_config_values.get('port_name')
779 vm_name = var_config_values.get('vm_name')
781 if port_name and vm_name:
782 vm = vm_dict.get(vm_name)
784 for vm_port in vm.get_vm_inst().ports:
785 if vm_port.name == port_name:
786 port_value_id = var_config_values.get('port_value')
788 if port_value_id == 'mac_address':
789 return vm_port.mac_address
790 if port_value_id == 'ip_address':
791 return vm_port.ips[0]['ip_address']
794 def __get_vm_fip_variable_value(var_config_values, vm_dict):
796 Returns the floating IP value if found
797 :param var_config_values: the configuration dictionary
798 :param vm_dict: the dictionary containing all VMs where the key is the VM's
800 :return: the floating IP string value or None
802 fip_name = var_config_values.get('fip_name')
803 vm_name = var_config_values.get('vm_name')
806 vm = vm_dict.get(vm_name)
808 fip = vm.get_floating_ip(fip_name)
813 def __get_image_variable_value(var_config_values, image_dict):
815 Returns the associated image value
816 :param var_config_values: the configuration dictionary
817 :param image_dict: the dictionary containing all images where the key is
822 if var_config_values.get('image_name'):
823 image_creator = image_dict.get(var_config_values['image_name'])
825 if (var_config_values.get('value')
826 and var_config_values['value'] == 'id'):
827 return image_creator.get_image().id
828 if (var_config_values.get('value')
829 and var_config_values['value'] == 'user'):
830 return image_creator.image_settings.image_user
833 def __get_flavor_variable_value(var_config_values, flavor_dict):
835 Returns the associated flavor value
836 :param var_config_values: the configuration dictionary
837 :param flavor_dict: the dictionary containing all flavor creators where the
839 :return: the value or None
842 if var_config_values.get('flavor_name'):
843 flavor_creator = flavor_dict.get(var_config_values['flavor_name'])
845 if (var_config_values.get('value')
846 and var_config_values['value'] == 'id'):
847 return flavor_creator.get_flavor().id
850 def __create_yaml(var_config_values, vm_dict):
852 Creates a yaml file containing an OpenStack pod's credentials with a list
853 of server IDs that can be used for obtaining SNAPS-OO instances for
854 manipulation such as rebooting
855 :param var_config_values: the configuration dictionary
856 :param vm_dict: the dictionary containing all vm creators where the
858 :return: the name of the generated file
861 out_dict['vms'] = list()
862 req_vm_names = var_config_values.get('vms')
864 for name, vm_creator in vm_dict.items():
865 vm_inst = vm_creator.get_vm_inst()
866 if vm_inst and vm_inst.name in req_vm_names:
867 out_dict['vms'].append({
868 'name': str(vm_inst.name),
869 'id': str(vm_inst.id),
870 'os_creds': vm_creator.get_os_creds().to_dict()
873 out_file = file_utils.persist_dict_to_yaml(
874 out_dict, var_config_values.get('file_name'))
880 def __cleanup(creators, clean_image=False):
882 Cleans up environment
883 :param creators: the list of creators by type
884 :param clean_image: when true
887 for creator_dict in reversed(creators):
888 for key, creator in creator_dict.items():
889 if ((isinstance(creator, OpenStackImage) and clean_image)
890 or not isinstance(creator, OpenStackImage)):