############################################################################### # 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 os import io import yaml import glob import time import shutil from ssh_client import SSHClient from common import ( err, log, exec_cmd, parse, N, E, R, delete, ) CLOUD_DEPLOY_FILE = 'deploy.py' BLADE_RESTART_TIMES = 3 class CloudDeploy(object): def __init__(self, dea, dha, fuel_ip, fuel_username, fuel_password, dea_file, fuel_plugins_conf_dir, work_dir, no_health_check, deploy_timeout, no_deploy_environment, deploy_log): self.dea = dea self.dha = dha self.fuel_ip = fuel_ip self.fuel_username = fuel_username self.fuel_password = fuel_password self.dea_file = dea_file self.updated_dea_file = ( '%s/.%s' % (os.path.dirname(self.dea_file), os.path.basename(self.dea_file))) shutil.copy2(self.dea_file, self.updated_dea_file) self.fuel_plugins_conf_dir = fuel_plugins_conf_dir self.work_dir = work_dir self.no_health_check = no_health_check self.deploy_timeout = deploy_timeout self.no_deploy_environment = no_deploy_environment self.deploy_log = deploy_log self.file_dir = os.path.dirname(os.path.realpath(__file__)) self.ssh = SSHClient(self.fuel_ip, self.fuel_username, self.fuel_password) self.node_ids = self.dha.get_node_ids() self.wanted_release = self.dea.get_property('wanted_release') self.blade_node_dict = {} self.macs_per_blade = {} def merge_plugin_config_files_to_dea_file(self): plugins_conf_dir = ( self.fuel_plugins_conf_dir if self.fuel_plugins_conf_dir else '%s/plugins_conf' % os.path.dirname(self.dea_file)) if os.path.isdir(plugins_conf_dir): with io.open(self.updated_dea_file) as stream: updated_dea = yaml.load(stream) for plugin_file in glob.glob('%s/*.yaml' % plugins_conf_dir): with io.open(plugin_file) as stream: plugin_conf = yaml.load(stream) updated_dea['settings']['editable'].update(plugin_conf) with io.open(self.updated_dea_file, 'w') as stream: yaml.dump(updated_dea, stream, default_flow_style=False) def upload_cloud_deployment_files(self): with self.ssh as s: s.exec_cmd('rm -rf %s' % self.work_dir, False) s.exec_cmd('mkdir %s' % self.work_dir) s.scp_put(self.updated_dea_file, '%s/%s' % ( self.work_dir, os.path.basename(self.dea_file))) s.scp_put('%s/common.py' % self.file_dir, self.work_dir) s.scp_put('%s/dea.py' % self.file_dir, self.work_dir) for f in glob.glob('%s/cloud/*' % self.file_dir): s.scp_put(f, self.work_dir) def power_off_nodes(self): for node_id in self.node_ids: self.dha.node_power_off(node_id) def power_on_nodes(self): for node_id in self.node_ids: self.dha.node_power_on(node_id) def set_boot_order(self, boot_order_list):