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): 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.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): for node_id in self.node_ids: self.dha.node_set_boot_order(node_id, boot_order_list[:]) def get_mac_addresses(self): self.macs_per_blade = {} for node_id in self.node_ids: self.macs_per_blade[node_id] = self.dha.get_node_pxe_mac(node_id) def run_cloud_deploy(self, deploy_app): log('START CLOUD DEPLOYMENT') deploy_app = '%s/%s' % (self.work_dir, deploy_app) dea_file = '%s/%s' % (self.work_dir, os.path.basename(self.dea_file)) with self.ssh as s: status = s.run('python %s %s %s %s %s' % ( deploy_app, ('-nh' if self.no_health_check else ''), ('-dt %s' % self.deploy_timeout if self.deploy_timeout else ''), ('-nde' if self.no_deploy_environment else ''), dea_file)) return status def check_supported_release(self): log('Check supported release: %s' % self.wanted_release) found = False release_list = parse(self.ssh.exec_cmd('fuel release -l')) for release in release_list: if release[R['name']] == self.wanted_release: found = True break if not found: err('This Fuel does not contain the following release: %s' % self.wanted_release) def check_previous_installation(self): log('Check previous installation') env_list = parse(self.ssh.exec_cmd('fuel env list')) if env_list: self.cleanup_fuel_environments(env_list) node_list = parse(self.ssh.exec_cmd('fuel node list')) if node_list: self.cleanup_fuel_nodes(node_list) 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']]) self.ssh.exec_cmd('fuel env --env %s --delete --force' % env[E['id']]) all_env_erased = False for i in range(WAIT_LOOP): env_list = parse(self.ssh.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']]) self.ssh.exec_cmd('fuel node --node-id %s --delete-from-db ' '--force' % node[N['id']]) self.ssh.exec_cmd('cobbler system remove --name node-%s' % node[N['id']], False) def check_prerequisites(self): log('Check prerequisites') with self.ssh: self.check_supported_release() self.check_previous_installation() def wait_for_discovered_blades(self): log('Wait for discovered blades') discovered_macs = [] restart_times = BLADE_RESTART_TIMES for blade in self.node_ids: self.blade_node_dict[blade] = None with self.ssh: all_discovered = self.discovery_waiting_loop(discovered_macs) while not all_discovered and restart_times != 0: restart_times -= 1 for blade in self.get_not_discovered_blades(): self.dha.node_reset(blade) with self.ssh: 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()) with io.open(self.updated_dea_file) as stream: updated_dea = yaml.load(stream) updated_dea.update({'blade_node_map': self.blade_node_dict}) with io.open(self.updated_dea_file, 'w') as stream: yaml.dump(updated_dea, stream, default_flow_style=False) def discovery_waiting_loop(self, discovered_macs): WAIT_LOOP = 360 SLEEP_TIME = 10 all_discovered = False for i in range(WAIT_LOOP): node_list = parse(self.ssh.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 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.blade_node_dict[blade] = int(node[N['id']]) 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.blade_node_dict.iteritems(): if not node_id: return False return True def not_discovered_blades_summary(self): summary = '' for blade, node_id in self.blade_node_dict.iteritems(): if not node_id: summary += '\n[blade %s]' % blade return summary def get_not_discovered_blades(self): not_discovered_blades = [] for blade, node_id in self.blade_node_dict.iteritems(): if not node_id: not_discovered_blades.append(blade) return not_discovered_blades def set_boot_order_nodes(self): self.power_off_nodes() self.set_boot_order(['pxe', 'disk']) self.power_on_nodes() def deploy(self): self.set_boot_order_nodes() self.check_prerequisites() self.get_mac_addresses() self.wait_for_discovered_blades() self.merge_plugin_config_files_to_dea_file() self.upload_cloud_deployment_files() delete(self.updated_dea_file) return self.run_cloud_deploy(CLOUD_DEPLOY_FILE)
class InstallFuelMaster(object): def __init__(self, dea_file, dha_file, fuel_ip, fuel_username, fuel_password, fuel_node_id, iso_file, work_dir, fuel_plugins_dir, no_plugins): self.dea_file = dea_file self.dha = LibvirtAdapter(dha_file) self.fuel_ip = fuel_ip self.fuel_username = fuel_username self.fuel_password = fuel_password self.fuel_node_id = fuel_node_id self.iso_file = iso_file self.iso_dir = os.path.dirname(self.iso_file) self.work_dir = work_dir self.fuel_plugins_dir = fuel_plugins_dir self.no_plugins = no_plugins self.file_dir = os.path.dirname(os.path.realpath(__file__)) self.ssh = SSHClient(self.fuel_ip, self.fuel_username, self.fuel_password) def install(self): log('Start Fuel Installation') self.dha.node_power_off(self.fuel_node_id) log('Zero the MBR') self.dha.node_zero_mbr(self.fuel_node_id) self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso']) try: self.proceed_with_installation() except Exception as e: self.post_install_cleanup() err(e) def proceed_with_installation(self): log('Eject ISO') self.dha.node_eject_iso(self.fuel_node_id) log('Insert ISO %s' % self.iso_file) self.dha.node_insert_iso(self.fuel_node_id, self.iso_file) self.dha.node_power_on(self.fuel_node_id) log('Waiting for Fuel master to accept SSH') self.wait_for_node_up() log('Wait until Fuel menu is up') fuel_menu_pid = self.wait_until_fuel_menu_up() log('Inject our own astute.yaml settings') self.inject_own_astute_yaml() log('Let the Fuel deployment continue') log('Found FUEL menu as PID %s, now killing it' % fuel_menu_pid) self.ssh_exec_cmd('kill %s' % fuel_menu_pid, False) log('Wait until installation is complete') self.wait_until_installation_completed() log('Waiting for one minute for Fuel to stabilize') time.sleep(60) self.delete_deprecated_fuel_client_config() if not self.no_plugins: self.collect_plugin_files() self.install_plugins() self.post_install_cleanup() log('Fuel Master installed successfully !') def collect_plugin_files(self): with self.ssh as s: s.exec_cmd('mkdir %s' % PLUGINS_DIR) if self.fuel_plugins_dir: for f in glob.glob('%s/*.rpm' % self.fuel_plugins_dir): s.scp_put(f, PLUGINS_DIR) def install_plugins(self): log('Installing Fuel Plugins') plugin_files = [] with self.ssh as s: for plugin_location in [PLUGINS_DIR, LOCAL_PLUGIN_FOLDER]: s.exec_cmd('mkdir -p %s' % plugin_location) r = s.exec_cmd('find %s -type f -name \'*.rpm\'' % plugin_location) plugin_files.extend(r.splitlines()) for f in plugin_files: log('Found plugin %s, installing ...' % f) r, e = s.exec_cmd('fuel plugins --install %s' % f, False) printout = r + e if e else r if e and all( [err not in printout for err in IGNORABLE_FUEL_ERRORS]): raise Exception('Installation of Fuel Plugin %s ' 'failed: %s' % (f, e)) def wait_for_node_up(self): WAIT_LOOP = 240 SLEEP_TIME = 10 success = False for i in range(WAIT_LOOP): try: self.ssh.open() success = True break except Exception: log('Trying to SSH into Fuel VM %s ... sleeping %s seconds' % (self.fuel_ip, SLEEP_TIME)) time.sleep(SLEEP_TIME) finally: self.ssh.close() if not success: raise Exception('Could not SSH into Fuel VM %s' % self.fuel_ip) def wait_until_fuel_menu_up(self): WAIT_LOOP = 60 SLEEP_TIME = 10 CMD = 'ps -ef' SEARCH = 'fuelmenu' fuel_menu_pid = None with self.ssh: for i in range(WAIT_LOOP): ret = self.ssh.exec_cmd(CMD) fuel_menu_pid = self.get_fuel_menu_pid(ret, SEARCH) if not fuel_menu_pid: time.sleep(SLEEP_TIME) else: break if not fuel_menu_pid: raise Exception('Could not find the Fuel Menu Process ID') return fuel_menu_pid def get_fuel_menu_pid(self, printout, search): for line in printout.splitlines(): if line.endswith(search): return clean(line)[1] def ssh_exec_cmd(self, cmd, check=True): with self.ssh: ret = self.ssh.exec_cmd(cmd, check=check) return ret def inject_own_astute_yaml(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.dea_file, self.work_dir) s.scp_put('%s/common.py' % self.file_dir, self.work_dir) s.scp_put('%s/dea.py' % self.file_dir, self.work_dir) s.scp_put('%s/transplant_fuel_settings.py' % self.file_dir, self.work_dir) log('Modifying Fuel astute') s.run('python %s/%s %s/%s' % (self.work_dir, TRANSPLANT_FUEL_SETTINGS, self.work_dir, os.path.basename(self.dea_file))) def wait_until_installation_completed(self): WAIT_LOOP = 360 SLEEP_TIME = 10 CMD = 'ps -ef | grep %s | grep -v grep' % BOOTSTRAP_ADMIN install_completed = False with self.ssh: for i in range(WAIT_LOOP): ret = self.ssh.exec_cmd(CMD) if not ret: install_completed = True break else: time.sleep(SLEEP_TIME) if not install_completed: raise Exception('Fuel installation did not complete') def post_install_cleanup(self): log('Eject ISO file %s' % self.iso_file) self.dha.node_eject_iso(self.fuel_node_id) delete(self.iso_dir) def delete_deprecated_fuel_client_config(self): with self.ssh as s: response, error = s.exec_cmd('fuel -v', False) if (error and 'DEPRECATION WARNING' in error and FUEL_CLIENT_CONFIG in error): log('Delete deprecated fuel client config %s' % FUEL_CLIENT_CONFIG) with self.ssh as s: s.exec_cmd('rm %s' % FUEL_CLIENT_CONFIG, False)
class InstallFuelMaster(object): def __init__(self, dea_file, dha_file, fuel_ip, fuel_username, fuel_password, fuel_node_id, iso_file, work_dir): self.dea_file = dea_file self.dha = LibvirtAdapter(dha_file) self.fuel_ip = fuel_ip self.fuel_username = fuel_username self.fuel_password = fuel_password self.fuel_node_id = fuel_node_id self.iso_file = iso_file self.work_dir = work_dir self.file_dir = os.path.dirname(os.path.realpath(__file__)) self.ssh = SSHClient(self.fuel_ip, self.fuel_username, self.fuel_password) def install(self): log('Start Fuel Installation') self.dha.node_power_off(self.fuel_node_id) self.zero_mbr_set_boot_order() self.proceed_with_installation() def custom_install(self): log('Start Custom Fuel Installation') self.dha.node_power_off(self.fuel_node_id) log('Zero the MBR') self.dha.node_zero_mbr(self.fuel_node_id) self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso']) self.proceed_with_installation() def proceed_with_installation(self): log('Eject ISO') self.dha.node_eject_iso(self.fuel_node_id) log('Insert ISO %s' % self.iso_file) self.dha.node_insert_iso(self.fuel_node_id, self.iso_file) self.dha.node_power_on(self.fuel_node_id) log('Waiting for Fuel master to accept SSH') self.wait_for_node_up() log('Wait until Fuel menu is up') fuel_menu_pid = self.wait_until_fuel_menu_up() log('Inject our own astute.yaml settings') self.inject_own_astute_yaml() log('Let the Fuel deployment continue') log('Found FUEL menu as PID %s, now killing it' % fuel_menu_pid) self.ssh_exec_cmd('kill %s' % fuel_menu_pid) log('Wait until installation complete') self.wait_until_installation_completed() log('Waiting for one minute for Fuel to stabilize') time.sleep(60) log('Eject ISO') self.dha.node_eject_iso(self.fuel_node_id) log('Fuel Master installed successfully !') def zero_mbr_set_boot_order(self): if self.dha.node_can_zero_mbr(self.fuel_node_id): log('Fuel Node %s capable of zeroing MBR so doing that...' % self.fuel_node_id) self.dha.node_zero_mbr(self.fuel_node_id) self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso']) elif self.dha.node_can_set_boot_order_live(self.fuel_node_id): log('Node %s can change ISO boot order live' % self.fuel_node_id) self.dha.node_set_boot_order(self.fuel_node_id, ['iso', 'disk']) else: err('No way to install Fuel node') def wait_for_node_up(self): WAIT_LOOP = 60 SLEEP_TIME = 10 success = False for i in range(WAIT_LOOP): try: self.ssh.open() success = True break except Exception as e: log('EXCEPTION [%s] received when SSH-ing into Fuel VM %s ... ' 'sleeping %s seconds' % (e, self.fuel_ip, SLEEP_TIME)) time.sleep(SLEEP_TIME) finally: self.ssh.close() if not success: err('Could not SSH into Fuel VM %s' % self.fuel_ip) def wait_until_fuel_menu_up(self): WAIT_LOOP = 60 SLEEP_TIME = 10 CMD = 'ps -ef' SEARCH = 'fuelmenu' fuel_menu_pid = None with self.ssh: for i in range(WAIT_LOOP): ret = self.ssh.exec_cmd(CMD) fuel_menu_pid = self.get_fuel_menu_pid(ret, SEARCH) if not fuel_menu_pid: time.sleep(SLEEP_TIME) else: break if not fuel_menu_pid: err('Could not find the Fuel Menu Process ID') return fuel_menu_pid def get_fuel_menu_pid(self, printout, search): fuel_menu_pid = None for line in printout.splitlines(): if search in line: fuel_menu_pid = clean(line)[1] break return fuel_menu_pid def ssh_exec_cmd(self, cmd): with self.ssh: ret = self.ssh.exec_cmd(cmd) return ret def inject_own_astute_yaml(self): dest ='~/%s/' % self.work_dir with self.ssh as s: s.exec_cmd('rm -rf %s' % self.work_dir, check=False) s.exec_cmd('mkdir ~/%s' % self.work_dir) s.scp_put(self.dea_file, dest) s.scp_put('%s/common.py' % self.file_dir, dest) s.scp_put('%s/dea.py' % self.file_dir, dest) s.scp_put('%s/transplant_fuel_settings.py' % self.file_dir, dest) log('Modifying Fuel astute') s.run('python ~/%s/%s ~/%s/%s' % (self.work_dir, TRANSPLANT_FUEL_SETTINGS, self.work_dir, os.path.basename(self.dea_file))) def wait_until_installation_completed(self): WAIT_LOOP = 180 SLEEP_TIME = 10 CMD = 'ps -ef | grep %s | grep -v grep' % BOOTSTRAP_ADMIN install_completed = False with self.ssh: for i in range(WAIT_LOOP): ret = self.ssh.exec_cmd(CMD) if not ret: install_completed = True break else: time.sleep(SLEEP_TIME) if not install_completed: err('Fuel installation did not complete')
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): for node_id in self.node_ids: self.dha.node_set_boot_order(node_id, boot_order_list[:]) def get_mac_addresses(self): self.macs_per_blade = {} for node_id in self.node_ids: self.macs_per_blade[node_id] = self.dha.get_node_pxe_mac(node_id) def run_cloud_deploy(self, deploy_app): log('START CLOUD DEPLOYMENT') deploy_app = '%s/%s' % (self.work_dir, deploy_app) dea_file = '%s/%s' % (self.work_dir, os.path.basename(self.dea_file)) with self.ssh as s: status = s.run( 'python %s %s %s %s %s' % (deploy_app, ('-nh' if self.no_health_check else ''), ('-dt %s' % self.deploy_timeout if self.deploy_timeout else ''), ('-nde' if self.no_deploy_environment else ''), dea_file)) return status def check_supported_release(self): log('Check supported release: %s' % self.wanted_release) found = False release_list = parse(self.ssh.exec_cmd('fuel release -l')) for release in release_list: if release[R['name']] == self.wanted_release: found = True break if not found: err('This Fuel does not contain the following release: %s' % self.wanted_release) def check_previous_installation(self): log('Check previous installation') env_list = parse(self.ssh.exec_cmd('fuel env list')) if env_list: self.cleanup_fuel_environments(env_list) node_list = parse(self.ssh.exec_cmd('fuel node list')) if node_list: self.cleanup_fuel_nodes(node_list) 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']]) self.ssh.exec_cmd('fuel env --env %s --delete --force' % env[E['id']]) all_env_erased = False for i in range(WAIT_LOOP): env_list = parse(self.ssh.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']]) self.ssh.exec_cmd('fuel node --node-id %s --delete-from-db ' '--force' % node[N['id']]) self.ssh.exec_cmd( 'cobbler system remove --name node-%s' % node[N['id']], False) def check_prerequisites(self): log('Check prerequisites') with self.ssh: self.check_supported_release() self.check_previous_installation() def wait_for_discovered_blades(self): log('Wait for discovered blades') discovered_macs = [] restart_times = BLADE_RESTART_TIMES for blade in self.node_ids: self.blade_node_dict[blade] = None with self.ssh: all_discovered = self.discovery_waiting_loop(discovered_macs) while not all_discovered and restart_times != 0: restart_times -= 1 for blade in self.get_not_discovered_blades(): self.dha.node_reset(blade) with self.ssh: 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()) with io.open(self.updated_dea_file) as stream: updated_dea = yaml.load(stream) updated_dea.update({'blade_node_map': self.blade_node_dict}) with io.open(self.updated_dea_file, 'w') as stream: yaml.dump(updated_dea, stream, default_flow_style=False) def discovery_waiting_loop(self, discovered_macs): WAIT_LOOP = 360 SLEEP_TIME = 10 all_discovered = False for i in range(WAIT_LOOP): node_list = parse(self.ssh.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 node_discovery(self, node_list, discovered_macs): for node in node_list: if (node[N['status']] == 'discover' and (node[N['online']] == 'True' or node[N['online']] == '1') 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.blade_node_dict[blade] = int(node[N['id']]) 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.blade_node_dict.iteritems(): if not node_id: return False return True def not_discovered_blades_summary(self): summary = '' for blade, node_id in self.blade_node_dict.iteritems(): if not node_id: summary += '\n[blade %s]' % blade return summary def get_not_discovered_blades(self): not_discovered_blades = [] for blade, node_id in self.blade_node_dict.iteritems(): if not node_id: not_discovered_blades.append(blade) return not_discovered_blades def set_boot_order_nodes(self): self.power_off_nodes() self.set_boot_order(['pxe', 'disk']) self.power_on_nodes() def get_put_deploy_log(self): with self.ssh as s: s.scp_get("deploy-*", local=self.deploy_log) def deploy(self): self.set_boot_order_nodes() self.check_prerequisites() self.get_mac_addresses() self.wait_for_discovered_blades() self.merge_plugin_config_files_to_dea_file() self.upload_cloud_deployment_files() delete(self.updated_dea_file) rc = self.run_cloud_deploy(CLOUD_DEPLOY_FILE) self.get_put_deploy_log() return rc