def _gather_mac_addr(self): from lib.container import Container cont = Container(self.config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'clear_port_macs.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) _run_playbook("activate_client_interfaces.yml", self.config_file_path) cmd[-2] = os.path.join( gen.get_container_python_path(), 'set_port_macs.py') try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) else: print('Success: Gathered Client MAC addresses')
def _gather_mac_addr(self): from lib.container import Container from lib.inventory import Inventory yellow = '\033[93m' endc = '\033[0m' log = logger.getlogger() cont = Container(self.config_file_path) found_all = False while found_all is not True: cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append( os.path.join(gen.get_container_python_path(), 'clear_port_macs.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd, interactive=True) except UserException as exc: print('Fail:', str(exc), file=sys.stderr) sys.exit(1) _run_playbook("activate_client_interfaces.yml", self.config_file_path) cmd[-2] = os.path.join(gen.get_container_python_path(), 'set_port_macs.py') try: cont.run_command(cmd, interactive=True) except UserException as exc: print('Fail:', str(exc), file=sys.stderr) sys.exit(1) inv = Inventory(cfg_file=self.config_file_path) if inv.check_data_interfaces_macs(): found_all = True else: print() msg = 'Some data interface MAC addresses were not found!' log.warning(msg) print(f'{yellow}' + ('-' * (len(msg) + 10)) + f'{endc}') print("\nPress enter to retry") resp = input( "Enter C to continue POWER-Up or 'T' to terminate ") if resp == 'T': log.info( "'{}' entered. Terminating POWER-Up at user request". format(resp)) sys.exit(1) elif resp == 'C': log.info("'{}' entered. Continuing POWER-Up".format(resp)) found_all = True print('Success: Gathered Client MAC addresses')
def __init__(self, config_path=None, name=None): self.log = logger.getlogger() self.cfg = Config(config_path) self.cont_package_path = gen.get_container_package_path() self.cont_id_file = gen.get_container_id_file() self.cont_venv_path = gen.get_container_venv_path() self.cont_scripts_path = gen.get_container_scripts_path() self.cont_python_path = gen.get_container_python_path() self.cont_os_images_path = gen.get_container_os_images_path() self.cont_playbooks_path = gen.get_container_playbooks_path() self.depl_package_path = gen.get_package_path() self.depl_python_path = gen.get_python_path() self.depl_playbooks_path = gen.get_playbooks_path() if name is True or name is None: for vlan in self.cfg.yield_depl_netw_client_vlan('pxe'): break self.name = '{}-pxe{}'.format(self.DEFAULT_CONTAINER_NAME, vlan) else: self.name = name self.client = docker.from_env() try: self.image = self.client.images.get('power-up') except docker.errors.ImageNotFound: self.image = None try: self.cont = self.client.containers.get(self.name) except docker.errors.NotFound: self.cont = None
def _config_data_switches(self): import configure_data_switches print(COL.scroll_ten, COL.up_ten) print('{}Configuring data switches{}\n'. format(COL.header1, COL.endc)) print('This may take a few minutes depending on the size' ' of the cluster') if gen.is_container_running(): from lib.container import Container cont = Container(self.config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'configure_data_switches.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('\n{}Fail: {}{}'.format(COL.red, exc.message, COL.endc), file=sys.stderr) else: print('\nSuccesfully configured data switches') else: try: configure_data_switches.configure_data_switch(self.args.config_file_name) except UserException as exc: print('\n{}Fail: {}{}'.format(COL.red, exc.message, COL.endc), file=sys.stderr) except SwitchException as exc: print('\n{}Fail (switch error): {}{}'.format( COL.red, exc.message, COL.endc), file=sys.stderr) else: print('\nSuccesfully configured data switches')
def _inv_add_ports_pxe(self): log = logger.getlogger() from lib.inventory import Inventory inv = Inventory(cfg_file=self.config_file_path) if (inv.check_all_nodes_pxe_macs() and inv.check_all_nodes_pxe_ipaddrs()): log.info("PXE ports MAC and IP addresses already in inventory") return power_wait = gen.get_power_wait() ipmi_set_power('off', self.config_file_path, wait=power_wait) # set boot dev to bios, to avoid situations where some node types can skip # past pxe boot or attempt to boot from disk if pxe does not respond in time ipmi_set_bootdev('setup', False, self.config_file_path) ipmi_set_power('on', self.config_file_path, wait=power_wait) dhcp_lease_file = '/var/lib/misc/dnsmasq.leases' from lib.container import Container cont = Container(self.config_file_path, self.args.inv_add_ports_pxe) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'inv_add_ports.py')) cmd.append(dhcp_lease_file) cmd.append('pxe') cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) print('PXE ports added to inventory')
def _inv_add_ports_ipmi(self): log = logger.getlogger() from lib.inventory import Inventory inv = Inventory(cfg_file=self.config_file_path) if (inv.check_all_nodes_ipmi_macs() and inv.check_all_nodes_ipmi_ipaddrs()): log.info("IPMI ports MAC and IP addresses already in inventory") return dhcp_lease_file = '/var/lib/misc/dnsmasq.leases' from lib.container import Container cont = Container(self.config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'inv_add_ports.py')) cmd.append(dhcp_lease_file) cmd.append('ipmi') cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) print('IPMI ports added to inventory')
def _create_inventory(self): # from lib.inventory import Inventory # log = logger.getlogger() # inv = Inventory(cfg_file=self.config_file_path) # node_count = len(inv.inv['nodes']) # if node_count > 0: # log.info("Inventory already exists!") # print("\nInventory already exists with {} nodes defined." # "".format(node_count)) # print("Press enter to continue using the existing inventory.") # print("Type 'C' to continue creating a new inventory. " # "WARNING: Contents of current file will be overwritten!") # resp = raw_input("Type 'T' to terminate Cluster Genesis ") # if resp == 'T': # sys.exit('POWER-Up stopped at user request') # elif resp == 'C': # log.info("'{}' entered. Creating new inventory file." # "".format(resp)) # else: # log.info("Continuing with existing inventory.") # return from lib.container import Container log = logger.getlogger() cont = Container(self.config_file_path, self.args.create_inventory) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'inv_create.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) deployer_inv_file = gen.get_symlink_realpath(self.config_file_path) # If inventory file symlink is broken link remove it symlink_path = gen.get_symlink_path(self.config_file_path) if os.path.islink(symlink_path): if not os.path.exists(os.readlink(symlink_path)): os.unlink(symlink_path) # If inventory is an empty file delete it if (os.path.isfile(deployer_inv_file) and os.stat(deployer_inv_file).st_size == 0): os.remove(deployer_inv_file) # Create a sym link on deployer to inventory inside container if not os.path.isfile(deployer_inv_file): cont_inv_file = os.path.join(gen.LXC_DIR, cont.name, 'rootfs', gen.CONTAINER_PACKAGE_PATH[1:], gen.INV_FILE_NAME) log.debug("Creating symlink on deployer to container inventory: " "{} -> {}".format(deployer_inv_file, cont_inv_file)) os.symlink(cont_inv_file, deployer_inv_file) print('Success: Created inventory file')
def _create_inventory(self): # from lib.inventory import Inventory # log = logger.getlogger() # inv = Inventory(cfg_file=self.config_file_path) # node_count = len(inv.inv['nodes']) # if node_count > 0: # log.info("Inventory already exists!") # print("\nInventory already exists with {} nodes defined." # "".format(node_count)) # print("Press enter to continue using the existing inventory.") # print("Type 'C' to continue creating a new inventory. " # "WARNING: Contents of current file will be overwritten!") # resp = input("Type 'T' to terminate POWER-Up ") # if resp == 'T': # sys.exit('POWER-Up stopped at user request') # elif resp == 'C': # log.info("'{}' entered. Creating new inventory file." # "".format(resp)) # else: # log.info("Continuing with existing inventory.") # return from lib.container import Container from shutil import copy2 from lib.utilities import timestamp log = logger.getlogger() cont = Container(self.config_file_path, self.args.create_inventory) cont.copy(self.config_file_path, self.cont_config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append( os.path.join(gen.get_container_python_path(), 'inv_create.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd, interactive=True) except UserException as exc: print('Fail:', str(exc), file=sys.stderr) sys.exit(1) log.info('Success: Created inventory file') name = os.path.basename(self.config_file_path) parts = name.rpartition('.') bakupname = parts[0] + '-' + timestamp() + '.' + parts[2] bakuppath = os.path.join(gen.get_logs_path(), 'config-files') if not os.path.exists(bakuppath): os.mkdir(bakuppath) try: copy2(self.config_file_path, os.path.join(bakuppath, bakupname)) except FileNotFoundError as exc: log.debug(f'Unable to create copy of config file. {exc}')
def _add_cobbler_systems(self): from lib.container import Container cont = Container(self.config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'cobbler_add_systems.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) print('Success: Cobbler systems added')
def _reserve_ipmi_pxe_ips(self): from lib.container import Container cont = Container(self.config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'inv_reserve_ipmi_pxe_ips.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) print('Success: IPMI and PXE IP Addresses Reserved')
def _add_cobbler_distros(self): from lib.container import Container cont = Container(self.config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append( os.path.join(gen.get_container_python_path(), 'cobbler_add_distros.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd, interactive=True) except UserException as exc: print('Fail:', str(exc), file=sys.stderr) sys.exit(1) print('Success: Cobbler distros and profiles added')
def _install_client_os(self): from lib.container import Container remove_client_host_keys.remove_client_host_keys(self.config_file_path) cont = Container(self.config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append(os.path.join( gen.get_container_python_path(), 'install_client_os.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd) except UserException as exc: print('Fail:', exc.message, file=sys.stderr) sys.exit(1) _run_playbook("wait_for_clients_ping.yml", self.config_file_path) print('Success: Client OS installaion complete')
def _create_inventory(self): # from lib.inventory import Inventory # log = logger.getlogger() # inv = Inventory(cfg_file=self.config_file_path) # node_count = len(inv.inv['nodes']) # if node_count > 0: # log.info("Inventory already exists!") # print("\nInventory already exists with {} nodes defined." # "".format(node_count)) # print("Press enter to continue using the existing inventory.") # print("Type 'C' to continue creating a new inventory. " # "WARNING: Contents of current file will be overwritten!") # resp = input("Type 'T' to terminate Cluster Genesis ") # if resp == 'T': # sys.exit('POWER-Up stopped at user request') # elif resp == 'C': # log.info("'{}' entered. Creating new inventory file." # "".format(resp)) # else: # log.info("Continuing with existing inventory.") # return from lib.container import Container cont = Container(self.config_file_path, self.args.create_inventory) cont.copy(self.config_file_path, self.cont_config_file_path) cmd = [] cmd.append(gen.get_container_venv_python_exe()) cmd.append( os.path.join(gen.get_container_python_path(), 'inv_create.py')) cmd.append(self.cont_config_file_path) try: cont.run_command(cmd, interactive=True) except UserException as exc: print('Fail:', str(exc), file=sys.stderr) sys.exit(1) print('Success: Created inventory file')
def __init__(self, config_path=None, name=None): self.log = logger.getlogger() self.cfg = Config(config_path) self.cont_package_path = gen.get_container_package_path() self.cont_id_file = gen.get_container_id_file() self.cont_venv_path = gen.get_container_venv_path() self.cont_scripts_path = gen.get_container_scripts_path() self.cont_python_path = gen.get_container_python_path() self.cont_os_images_path = gen.get_container_os_images_path() self.cont_playbooks_path = gen.get_container_playbooks_path() self.depl_package_path = gen.get_package_path() self.depl_python_path = gen.get_python_path() self.depl_playbooks_path = gen.get_playbooks_path() self.cont_ini = os.path.join(self.depl_package_path, 'container.ini') self.rootfs = self.ROOTFS # Check if architecture is supported arch = platform.machine() if arch not in self.ARCHITECTURE.keys(): msg = "Unsupported architecture '{}'".format(arch) self.log.error(msg) raise UserException(msg) self.rootfs.arch = self.ARCHITECTURE[arch] if name is True or name is None: for vlan in self.cfg.yield_depl_netw_client_vlan('pxe'): break self.name = '{}-pxe{}'.format(self.DEFAULT_CONTAINER_NAME, vlan) else: self.name = name self.cont = lxc.Container(self.name) # Get a file descriptor for stdout self.fd = open(os.path.join(gen.GEN_LOGS_PATH, self.name + '.stdout.log'), 'w')