更新时间:2024-11-26 GMT+08:00

查询绑定在节点上的资源列表

功能介绍

该接口用于查询绑定在节点上的资源列表。

调用方法

请参见如何调用API

URI

POST /v1/resource/{rf_resource_type}/type/{type}/ci-relationships

表1 路径参数

参数

是否必选

参数类型

描述

rf_resource_type

String

云服务资源,同rms服务的provider

type

String

云服务资源类型,同rms服务的type

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token。

Content-Type

String

指定类型为application/json,有Body体的情况下必选,没有Body体则无需填写和校验。

表3 请求Body参数

参数

是否必选

参数类型

描述

marker

String

页面的分页标志位,为分页的最后一条记录的id

limit

Integer

查询返回记录的数量限制。limit可以为空,如果值小于1或者大于100,则会使用默认值100

keywords

Map<String,String>

关键字模糊搜索。Key取值:NAME、RESOURCE_ID

ci_relationships

Boolean

是否需要返回拓扑树,默认是false。需要:true---性能差,不需要false--性能好

ci_type

String

节点类型,取值:application、sub_application、component、environment

ci_region

String

环境的region信息,若没有值,代表全部

ci_ids

Array of strings

节点id列表;如果ci_ids和ci_id同时有,则优先ci_ids,但是不能同时为空

ci_id

String

节点id列表;如果ci_ids和ci_id同时有,则优先ci_ids,但是不能同时为空。但是不支持应用批量查询

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

data

Array of objects

分页查询的数据。

page_info

Object

分页信息。

状态码: 400

表5 响应Body参数

参数

参数类型

描述

error_code

String

AOM.30005001

error_msg

String

参数错误

状态码: 403

表6 响应Body参数

参数

参数类型

描述

error_code

String

AOM.30001005

error_msg

String

没有权限

请求示例

获取节点下资源列表

https://{Endpoint}/v1/resource/{rf_resource_type}/type/{type}/ci-relationships

{
  "ci_ids" : [ "63c2195e9da846258b113205184b2b53" ],
  "ci_relationships" : true,
  "ci_type" : "environment"
}

响应示例

状态码: 200

资源关联返回的信息

{
  "data" : [ {
    "id" : "7015d303a8454f49a289dd47ada4b60c",
    "resource_id" : "aom_7015d303a8454f49a289dd47ada4b60c",
    "resource_name" : "luban121000000333",
    "resource_region" : "xxx",
    "env_ids" : [ "63c2195e9da846258b113205184b2b53" ],
    "topology" : [ {
      "app_id" : "07f6836530e24efdab068aacef933d4b",
      "app_name" : "test91",
      "sub_app_id" : "b554711fb4774bf98cfbdfa955a2d640",
      "sub_app_name" : "sub-888",
      "component_id" : "b218263a62554ad6aa976908e4990cf3",
      "component_name" : "组件99",
      "env_id" : "63c2195e9da846258b113205184b2b53",
      "env_name" : "环境22",
      "env_region" : "xxx",
      "os_type" : "LINUX"
    } ],
    "status" : "ACTIVE",
    "cloud_vendors" : "His",
    "agent_state" : "UNINSTALLED",
    "vpc_id" : " 6681507e-779e-4d0d-9421-5df07b95cca6 ",
    "addresses" : [ {
      "host_ip" : "117.1.0.1",
      "ip_type" : "fixed",
      "ip_version" : 4,
      "mac" : null
    }, {
      "host_ip" : "179.1.0.1",
      "ip_type" : "floating",
      "ip_version" : 4,
      "mac" : null
    } ]
  }, {
    "id" : "2c6fd895c88742559f2fd6c57817cf93",
    "resource_id" : "aom_2c6fd895c88742559f2fd6c57817cf93",
    "env_ids" : [ "63c2195e9da846258b113205184b2b53" ],
    "topology" : [ {
      "app_id" : "07f6836530e24efdab068aacef933d4b",
      "app_name" : "test91",
      "sub_app_id" : "b554711fb4774bf98cfbdfa955a2d640",
      "sub_app_name" : "sub-888",
      "component_id" : "b218263a62554ad6aa976908e4990cf3",
      "component_name" : "组件99",
      "env_id" : "63c2195e9da846258b113205184b2b53",
      "env_name" : "环境22",
      "env_region" : "xxx",
      "os_type" : "LINUX"
    } ],
    "cloud_vendors" : "His",
    "agent_state" : "UNINSTALLED",
    "addresses" : [ {
      "host_ip" : "1.3.4.5",
      "ip_type" : "fixed",
      "ip_version" : 4,
      "mac" : null
    } ]
  } ],
  "page_info" : {
    "next_marker" : null,
    "current_count" : 2
  }
}

SDK代码示例

SDK代码示例如下。

获取节点下资源列表

 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
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.v3.region.AomRegion;
import com.huaweicloud.sdk.aom.v3.*;
import com.huaweicloud.sdk.aom.v3.model.*;

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

public class ListResourceUnderNodeSolution {

    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();
        ListResourceUnderNodeRequest request = new ListResourceUnderNodeRequest();
        request.withRfResourceType("{rf_resource_type}");
        request.withType("{type}");
        PageResourceListParam body = new PageResourceListParam();
        List<String> listbodyCiIds = new ArrayList<>();
        listbodyCiIds.add("63c2195e9da846258b113205184b2b53");
        body.withCiRelationships(true);
        body.withCiIds(listbodyCiIds);
        body.withCiType("environment");
        request.withBody(body);
        try {
            ListResourceUnderNodeResponse response = client.listResourceUnderNode(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());
        }
    }
}

获取节点下资源列表

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

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkaom.v3.region.aom_region import AomRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkaom.v3 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"]

    credentials = BasicCredentials(ak, sk)

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

    try:
        request = ListResourceUnderNodeRequest()
        request.rf_resource_type = "{rf_resource_type}"
        request.type = "{type}"
        listCiIdsbody = [
            "63c2195e9da846258b113205184b2b53"
        ]
        request.body = PageResourceListParam(
            ci_relationships=True,
            ci_ids=listCiIdsbody,
            ci_type="environment"
        )
        response = client.list_resource_under_node(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

获取节点下资源列表

 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/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v3/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.ListResourceUnderNodeRequest{}
	request.RfResourceType = "{rf_resource_type}"
	request.Type = "{type}"
	var listCiIdsbody = []string{
        "63c2195e9da846258b113205184b2b53",
    }
	ciRelationshipsPageResourceListParam:= true
	request.Body = &model.PageResourceListParam{
		CiRelationships: &ciRelationshipsPageResourceListParam,
		CiIds: &listCiIdsbody,
		CiType: "environment",
	}
	response, err := client.ListResourceUnderNode(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

资源关联返回的信息

400

参数错误

403

没有权限

错误码

请参见错误码