文档首页/ 应用运维管理 AOM/ API参考/ API/ UniAgent管理/ 下发批量安装UniAgent任务 - BatchImportAgent
更新时间:2025-12-30 GMT+08:00
分享

下发批量安装UniAgent任务 - BatchImportAgent

功能介绍

该接口用于下发批量安装UniAgent任务。

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,需具备如下身份策略权限。

    授权项

    访问级别

    资源类型(*为必须)

    条件键

    别名

    依赖的授权项

    aom:uniagentAgent:install

    Write

    -

    -

    -

    -

URI

POST /v1/{project_id}/uniagent-console/mainview/batch-import

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,可以从控制台获取,也可以从调用API处获取。获取方式请参见:获取项目ID

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

region

String

参数解释:

当前可调用的地域。表示当前API开放的地域。填写region_id。

约束限制:

不涉及。

取值范围:

region列表,通过https://console.huaweicloud.com/apiexplorer/#/endpoint/AOM获取。

默认取值:

不涉及。

X-Auth-Token

String

参数解释:

从IAM服务获取的用户Token。获取方式请参见:获取Token

约束限制:

不涉及。

取值范围:

最小长度:1

最大长度:40960

默认取值:

不涉及。

Content-Type

String

参数解释:

消息体的类型(格式)。指定类型为“application/json”。

约束限制:

不涉及。

取值范围:

固定值。

默认取值:

application/json

表3 请求Body参数

参数

是否必选

参数类型

描述

agent_import_param_list

Array of AgentImportParamNew objects

参数解释:

导入待安装UniAgent的机器参数列表。

约束限制:

数组最小元素数:1

数组最大元素数:100

取值范围:

不涉及。

默认取值:

不涉及。

proxy_region_id

Integer

参数解释:

代理区域ID。获取方式:进入AOM控制台,单击”全局设置 > 代理区域管理“,进入代理区域管理页面,按F12,进入浏览器调试页面,https://console.huaweicloud.com/aom2/uniagent/v1/{projectid}/uniagent-console//proxy-region/proxy-agent-list接口的响应参数proxy_id的值。

约束限制:

不涉及。

取值范围:

  • 直连接入填0。

  • 代理接入填实际代理区域ID。

默认取值:

不涉及。

installer_agent_id

String

参数解释:

安装机的agent ID。获取方式:agent_id进入AOM控制台,单击”全局设置 > UniAgent管理“,进入UniAgent管理页面,按F12,进入浏览器调试页面,https://console.huaweicloud.com/aom2/uniagent/v1/{projectid}/uniagent-console/mainview/agent-list/ecs接口的响应参数agent_id的值。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

icagent_install_flag

Boolean

参数解释:

是否需要安装ICAgent插件。

约束限制:

不涉及。

取值范围:

  • true:安装ICAgent插件。默认安装最新版本的ICAgent插件。

  • false:不安装ICAgent插件。

默认取值:

不涉及。

plugin_install_base_param

PluginInstallBasicParam object

参数解释:

插件安装基础信息。

约束限制:

  • 当icagent_install_flag设置为true:如果plugin_install_base_param取值为空,默认安装最新版本ICAgent插件;如果plugin_install_base_param传入指定版本,则安装指定版本的ICAgent插件。

  • 当icagent_install_flag设置为false:无论是否传入该参数,都不安装ICAgent插件。

取值范围:

不涉及

默认取值:

不涉及。

version

String

参数解释:

待安装的UniAgent版本号。

约束限制:

UniAgent所支持的版本号。

取值范围:

1.1.8、1.2.0。

默认取值:

不涉及。

public_net_flag

Boolean

参数解释:

是否公网接入。

约束限制:

不涉及。

取值范围:

  • true:公网接入

  • false:非公网接入

默认取值:

不涉及。

表4 AgentImportParamNew

参数

是否必选

参数类型

描述

password

String

参数解释:

机器登录密码。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

agent_id

String

参数解释:

agent唯一值,重复导入时需要传递。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

inner_ip

String

参数解释:

机器IP。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

port

Integer

参数解释:

机器登录端口,默认22。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

22

account

String

参数解释:

机器ssh账号。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

os_type

String

参数解释:

机器操作系统类型。

约束限制:

不涉及。

取值范围:

  • linux

  • windows

默认取值:

不涉及。

vpc_id

String

参数解释:

机器所属VPC ID。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

coc_cmdb_id

String

参数解释:

外来唯一标识,COC用。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

表5 PluginInstallBasicParam

参数

是否必选

参数类型

描述

install_version

String

参数解释:

指定安装的ICAgent版本。

约束限制:

ICAgent所支持的版本。

取值范围:

7.6.0.1;7.6.0.3;7.6.0.5 等,具体版本可提工单咨询。

默认取值:

不涉及。

domain_ak

String

参数解释:

IAM账号AK。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

domain_sk

String

参数解释:

IAM账号SK。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

响应参数

状态码:200

表6 响应Body参数

参数

参数类型

描述

state

