Exemplo n.º 1
0
def load(base_path, template_name):
    with (base_path / template_name).open() as input_fd:
        input_yaml = yaml.load(input_fd, str(template_name))
    if not isinstance(input_yaml.value, dict):
        raise ParseError(
            "Top level structure should be a map.",
            yaml_node.loc,
        )

    tosca_version = _get_tosca_version(input_yaml)
    parser = _get_parser(tosca_version)

    stdlib_yaml = stdlib.load(tosca_version)
    service = parser.parse(
        stdlib_yaml,
        base_path,
        PurePath("STDLIB"),
        set(),
    )[0]
    service.merge(
        parser.parse(
            input_yaml,
            base_path,
            template_name,
            set(),
        )[0])
    service.visit("resolve_path", base_path)
    service.visit("resolve_reference", service)

    return service
Exemplo n.º 2
0
def deploy(args):
    csar.save(args.name, args.csar.name)

    print("Loading service template ...")
    service_template = types.ServiceTemplate.from_data(stdlib.load())
    service_template.merge(
        types.ServiceTemplate.from_data(yaml.safe_load(args.csar)))

    print("Resolving service template links ...")
    service_template.resolve()

    print("Creating instance model ...")
    instances = service_template.instantiate()

    print("Deploying instance model ...")
    instances.deploy()

    print("Done.")

    return 0
Exemplo n.º 3
0
def undeploy(args):
    template_name = csar.load(args.name)

    print("Loading service template ...")
    service_template = types.ServiceTemplate.from_data(stdlib.load())
    with open(template_name) as fd:
        service_template.merge(
            types.ServiceTemplate.from_data(yaml.safe_load(fd))
        )

    print("Resolving service template links ...")
    service_template.resolve()

    print("Loading instance model ...")
    instances = service_template.instantiate()
    instances.load()

    print("Undeploying instance model ...")
    instances.undeploy()

    print("Done.")

    return 0