Updated on 2022-02-22 GMT+08:00

Creating a Stack

Function

This API is used to create a stack.

The stack input consists of the template and input parameters.

  • Template defines the framework of the stack, and determines the structure of the internal nodes of the stack, the relationships between nodes, and the value or source of the attributes of each node.
  • Input parameters are one of the sources of the node attribute values in the template. They are defined in the input fields of the template and are triggered by the get_input function in the template.

URI

POST /v2/stacks

Request

  • Request parameters
    Table 1 Request parameters

    Parameter

    Mandatory

    Type

    Description

    name

    Yes

    String

    Stack name Restrictions are the same as the name field in Table 2.

    project_id

    Yes

    String

    ID of the project to which the stack belongs. The default value is the project to which the user token belongs. If this parameter is set, the value must be the same as the project information in the user token.

    The value supports a maximum of 63 character and cannot start or end with a hyphen (-). Only lowercase letters, digits, and hyphens are allowed.

    description

    No

    String

    Stack description Restrictions are the same as the description field in Table 2.

    template_id

    Yes

    String

    ID of the template used by the stack. The value supports a maximum of 64 characters.

    inputs_json

    No

    Object

    Input parameter of the template used by the stack.

    Each key-value structure in this parameter corresponds to a key field in the inputs, and the input value is value.

    If a key is not specified, the default value specified by the key is used. If no default value is specified, an error is reported.

    Example: "{'template_input_key': 'value'}"

    force

    No

    Boolean

    Force tailoring ID of the stack. This parameter is applicable to tailoring scenarios.

    labels

    No

    Object

    Stack label. Each internal key-value indicates a label. The key/value field supports a maximum of 64 characters, and must comply with the regular expression ^[a-zA-Z0-9_]+[-.a-zA-Z0-9_]*$.

    namespace

    No

    String

    This parameter must be specified when CCE resources and applications are orchestrated. If the value is not read from CCE, default is used by default.

    cluster_id

    No

    String

    This parameter must be specified when CCE resources and applications are orchestrated. ID of the cluster to which the stack belongs.

    action_parameters

    No

    Object

    After a stack is created, lifecycle configurations are automatically executed and installed. Restrictions are the same as those in Table 2.

    Table 2 Lifecycle configurations

    Parameter

    Mandatory

    Type

    Description

    failure_strategy

    No

    String

    Failure strategy. The default value is DoNothing. The value can be DoNothing or Rollback.

    auto_create

    Yes

    Boolean

    The default value is true.

    timeout

    No

    Integer

    Lifecycle timeout period (in minutes). The default value is 60 minutes. The value supports a maximum of 1440 minutes (that is, one day).

    When the inputs_json parameter is set to the attribute of a VM application and a valid URL is not entered in the url or name field, the name/version/repository field is used to access SWR for fuzzy search. The efficiency is low when there are a large number of files in the software repository. A feasible solution is to fill in the url field to avoid fuzzy search or specify the name, version, repository parameters in detail to reduce the search scope.

    • url: http://SWR.url/xxx/file.tgz (recommended)
    • name: file.tgz; version: v1; repository: myProject (good)
    • name: file.tgz (low-efficiency)
  • Example request
    {
        "name": "aos-lm-verydows-t1",
        "template_id": "b417b635-6ab2-1fed-b593-b129a9923ba2",
        "project_id": "10556c2112784111b8bf10512591189e",
        "cluster_id": "46c547ca-e96c-11e7-98b9-0255ac102005",
        "inputs_json": {
            "ecsng-image": "192.168.3.88:20202/default/verydows-ecsng:2.1.1",
            "mysql-image": "192.168.3.88:20202/tangtao/verydows-mysql:5.6.35",
            "redis-image": "192.168.3.88:20202/default/verydows-redis:4.0.2_passwd",
            "verydows-image": "192.168.3.88:20202/default/verydows:2.3.1",
            "verydows-install-image": "192.168.3.88:20202/default/verydows:2.3.1",
            "mysql-name": "verydows-mysql-t1"
        }
    }

