Updated on 2023-08-14 GMT+08:00

Creating a Template

Function

This API is used to create a template by uploading a local template to the server.

URI

POST /v2/templates

Request

  • Request parameters
    Table 1 Request parameters

    Parameter

    Mandatory

    Data Type

    Description

    resource

    Yes

    String

    Template content. For details, see UploadResource parameters.

    archive_content

    No

    String or Binary

    The file must be in the ZIP, TAR.GZ, TGZ, YAML, or JSON format.

    When content_type is set to yaml or json, the parameter type is String and the value is a YAML or JSON string.

    If the value of content_type is set to file or left blank, the parameter type is Binary and the value is the binary content of the file.

    Table 2 UploadResource parameters

    Parameter

    Mandatory

    Data Type

    Description

    name

    Yes

    String

    Template name. The value must be 1 to 64 characters long and start with a letter, but cannot end with a hyphen (-). Only lowercase letters, digits, and hyphens are allowed.

    description

    No

    String

    Template description. The value supports a maximum of 255 characters. A Chinese character is regarded as multiple characters. The following characters are not allowed: <>()#%&/

    scope

    No

    String

    Template application scope. Only the default value domain is supported.

    vendor

    No

    String

    Template provider. The value supports a maximum of 64 characters. A Chinese character is regarded as one character. The following characters are not allowed: <>()#%&/

    version

    Yes

    String

    Template version. The value supports a maximum of 24 characters and must meet the regular expression ^[a-zA-Z0-9_]+([-.][a-zA-Z0-9]+)*$.

    main_file_name

    No

    String

    Name of the main file of a template. If this parameter is left blank, the default value blueprint.yaml is used. The value supports a maximum of 255 characters. If this parameter is not left blank, the file name extension must be .yaml and the file name must comply with the regular expression ^[a-zA-Z0-9_]+([-.][a-zA-Z0-9]+)*$.

    project_id

    No

    String

    Project ID contained in the template to be uploaded.

    filename

    No

    String

    Name of the compressed package file. This parameter must be specified when the Internet Explorer is used. The value must be a string that supports a maximum of 64 characters.

    dsl_version

    No

    String

    If this parameter is not left blank, the DSL version of the uploaded template must be the same as the specified version. Otherwise, the template cannot be uploaded. DSL version of the template. Only huaweicloud_tosca_version_1_0 and fusionstage_tosca_version_2_1 are supported. By default, this parameter is left blank.

    content_type

    No

    String

    Template file type. The value can be yaml, json, or file.

    Parameters in the preceding two template upload scenarios cannot be mixed up. Otherwise, an error will be reported.

    Table 3 Request headers

    Parameter

    Mandatory

    Data Type

    Description

    Content-Type

    Yes

    String

    multipart/form-data.

    X-Auth-Token

    Yes

    String

    Valid token (a user token with the op_cred permission and a short validity period). This parameter is mandatory on the account side.

    For AOS API HTTP headers, if only parameters (in JSON format) are transmitted, Content-Type must be set to Application/json. Unless otherwise specified, other fields are the same as those listed in the preceding table.

Response message.

  • Response when the request is successful
    • Response parameters
      Table 4 Response parameter when the request is successful

      Parameter

      Data Type

      Description

      id

      String

      Template ID

    • Example response
      {
          "id": "d078e49c-124c-7706-bcbb-81885661f431"
      }
  • Response when the request fails
    • Response parameters
      Table 5 Response parameters when the request fails

      Parameter

      Data Type

      Description

      message

      String

      Detailed reason why the request fails.

      code

      String

      Code for the reason why the request fails.

      extend

      String

      Extended reason why the request fails. This field is reserved for future use.

      Unless otherwise specified, subsequent AOS API errors are returned in the following form:

    • Example response
      {
          "message": "Parameters validate err, The name should not be empty.",
          "code": "02000005",
          "extend": ""
      }

Status Codes

  • Normal
    Table 6 Status code

    Status Code

    Description

    201

    The template is created successfully.

  • Abnormal
    Table 7 Status codes

    Status Code

    Description

    400

    The request cannot be parsed by the server due to incorrect parameters. Unless being modified, the request should not be sent again.

    409

    The request cannot be completed due to a conflict with the current resource.

    500

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