############################################################################### # Copyright (c) 2015 Ericsson AB and others. # szilard.cserey@ericsson.com # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################### import time import os import yaml import glob import shutil from common import ( N, E, R, ArgParser, exec_cmd, parse, err, log, delete, commafy, ) DEA_1 = ''' title: Deployment Environment Adapter (DEA) # DEA API version supported version: 1.1 created: {date} comment: {comment} ''' DHA_1 = ''' title: Deployment Hardware Adapter (DHA) # DHA API version supported version: 1.1 created: {date} comment: {comment} # Adapter to use for this definition # adapter: [ipmi|libvirt] adapter: # Node list. # Mandatory properties are id and role. # All other properties are adapter specific. # For Non-Fuel nodes controlled by: # - ipmi adapter you need to provide: # pxeMac # ipmiIp # ipmiUser # ipmiPass # - libvirt adapter you need to provide: # libvirtName: # libvirtTemplate: [libvirt/vms/controller.xml | libvirt/vms/compute.xml] # # For the Fuel Node you need to provide: # libvirtName: # libvirtTemplate: libvirt/vms/fuel.xml # isFuel: yes # username: root # password: r00tme ''' DHA_2 = ''' # Adding the Fuel node as node id {node_id} # which may not be correct - please adjust as needed. ''' DISKS = {'fuel': '30G', 'controller': '30G', 'compute': '30G'} class Reap(object): def __init__(self, dea_file, dha_file, comment): self.dea_file = dea_file self.dha_file = dha_file self.comment = comment self.temp_dir = None self.env = None self.env_id = None self.last_node = None def get_env(self): env_list = parse(exec_cmd('fuel env')) if len(env_list) > 1: err('Not exactly one environment') self.env = env_list[0] self.env_id = self.env[E['id']] def download_config(self, config_type): log('Download %s config for environment %s' % (config_type, self.env_id)) exec_cmd('fuel %s --env %s --download --dir %s' % (config_type, self.env_id, self.temp_dir)) def write(self, file, text, newline=True): mode = 'a' if os.path.isfile(file) else 'w' with open(file, mode) as f: f.write('%s%s' % (text, ('\n' if newline else ''))) def write_yaml(self, file, data, newline=True): self.write(file, yaml.dump(data, default_flow_style=False).strip(), newline) def get_node_by_id(self, node_list, node_id): for node in node_list: if node[N['id']] == node_id: return node def reap_interface(self, node_id, interfaces): interface, mac = self.get_interface(node_id) if_name = None if interfaces: if_name = self.check_dict_exists(interfaces, interface) if not if_name: if_name = 'interfaces_%s' % str(len(interfaces) + 1) interfaces[if_name] = interface return if_name, mac def reap_transformation(self, node_id, roles, transformations): main_role = 'controller' if 'controller' in roles else 'compute' node_file = glob.glob('%s/deployment_%s/*%s_%s.yaml' % (self.temp_dir, self.env_id, main_role, node_id)) tr_name = None with open(node_file[0]) as f: node_config = yaml.load(f) transformation = {'transformations': node_config['network_scheme']['transformations']} if transformations: tr_name = self.check_dict_exists(transformations, transformation) if not tr_name: tr_name = 'transformations_%s' % str(len(transformations) + 1) transformations[tr_name] = transformation return tr_name def check_dict_exists(self, main_dict, dict): for key, val in main_dict.iteritems(): if cmp(dict, val) == 0: return key def reap_nodes_interfaces_transformations(self): node_list = par