def undeploy(storage: Storage, verbose_mode: bool, num_workers: int): """ Undeploy a deployment. :raises ParseError: :raises DataError: """ if storage.exists("inputs"): inputs = storage.read_json("inputs") else: inputs = {} if storage.exists("root_file"): service_template = storage.read("root_file") workdir = str(Path.cwd()) if storage.exists("csars"): csar_dir = Path(storage.path) / "csars" / "csar" workdir = str(csar_dir) ast = tosca.load(Path(csar_dir), PurePath(service_template).relative_to(csar_dir)) else: ast = tosca.load(Path.cwd(), PurePath(service_template)) template = ast.get_template(inputs) topology = template.instantiate(storage) topology.undeploy(verbose_mode, workdir, num_workers) else: print("There is no root_file in storage.")
def update(storage_old: Storage, workdir_old: str, storage_new: Storage, workdir_new: str, instance_comparer: InstanceComparer, instance_diff: Diff, verbose_mode: bool, num_workers: int, overwrite: bool): template_old = get_template(storage_old) template_new = get_template(storage_new) topology_old = template_old.instantiate(storage_old) topology_new = template_new.instantiate(storage_new) if verbose_mode: print(format_outputs(instance_diff.outputs(), "json")) instance_comparer.prepare_update(topology_old, topology_new, instance_diff) topology_old.undeploy(verbose_mode, workdir_old, num_workers) topology_old.write_all() if overwrite: # swap storage topology_new.set_storage(storage_old) # rewrite inputs and root file storage_old.write_json(storage_new.read_json("inputs"), "inputs") storage_old.write(storage_new.read("root_file"), "root_file") topology_new.write_all() topology_new.deploy(verbose_mode, workdir_new, num_workers)
def outputs(storage: Storage) -> dict: """ Get deployment outputs. :raises ParseError: :raises DataError: """ if storage.exists("inputs"): inputs = storage.read_json("inputs") else: inputs = {} if storage.exists("root_file"): service_template_path = PurePath(storage.read("root_file")) if storage.exists("csars"): csar_dir = Path(storage.path) / "csars" / "csar" ast = tosca.load(Path(csar_dir), service_template_path.relative_to(csar_dir)) else: ast = tosca.load(Path(service_template_path.parent), PurePath(service_template_path.name)) template = ast.get_template(inputs) # We need to instantiate the template in order # to get access to the instance state. template.instantiate(storage) result: Dict = template.get_outputs() return result else: print("There is no root_file in storage.") return {}
def outputs(args): if args.instance_path and not path.isdir(args.instance_path): raise argparse.ArgumentTypeError( "Directory {0} is not a valid path!".format(args.instance_path)) storage = Storage(Path(args.instance_path).joinpath( ".opera")) if args.instance_path else Storage(Path(".opera")) root = storage.read("root_file") inputs = storage.read_json("inputs") try: ast = tosca.load(Path.cwd(), PurePath(root)) template = ast.get_template(inputs) topology = template.instantiate(storage) # We need to instantiate the template in order to get access to the # instance state. print(format_outputs(template.get_outputs(), args.format)) except ParseError as e: print("{}: {}".format(e.loc, e)) return 1 except DataError as e: print(str(e)) return 1 return 0
def undeploy(args): storage = Storage(Path(".opera")) root = storage.read("root_file") inputs = storage.read_json("inputs") try: ast = tosca.load(Path.cwd(), PurePath(root)) template = ast.get_template(inputs) topology = template.instantiate(storage) topology.undeploy() except ParseError as e: print("{}: {}".format(e.loc, e)) return 1 except DataError as e: print(str(e)) return 1 return 0
def outputs(args): storage = Storage(Path(".opera")) root = storage.read("root_file") inputs = storage.read_json("inputs") try: ast = tosca.load(Path.cwd(), PurePath(root)) template = ast.get_template(inputs) topology = template.instantiate(storage) # We need to instantiate the template in order to get access to the # instance state. print(format_outputs(template.get_outputs(), args.format)) except ParseError as e: print("{}: {}".format(e.loc, e)) return 1 except DataError as e: print(str(e)) return 1 return 0
def outputs(storage: Storage) -> dict: """ :raises ParseError: :raises DataError: """ service_template = storage.read("root_file") inputs = storage.read_json("inputs") if storage.exists("csars"): csar_dir = Path(storage.path) / "csars" / "csar" ast = tosca.load(Path(csar_dir), PurePath(service_template).relative_to(csar_dir)) else: ast = tosca.load(Path.cwd(), PurePath(service_template)) template = ast.get_template(inputs) # We need to instantiate the template in order # to get access to the instance state. template.instantiate(storage) return template.get_outputs()