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 __init__(self, inv_file=None, cfg_file=None): self.log = logger.getlogger() if inv_file: self.inv_file = os.path.realpath(inv_file) else: symlink_path = gen.get_symlink_path(cfg_file) if os.path.islink(symlink_path): if not os.path.exists(os.readlink(symlink_path)): os.unlink(symlink_path) self.inv_file = gen.get_inventory_realpath(cfg_file) self.inv = None # Create inventory file if it does not exist if not os.path.isfile(self.inv_file): os.mknod(self.inv_file, self.FILE_MODE)