Boolean

参数解释:

执行状态

取值范围:

  • true:成功下发任务。

  • false:失败下发任务。

total_num

Integer

参数解释:

下发批量安装UniAgent任务的总数量。

取值范围:

不涉及。

fail_num

Integer

参数解释:

批量安装UniAgent任务执行的失败数量。

取值范围:

不涉及。

record_id

Integer

参数解释:

下发批量安装UniAgent任务的记录ID

取值范围:

不涉及。

error_msg

String

参数解释:

错误信息描述。

取值范围:

  • 执行状态为“false”时,该参数值返回对应的错误信息。

  • 执行状态为“true”时,该参数返回值为空

状态码:400

表7 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

非法请求错误码。

取值范围:

不涉及。

error_msg

String

参数解释:

错误信息。

取值范围:

不涉及。

状态码:403

表8 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

非法请求错误码。

取值范围:

不涉及。

error_msg

String

参数解释:

错误信息。

取值范围:

不涉及。

请求示例

下发批量安装UniAgent任务

https://{Endpoint}/v1/{project_id}/uniagent-console/mainview/batch-import

{
  "proxy_region_id" : 0,
  "public_net_flag" : false,
  "version" : "1.1.0",
  "icagent_install_flag" : false,
  "installer_agent_id" : "123456",
  "agent_import_param_list" : [ {
    "inner_ip" : "1.2.3.4",
    "os_type" : "LINUX",
    "port" : "22",
    "account" : "root",
    "password" : "************"
  } ]
}

响应示例

状态码:200

OK 请求响应成功。

{
  "state" : true,
  "fail_num" : 0,
  "total_num" : 1,
  "record_id" : 12345,
  "error_msg" : ""
}

状态码:400

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

{
  "error_code" : "AOM.32000003",
  "error_msg" : "Invalid parameter."
}

状态码:403

Forbidden 请求被拒绝访问。返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。

{
  "error_code" : "AOM.32000002",
  "error_msg" : "No permission."
}

SDK代码示例

SDK代码示例如下。

下发批量安装UniAgent任务

 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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.v4.region.AomRegion;
import com.huaweicloud.sdk.aom.v4.*;
import com.huaweicloud.sdk.aom.v4.model.*;

import java.util.List;
import java.util.ArrayList;

public class BatchImportAgentSolution {

    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");
        String projectId = "{project_id}";

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

        AomClient client = AomClient.newBuilder()
                .withCredential(auth)
                .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                .build();
        BatchImportAgentRequest request = new BatchImportAgentRequest();
        AgentBatchImportParamNew body = new AgentBatchImportParamNew();
        List<AgentImportParamNew> listbodyAgentImportParamList = new ArrayList<>();
        listbodyAgentImportParamList.add(
            new AgentImportParamNew()
                .withPassword("************")
                .withInnerIp("1.2.3.4")
                .withPort(22)
                .withAccount("root")
                .withOsType("LINUX")
        );
        body.withPublicNetFlag(false);
        body.withVersion("1.1.0");
        body.withIcagentInstallFlag(false);
        body.withInstallerAgentId("123456");
        body.withProxyRegionId(0);
        body.withAgentImportParamList(listbodyAgentImportParamList);
        request.withBody(body);
        try {
            BatchImportAgentResponse response = client.batchImportAgent(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());
        }
    }
}

下发批量安装UniAgent任务

 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkaom.v4.region.aom_region import AomRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkaom.v4 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 = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

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

    try:
        request = BatchImportAgentRequest()
        listAgentImportParamListbody = [
            AgentImportParamNew(
                password="************",
                inner_ip="1.2.3.4",
                port=22,
                account="root",
                os_type="LINUX"
            )
        ]
        request.body = AgentBatchImportParamNew(
            public_net_flag=False,
            version="1.1.0",
            icagent_install_flag=False,
            installer_agent_id="123456",
            proxy_region_id=0,
            agent_import_param_list=listAgentImportParamListbody
        )
        response = client.batch_import_agent(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

下发批量安装UniAgent任务

 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
53
54
55
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v4"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v4/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v4/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")
    projectId := "{project_id}"

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

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

    request := &model.BatchImportAgentRequest{}
	var listAgentImportParamListbody = []model.AgentImportParamNew{
        {
            Password: "************",
            InnerIp: "1.2.3.4",
            Port: int32(22),
            Account: "root",
            OsType: "LINUX",
        },
    }
	icagentInstallFlagAgentBatchImportParamNew:= false
	request.Body = &model.AgentBatchImportParamNew{
		PublicNetFlag: false,
		Version: "1.1.0",
		IcagentInstallFlag: &icagentInstallFlagAgentBatchImportParamNew,
		InstallerAgentId: "123456",
		ProxyRegionId: int32(0),
		AgentImportParamList: listAgentImportParamListbody,
	}
	response, err := client.BatchImportAgent(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK 请求响应成功。

400

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

403

Forbidden 请求被拒绝访问。返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。

错误码

请参见错误码

相关文档