def __init__(self, dea_file, no_health_check): self.dea = DeploymentEnvironmentAdapter(dea_file) self.no_health_check = no_health_check self.macs_per_blade = {} self.blades = self.dea.get_node_ids() self.blade_node_dict = self.dea.get_blade_node_map() self.node_roles_dict = {} self.env_id = None self.wanted_release = self.dea.get_property('wanted_release')
class Deploy(object): def __init__(self, dea_file, no_health_check, deploy_timeout, no_deploy_environment): self.dea = DeploymentEnvironmentAdapter(dea_file) self.no_health_check = no_health_check self.deploy_timeout = deploy_timeout self.no_deploy_environment = no_deploy_environment self.macs_per_blade = {} self.blades = self.dea.get_node_ids() self.blade_node_dict = self.dea.get_blade_node_map() self.node_roles_dict = {} self.env_id = None self.wanted_release = self.dea.get_property('wanted_release') def assign_roles_to_cluster_node_ids(self): self.node_roles_dict = {} for blade, node in self.blade_node_dict.iteritems(): if self.dea.get_node_roles(blade): roles = commafy(self.dea.get_node_roles(blade)) self.node_roles_dict[node] = (roles, blade) def configure_environment(self): release_list = parse(exec_cmd('fuel release -l')) for release in release_list: if release[R['name']] == self.wanted_release: break config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR, release[R['id']], self.node_roles_dict) config_env.configure_environment() self.env_id = config_env.env_id def deploy_cloud(self): dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id, self.node_roles_dict, self.no_health_check, self.deploy_timeout) if not self.no_deploy_environment: dep.deploy() else: log('Configuration is done. Deployment is not launched.') def deploy(self): self.assign_roles_to_cluster_node_ids() self.configure_environment() self.deploy_cloud()
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, deploy_log): 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.deploy_log = deploy_log 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 main(): dea_file = parse_arguments() check_file_exists(ASTUTE_YAML) dea = DeploymentEnvironmentAdapter(dea_file) with io.open(ASTUTE_YAML) as stream: astute = yaml.load(stream) transplant(dea, astute) with io.open(ASTUTE_YAML, 'w') as stream: yaml.dump(astute, stream, default_flow_style=False)
def __init__(self, dea_file, macs_file): self.dea = DeploymentEnvironmentAdapter(dea_file) self.macs_file = macs_file self.macs_per_blade = {} self.blades = self.dea.get_node_ids() self.node_ids_dict = {} self.node_id_roles_dict = {} self.supported_release = None self.env_id = None self.wanted_release = self.dea.get_wanted_release()
def __init__(self, without_fuel, iso_file, dea_file, dha_file): self.without_fuel = without_fuel self.iso_file = iso_file self.dea_file = dea_file self.dha_file = dha_file self.dea = DeploymentEnvironmentAdapter(dea_file) self.dha = DeploymentHardwareAdapter(dha_file) self.fuel_conf = {} self.fuel_node_id = self.dha.get_fuel_node_id() self.fuel_custom = self.dha.use_fuel_custom_install() self.fuel_username, self.fuel_password = self.dha.get_fuel_access()
def __init__(self, dea_file, no_health_check, deploy_timeout, no_deploy_environment): self.dea = DeploymentEnvironmentAdapter(dea_file) self.no_health_check = no_health_check self.deploy_timeout = deploy_timeout self.no_deploy_environment = no_deploy_environment self.macs_per_blade = {} self.blades = self.dea.get_node_ids() self.blade_node_dict = self.dea.get_blade_node_map() self.node_roles_dict = {} self.env_id = None self.wanted_release = self.dea.get_property('wanted_release')
def main(): dea_file = parse_arguments() check_file_exists(ASTUTE_YAML) # Temporarily disabled for Fuel 10. # check_file_exists(FUEL_BOOTSTRAP_CLI_YAML) dea = DeploymentEnvironmentAdapter(dea_file) log('Reading astute file %s' % ASTUTE_YAML) with io.open(ASTUTE_YAML) as stream: astute = yaml.load(stream) log('Initiating transplant') transplant(dea, astute) with io.open(ASTUTE_YAML, 'w') as stream: yaml.dump(astute, stream, default_flow_style=False) log('Transplant done')
def main(): dea_file = parse_arguments() check_file_exists(ASTUTE_YAML) check_file_exists(FUEL_BOOTSTRAP_CLI_YAML) dea = DeploymentEnvironmentAdapter(dea_file) log('Reading astute file %s' % ASTUTE_YAML) with io.open(ASTUTE_YAML) as stream: astute = yaml.load(stream) log('Initiating transplant') transplant(dea, astute) with io.open(ASTUTE_YAML, 'w') as stream: yaml.dump(astute, stream, default_flow_style=False) log('Transplant done') # Update bootstrap config yaml with info from DEA/astute.yaml with io.open(FUEL_BOOTSTRAP_CLI_YAML) as stream: fuel_bootstrap_cli = yaml.load(stream) transplant_bootstrap(astute, fuel_bootstrap_cli) with io.open(FUEL_BOOTSTRAP_CLI_YAML, 'w') as stream: yaml.dump(fuel_bootstrap_cli, stream, default_flow_style=False)
class AutoDeploy(object): def __init__(self, without_fuel, iso_file, dea_file, dha_file): self.without_fuel = without_fuel self.iso_file = iso_file self.dea_file = dea_file self.dha_file = dha_file self.dea = DeploymentEnvironmentAdapter(dea_file) self.dha = DeploymentHardwareAdapter(dha_file) self.fuel_conf = {} self.fuel_node_id = self.dha.get_fuel_node_id() self.fuel_custom = self.dha.use_fuel_custom_install() self.fuel_username, self.fuel_password = self.dha.get_fuel_access() def setup_dir(self, dir): self.cleanup_dir(dir) os.makedirs(dir) def cleanup_dir(self, dir): if os.path.isdir(dir): shutil.rmtree(dir) def power_off_blades(self): node_ids = self.dha.get_all_node_ids() node_ids = list(set(node_ids) - set([self.fuel_node_id])) for node_id in node_ids: self.dha.node_power_off(node_id) 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): if self.without_fuel: log('Not Installing Fuel Master') return log('Install Fuel Master') new_iso = '%s/deploy-%s' % (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) if self.fuel_custom: log('Custom Fuel install') fuel.custom_install() else: log('Ordinary Fuel install') fuel.install() def patch_iso(self, new_iso): tmp_orig_dir = '%s/origiso' % TMP_DIR tmp_new_dir = '%s/newiso' % TMP_DIR self.copy(tmp_orig_dir, tmp_new_dir) self.patch(tmp_new_dir, new_iso) def copy(self, tmp_orig_dir, tmp_new_dir): log('Copying...') self.setup_dir(tmp_orig_dir) self.setup_dir(tmp_new_dir) exec_cmd('fuseiso %s %s' % (self.iso_file, tmp_orig_dir)) with cd(tmp_orig_dir): exec_cmd('find . | cpio -pd %s' % tmp_new_dir) with cd(tmp_new_dir): exec_cmd('fusermount -u %s' % tmp_orig_dir) shutil.rmtree(tmp_orig_dir) exec_cmd('chmod -R 755 %s' % tmp_new_dir) def patch(self, tmp_new_dir, new_iso): log('Patching...') patch_dir = '%s/%s' % (os.getcwd(), PATCH_DIR) ks_path = '%s/ks.cfg.patch' % patch_dir with cd(tmp_new_dir): exec_cmd('cat %s | patch -p0' % ks_path) shutil.rmtree('.rr_moved') isolinux = 'isolinux/isolinux.cfg' log('isolinux.cfg before: %s' % exec_cmd('grep netmask %s' % isolinux)) self.update_fuel_isolinux(isolinux) log('isolinux.cfg after: %s' % exec_cmd('grep netmask %s' % isolinux)) iso_linux_bin = 'isolinux/isolinux.bin' exec_cmd('mkisofs -quiet -r -J -R -b %s ' '-no-emul-boot -boot-load-size 4 ' '-boot-info-table -hide-rr-moved ' '-x "lost+found:" -o %s .' % (iso_linux_bin, new_iso)) def update_fuel_isolinux(self, file): with io.open(file) as f: data = f.read() for key, val in self.fuel_conf.iteritems(): pattern = r'%s=[^ ]\S+' % key replace = '%s=%s' % (key, val) data = re.sub(pattern, replace, data) with io.open(file, 'w') as f: f.write(data) def deploy_env(self): dep = CloudDeploy(self.dha, self.fuel_conf['ip'], self.fuel_username, self.fuel_password, self.dea_file, WORK_DIR) dep.deploy() def deploy(self): check_if_root() self.setup_dir(TMP_DIR) self.collect_fuel_info() self.power_off_blades() self.install_fuel_master() self.cleanup_dir(TMP_DIR) self.deploy_env()
class Deploy(object): def __init__(self, dea_file, macs_file): self.dea = DeploymentEnvironmentAdapter(dea_file) self.macs_file = macs_file self.macs_per_blade = {} self.blades = self.dea.get_node_ids() self.node_ids_dict = {} self.node_id_roles_dict = {} self.supported_release = None self.env_id = None self.wanted_release = self.dea.get_wanted_release() def cleanup_fuel_environments(self, env_list): WAIT_LOOP = 60 SLEEP_TIME = 10 for env in env_list: log('Deleting environment %s' % env[E['id']]) exec_cmd('fuel env --env %s --delete' % env[E['id']]) all_env_erased = False for i in range(WAIT_LOOP): env_list = parse(exec_cmd('fuel env list')) if env_list: time.sleep(SLEEP_TIME) else: all_env_erased = True break if not all_env_erased: err('Could not erase these environments %s' % [(env[E['id']], env[E['status']]) for env in env_list]) def cleanup_fuel_nodes(self, node_list): for node in node_list: if node[N['status']] == 'discover': log('Deleting node %s' % node[N['id']]) exec_cmd('fuel node --node-id %s --delete-from-db' % node[N['id']]) exec_cmd('dockerctl shell cobbler cobbler system remove ' '--name node-%s' % node[N['id']]) def check_previous_installation(self): log('Check previous installation') env_list = parse(exec_cmd('fuel env list')) if env_list: self.cleanup_fuel_environments(env_list) node_list = parse(exec_cmd('fuel node list')) if node_list: self.cleanup_fuel_nodes(node_list) def check_supported_release(self): log('Check supported release: %s' % self.wanted_release) release_list = parse(exec_cmd('fuel release -l')) for release in release_list: if release[R['name']] == self.wanted_release: self.supported_release = release break if not self.supported_release: err('This Fuel does not contain the following release: %s' % self.wanted_release) def check_prerequisites(self): log('Check prerequisites') self.check_supported_release() self.check_previous_installation() def get_mac_addresses(self): with io.open(self.macs_file, 'r') as stream: self.macs_per_blade = yaml.load(stream) def find_mac_in_dict(self, mac): for blade, mac_list in self.macs_per_blade.iteritems(): if mac in mac_list: return blade def all_blades_discovered(self): for blade, node_id in self.node_ids_dict.iteritems(): if not node_id: return False return True def not_discovered_blades_summary(self): summary = '' for blade, node_id in self.node_ids_dict.iteritems(): if not node_id: summary += '\n[blade %s]' % blade return summary def node_discovery(self, node_list, discovered_macs): for node in node_list: if (node[N['status']] == 'discover' and node[N['online']] == 'True' and node[N['mac']] not in discovered_macs): discovered_macs.append(node[N['mac']]) blade = self.find_mac_in_dict(node[N['mac']]) if blade: log('Blade %s discovered as Node %s with MAC %s' % (blade, node[N['id']], node[N['mac']])) self.node_ids_dict[blade] = node[N['id']] def discovery_waiting_loop(self, discovered_macs): WAIT_LOOP = 180 SLEEP_TIME = 10 all_discovered = False for i in range(WAIT_LOOP): node_list = parse(exec_cmd('fuel node list')) if node_list: self.node_discovery(node_list, discovered_macs) if self.all_blades_discovered(): all_discovered = True break else: time.sleep(SLEEP_TIME) return all_discovered def wait_for_discovered_blades(self): log('Wait for discovered blades') discovered_macs = [] for blade in self.blades: self.node_ids_dict[blade] = None all_discovered = self.discovery_waiting_loop(discovered_macs) if not all_discovered: err('Not all blades have been discovered: %s' % self.not_discovered_blades_summary()) def assign_roles_to_cluster_node_ids(self): self.node_id_roles_dict = {} for blade, node_id in self.node_ids_dict.iteritems(): role_list = [] role = self.dea.get_node_role(blade) if role == 'controller': role_list.extend(['controller', 'mongo']) elif role == 'compute': role_list.extend(['compute']) self.node_id_roles_dict[node_id] = (role_list, blade) def configure_environment(self): config_env = ConfigureEnvironment(self.dea, YAML_CONF_DIR, self.supported_release[R['id']], self.node_id_roles_dict) config_env.configure_environment() self.env_id = config_env.env_id def deploy_cloud(self): dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id, self.node_id_roles_dict) dep.deploy() def deploy(self): self.get_mac_addresses() self.check_prerequisites() self.wait_for_discovered_blades() self.assign_roles_to_cluster_node_ids() self.configure_environment() self.deploy_cloud()