文档首页> 应用运维管理 AOM> API参考> API> 自动化运维(aom2.0接口)> 根据作业id查询方案(自定义模板)列表
更新时间:2024-05-14 GMT+08:00

根据作业id查询方案(自定义模板)列表

功能介绍

该接口可根据作业ID查询执行方案,分页返回执行方案列表。

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/cms/template-list/{job_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户从IAM申请到的projectid,一般为32位字符串。

最小长度:32

最大长度:32

job_id

String

作业id。

最小长度:1

最大长度:64

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token。

最小长度:1

最大长度:40960

Content-Type

String

指定类型为application/json。

最小长度:1

最大长度:32

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

方案名称

最小长度:1

最大长度:64

page_num

Integer

page_num为正整数

最小值:1

最大值:9999999

page_size

Integer

每页显示的条数

最小值:1

最大值:100

order_by_column

String

需要排序的字段(默认为更新时间),支持字段有name,create_time,update_time。

最小长度:1

最大长度:16

sort_order

String

排序规则(默认降序) 传入升序或降序,升序:ASC,降序:DESC。

最小长度:1

最大长度:16

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

total_elements

Long

总数

最小值:0

最大值:9999999

elements

Array of Template objects

查询作业信息集合

数组长度:0 - 9999999

表5 Template

参数

参数类型

描述

approve_info

ApproveInfo object

审批信息

create_by

String

模板创建人,从接口调用传入的token中获取。

最小长度:1

最大长度:64

create_time

Long

模板创建时间,为utc时间毫秒数。

最小值:0

最大值:9999999999999

enterprise_project_id

String

企业项目id

最小长度:1

最大长度:64

id

String

模板id,唯一标识,根据project_id和template_name生成。

最小长度:1

最大长度:64

is_collect

Boolean

模板是否收藏,不允许更新模板时修改,更改收藏状态调用单独的更新模板收藏状态接口

is_publish

Boolean

是否发布成服务

job_id

String

作业id

最小长度:1

最大长度:64

job_version

Integer

作业版本

最小值:1

最大值:999

name

String

模板名称

最小长度:1

最大长度:64

need_synchronize

Boolean

是否需要同步

nodes

Array of Node objects

任务执行时需要的参数列表。

数组长度:1 - 20

parameters

Array of Parameter objects

任务执行时需要的参数列表。

数组长度:0 - 20

project_id

String

项目id

最小长度:32

最大长度:32

quote

Array of strings

引用参数

最小长度:1

最大长度:256

数组长度:0 - 999

rate_control

RateControl object

执行策略

share_type

String

默认模板为public,自定义模板为private

最小长度:1

最大长度:16

steps

Array of Step objects

作业步骤

数组长度:1 - 20

update_by

String

模板更新人,从接口调用传入的token中获取。

最小长度:1

最大长度:64

update_time

Long

模板更新时间,为utc时间毫秒数。

最小值:0

最大值:9999999999999

version

String

模板版本

最小长度:1

最大长度:32

表6 ApproveInfo

参数

参数类型

描述

topic_selected

String

审批人主题选择。

最小长度:1

最大长度:2048

need_approve

Boolean

是否审核,默认是不审核,true,false。

smn_urn_list

String

审批主题urn集合。

最小长度:1

最大长度:2048

表7 Node

参数

参数类型

描述

parent_node

String

父亲节点的名称。

最小长度:1

最大长度:64

category

String

节点类型。

最小长度:1

最大长度:32

description

String

节点描述。

最小长度:1

最大长度:1024

id

String

节点id

最小长度:1

最大长度:64

ignore_error

Boolean

是否忽略错误

metadata

Metadata object

元数据。

name

String

节点名称,比如是Node。

最小长度:1

最大长度:64

task_name

String

任务名称,节点上任务的名称。

最小长度:1

最大长度:64

表8 Metadata

参数

参数类型

描述

type

String

节点类型。

最小长度:1

最大长度:32

configuration

Map<String,Object>

配置信息。

表9 Parameter

参数

参数类型

描述

param_name

String

参数名称。

param_type

String

参数类型。

最小长度:1

最大长度:16

param_group

String

参数分组。

最小长度:1

最大长度:32

default_value

String

参数初始值。

最小长度:1

最大长度:40960

id

String

参数id。

最小长度:1

最大长度:64

encryption

Boolean

是否加密。

hint

String

参数提示。

最小长度:1

最大长度:1000

quote_param

Boolean

是否从参数库选择。

required

Boolean

是否为必填参数。

description

String

参数描述。

最小长度:1

最大长度:1000

表10 RateControl

参数

参数类型

描述

have_rate_control

Boolean

是否分批发布,默认值是false。

time_delay

Integer

每批间隔。

最小值:1

最大值:60

max

Integer

每批支持的最大实例数。

最小值:0

最大值:100

表11 Step

参数

参数类型

描述

id

String

步骤id。

最小长度:1

最大长度:64

name

String

步骤名称。

最小长度:1

最大长度:32

type

String

步骤类型。

最小长度:1

最大长度:16

input

Map<String,String>

步骤参数。

ignore_error

Boolean

是否自动忽略错误。

description

String

步骤说明。

最小长度:1

最大长度:1000

状态码: 400

表12 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:64

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

http返回码

最小值:0

最大值:999

状态码: 401

表13 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:64

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

http返回码

最小值:0

最大值:999

请求示例

根据作业id和作业name查询作业的执行方案列表。

POST https://{Endpoint}/v1/{project_id}/cms/template-list/{job_id}

{
  "name" : "xxxxxx",
  "page_num" : 0,
  "page_size" : 10,
  "order_by_column" : "create_time",
  "sort_order" : "DESC"
}

响应示例

状态码: 200

请求响应成功,返回执行方案列表。

{
  "elements" : [ {
    "approve_info" : {
      "need_approve" : false
    },
    "create_by" : "xxxxx",
    "create_time" : 1600073877378,
    "enterprise_project_id" : "0",
    "id" : "xxxxxx",
    "is_collect" : false,
    "is_publish" : false,
    "job_id" : "xxxxx",
    "job_version" : 1,
    "name" : "t1",
    "need_synchronize" : false,
    "nodes" : [ {
      "category" : "service",
      "description" : "",
      "id" : "xxxxx",
      "ignore_error" : false,
      "metadata" : {
        "configuration" : {
          "parameters" : {
            "project_id" : "{{project_id}}",
            "script_param" : "{xxxx}",
            "region_id" : "{{region_id}}",
            "get_instances" : "{xxxxx}"
          }
        },
        "type" : "operation"
      },
      "name" : "1",
      "task_name" : "CMS::ECS::runScript"
    }, {
      "category" : "service",
      "description" : "",
      "id" : "xxxxx",
      "ignore_error" : false,
      "metadata" : {
        "configuration" : {
          "parameters" : {
            "package" : "{xxxxxx}",
            "project_id" : "{{project_id}}",
            "region_id" : "{{region_id}}",
            "get_instances" : "{xxxxx}"
          }
        },
        "type" : "operation"
      },
      "name" : "xxx",
      "task_name" : "CMS::ECS::Package"
    } ],
    "parameters" : [ ],
    "project_id" : "xxxxx",
    "quote" : [ ],
    "rate_control" : {
      "have_rate_control" : false,
      "max" : 0,
      "time_delay" : 0
    },
    "share_type" : "private",
    "steps" : [ {
      "description" : "",
      "id" : "xxxxx",
      "ignore_error" : false,
      "input" : {
        "script_param" : "{xxxxx}",
        "get_instances" : "{xxxxx}"
      },
      "name" : "xxxx",
      "type" : "script"
    }, {
      "description" : "",
      "id" : "xxxxx",
      "ignore_error" : false,
      "input" : {
        "package" : "{xxxxx}",
        "get_instances" : "{xxxxx}"
      },
      "name" : "2",
      "type" : "package"
    } ],
    "update_by" : "xxxxx",
    "update_time" : 1600073877378,
    "version" : "v1"
  } ],
  "total_elements" : 1
}

状态码: 400

BadRequest。非法请求。建议直接修改该请求,不要重试该请求。

{
  "error_code" : "AOM.31001202",
  "error_msg" : " parameter invalid.",
  "http_code" : 400
}

状态码: 401

Unauthorized。在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。

{
  "error_code" : "AOM.31009002",
  "error_message" : "auth failed.",
  "http_code" : "401"
}

SDK代码示例

SDK代码示例如下。

根据作业id和作业name查询作业的执行方案列表。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.aom.v1.region.AomRegion;
import com.huaweicloud.sdk.aom.v1.*;
import com.huaweicloud.sdk.aom.v1.model.*;


public class ListTemplateByJobIdSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        AomClient client = AomClient.newBuilder()
                .withCredential(auth)
                .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                .build();
        ListTemplateByJobIdRequest request = new ListTemplateByJobIdRequest();
        ListTemplateByJobIdRequestBody body = new ListTemplateByJobIdRequestBody();
        body.withSortOrder("DESC");
        body.withOrderByColumn("create_time");
        body.withPageSize(10);
        body.withPageNum(0);
        body.withName("xxxxxx");
        request.withBody(body);
        try {
            ListTemplateByJobIdResponse response = client.listTemplateByJobId(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

根据作业id和作业name查询作业的执行方案列表。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkaom.v1.region.aom_region import AomRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkaom.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = AomClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(AomRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListTemplateByJobIdRequest()
        request.body = ListTemplateByJobIdRequestBody(
            sort_order="DESC",
            order_by_column="create_time",
            page_size=10,
            page_num=0,
            name="xxxxxx"
        )
        response = client.list_template_by_job_id(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

根据作业id和作业name查询作业的执行方案列表。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := aom.NewAomClient(
        aom.AomClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListTemplateByJobIdRequest{}
	sortOrderListTemplateByJobIdRequestBody:= "DESC"
	pageSizeListTemplateByJobIdRequestBody:= int32(10)
	pageNumListTemplateByJobIdRequestBody:= int32(0)
	nameListTemplateByJobIdRequestBody:= "xxxxxx"
	request.Body = &model.ListTemplateByJobIdRequestBody{
		SortOrder: &sortOrderListTemplateByJobIdRequestBody,
		OrderByColumn: "create_time",
		PageSize: &pageSizeListTemplateByJobIdRequestBody,
		PageNum: &pageNumListTemplateByJobIdRequestBody,
		Name: &nameListTemplateByJobIdRequestBody,
	}
	response, err := client.ListTemplateByJobId(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求响应成功,返回执行方案列表。

400

BadRequest。非法请求。建议直接修改该请求,不要重试该请求。

401

Unauthorized。在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。

错误码

请参见错误码