示例#1
0
def deploy_compressed_csar(csar_path: PurePath, inputs: typing.Optional[dict],
                           storage: Storage, verbose_mode: bool,
                           num_workers: int, delete_existing_state: bool):
    if delete_existing_state:
        storage.remove("instances")

    if inputs is None:
        inputs = {}
    storage.write_json(inputs, "inputs")

    csars_dir = Path(storage.path) / "csars"
    csars_dir.mkdir(exist_ok=True)

    csar = CloudServiceArchive.create(csar_path)
    csar.validate_csar()
    tosca_service_template = csar.get_entrypoint()

    # unzip csar, save the path to storage and set workdir
    csar_dir = csars_dir / Path("csar")
    ZipFile(csar_path, "r").extractall(csar_dir)  # pylint: disable=consider-using-with
    csar_tosca_service_template_path = csar_dir / tosca_service_template
    storage.write(str(csar_tosca_service_template_path), "root_file")
    workdir = str(csar_dir)

    # initialize service template from CSAR and deploy
    ast = tosca.load(Path(csar_dir), Path(tosca_service_template))
    template = ast.get_template(inputs)
    topology = template.instantiate(storage)
    topology.deploy(verbose_mode, workdir, num_workers)
示例#2
0
def deploy(service_template: str, inputs: typing.Optional[dict],
           storage: Storage, verbose_mode: bool, num_workers: int,
           delete_existing_state: bool):
    """
    :raises ParseError:
    :raises DataError:
    """
    if delete_existing_state:
        storage.remove("instances")

    if inputs is None:
        if storage.exists("inputs"):
            inputs = yaml.safe_load(storage.read("inputs"))
        else:
            inputs = {}
    storage.write_json(inputs, "inputs")
    storage.write(service_template, "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.deploy(verbose_mode, workdir, num_workers)
示例#3
0
def deploy_service_template(service_template_path: PurePath,
                            inputs: typing.Optional[dict], storage: Storage,
                            verbose_mode: bool, num_workers: int,
                            delete_existing_state: bool):
    if delete_existing_state:
        storage.remove("instances")

    if inputs is None:
        if storage.exists("inputs"):
            inputs = yaml.safe_load(storage.read("inputs"))
        else:
            inputs = {}
    storage.write_json(inputs, "inputs")
    storage.write(str(service_template_path), "root_file")

    # set workdir and check if service template/CSAR has been initialized
    workdir = Path(service_template_path.parent)
    if storage.exists("csars"):
        csar_dir = Path(storage.path) / "csars" / "csar"
        workdir = csar_dir
        ast = tosca.load(workdir, service_template_path.relative_to(csar_dir))
    else:
        ast = tosca.load(workdir, PurePath(service_template_path.name))

    # initialize service template and deploy
    template = ast.get_template(inputs)
    topology = template.instantiate(storage)
    topology.deploy(verbose_mode, workdir, num_workers)