#!/usr/bin/python ############################################################################### # 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 re import sys import yaml import errno import signal import netaddr from dea import DeploymentEnvironmentAdapter from dha import DeploymentHardwareAdapter from install_fuel_master import InstallFuelMaster from deploy_env import CloudDeploy from execution_environment import ExecutionEnvironment from common import ( log, exec_cmd, err, warn, check_file_exists, create_dir_if_not_exists, delete, check_if_root, ArgParser, ) FUEL_VM = 'fuel' PATCH_DIR = 'fuel_patch' WORK_DIR = '~/deploy' CWD = os.getcwd() MOUNT_STATE_VAR = 'AUTODEPLOY_ISO_MOUNTED' class cd: def __init__(self, new_path): self.new_path = os.path.expanduser(new_path) def __enter__(self): self.saved_path = CWD os.chdir(self.new_path) def __exit__(self, etype, value, traceback): os.chdir(self.saved_path) class AutoDeploy(object): def __init__(self, no_fuel, fuel_only, no_health_check, cleanup_only, cleanup, storage_dir, pxe_bridge, iso_file, dea_file, dha_file, fuel_plugins_dir, fuel_plugins_conf_dir, no_plugins, deploy_timeout, no_deploy_environment): self.no_fuel = no_fuel self.fuel_only = fuel_only self.no_health_check = no_health_check self.cleanup_only = cleanup_only self.cleanup = cleanup self.storage_dir = storage_dir self.pxe_bridge = pxe_bridge self.iso_file = iso_file self.dea_file = dea_file self.dha_file = dha_file self.fuel_plugins_dir = fuel_plugins_dir self.fuel_plugins_conf_dir = fuel_plugins_conf_dir self.no_plugins = no_plugins self.deploy_timeout = deploy_timeout self.no_deploy_environment = no_deploy_environment self.dea = (DeploymentEnvironmentAdapter(dea_file) if not cleanup_only else None) self.dha = DeploymentHardwareAdapter(dha_file) self.fuel_conf = {} self.fuel_node_id = self.dha.get_fuel_node_id() self.fuel_username, self.fuel_password = self.dha.get_fuel_access() self.tmp_dir = None def modify_ip(self, ip_addr, index, val): ip_str = str(netaddr.IPAddress(ip_addr)) decimal_list = map(int, ip_str.split('.')) decimal_list[index] = val return '.'.join(map(str, decimal_list)) def collect_fuel_info(self): self.fuel_conf['ip'] = self.dea.get_fuel_ip() self.fuel_conf['gw'] = self.dea.get_fuel_gateway() self.fuel_conf['dns1'] = self.dea.get_fuel_dns() self.fuel_conf['netmask'] = self.dea.get_fuel_netmask() self.fuel_conf['hostname'] = self.dea.get_fuel_hostname() self.fuel_conf['showmenu'] = 'yes' def install_fuel_master(self): log('Install Fuel Master') new_iso = ('%s/deploy-%s' % (self.tmp_dir, os.path.basename(self.iso_file))) self.patch_iso(new_iso) self.iso_file = new_iso self.install_iso() def install_iso(self): fuel = InstallFuelMaster(self.dea_file, self.dha_file, self.fuel_conf['ip'], self.fuel_username, self.fuel_password, self.fuel_node_id, self.iso_file, WORK_DIR, self.fuel_plugins_dir, self.no_plugins) fuel.install() def patch_iso(self, new_iso): tmp_orig_dir = '%s/origiso' % sel
# Use this environment to create a swap partition in all Overcloud nodes
resource_registry:
  OS::TripleO::AllNodesExtraConfig: ../extraconfig/all_nodes/swap-partition.yaml
g('Caught signal %s, cleaning up and exiting.' % signal_num) mount_point = os.environ.get(MOUNT_STATE_VAR) if mount_point: log('Unmounting ISO from "%s"' % mount_point) # Prevent 'Device or resource busy' errors when unmounting os.chdir('/') exec_cmd('fusermount -u %s' % mount_point, True) # Be nice and remove our environment variable, even though the OS would # would clean it up anyway os.environ.pop(MOUNT_STATE_VAR) sys.exit(1) def main(): signal.signal(signal.SIGINT, handle_signals) signal.signal(signal.SIGTERM, handle_signals) kwargs = parse_arguments() d = AutoDeploy(**kwargs) sys.exit(d.run()) if __name__ == '__main__': main()