Response

  • Response parameters

    A response parameter is a stack structure or response structure.

    • The stack structure is returned when the creation is successful.
    • The error response structure is returned when the creation fails.

    The stack structure is shown in Table 3 Response parameters and the returned incorrect response structure is shown in Table 5.

    Table 3 Response parameters

    Parameter

    Type

    Description

    name

    String

    Stack name

    guid

    String

    Stack ID

    description

    String

    Stack description

    project_id

    String

    ID of the project to which the stack belongs

    domain_id

    String

    Account to which the stack belongs

    template_id

    String

    Template ID

    template_name

    String

    Template name

    inputs_json

    String

    Input parameter of the template used by the stack

    status

    String

    Stack status

    create_at

    String

    Stack creation time

    update_at

    String

    Stack update time

    force

    Boolean

    Force tailoring ID of the stack. This parameter is applicable to tailoring scenarios.

    labels

    String

    Stack label

    cluster_id

    String

    ID of the cluster where the stack is located

    cluster_name

    String

    Name of the cluster where the stack is located

    namespace

    String

    Namespace to which the stack belongs

    template_version

    String

    Version of the template used by the stack

    dsl_version

    String

    Syntax version of the template used by the stack

  • Example response when the request is successful
    {
        "force": true,
        "guid": "d956ea24-e979-11e7-9764-0255ac103504",
        "namespace": "default",
        "project_id": "c261c106051448479eb7c66549866011",
        "cluster_name": "test-not-delete",
        "cluster_id": "46c547ca-e96c-11e7-98b9-0255ac102005",
        "domain_id": "ef09dd6cc93f4653b5557181b802ee71",
        "name": "aos-lm-verydows-t1",
        "description": "",
        "status": "",
        "template_id": "b417b635-6ab2-1fed-b593-b129a9923ba2",
        "previous_template_id": "",
        "template_name": "verydows",
        "healthy": true,
        "healthy_message": "",
        "inputs_json": "{\"ecsng-container-port\":80,\"ecsng-image\":\"192.168.3.88:20202/default/verydows-ecsng:2.1.1\",\"imagePullPolicy\":\"IfNotPresent\",\"mysql-container-port\":3306,\"mysql-database\":\"verydows\",\"mysql-image\":\"192.168.3.88:20202/tangtao/verydows-mysql:5.6.35\",\"mysql-name\":\"verydows-mysql-t1\",\"mysql-password\":\"******\",\"mysql-port\":13306,\"mysql-root-password\":\"******\",\"mysql-user\":\"verydows\",\"redis-container-port\":6379,\"redis-image\":\"192.168.3.88:20202/default/verydows-redis:4.0.2_passwd\",\"redis-password\":\"******\",\"redis-port\":16379,\"verydows-container-port\":80,\"verydows-http-host\":\"\",\"verydows-image\":\"192.168.3.88:20202/default/verydows:2.3.1\",\"verydows-install-image\":\"192.168.3.88:20202/default/verydows:2.3.1\",\"verydows-port\":8088}",
        "previous_inputs_json": "",
        "create_at": "",
        "update_at": "",
        "labels": "",
        "template_version": "2.0.1",
        "dsl_version": "cloud_tosca_version_1_0"
    }
  • Example response when the request fails
    {
        "message": "The request body is invalid, please check. Error: The stack name is already existed.",
        "code": "02030008",
        "extend": ""
    }

Status Code

  • Normal
    Table 4 Status code

    Status Code

    Description

    201

    The stack is successfully created.

  • Abnormal
    Table 5 Status code

    Status Code

    Description

    400

    The request parameter is invalid or more than one package exists.

    404

    The package defined in the template does not exist.

    500

    The server fails to process the request due to an unexpected condition.