Updated on 2024-06-28 GMT+08:00

Querying the Resource List of a Node

Function

This API is used to query the resource list of a node.

Calling Method

For details, see Calling APIs.

URI

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

rf_resource_type

Yes

String

Cloud service resource, which is the same as provider of Resource Management Service (RMS).

type

Yes

String

Cloud service resource type, which is the same as type of RMS.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token obtained from IAM.

Content-Type

Yes

String

Content type, which is application/json. This parameter is mandatory only when the body exists.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

marker

No

String

Pagination marker, which is the ID of the last record on the previous page.

limit

No

Integer

Maximum number of records that can be returned. This parameter can be empty. If its value is less than 1 or greater than 100, the default value 100 will be used.

keywords

No

Map<String,String>

Keywords for fuzzy search. Options: NAME and RESOURCE_ID.

ci_relationships

No

Boolean

Whether to return the topology tree. Default: false. true: The topology will be returned, but the performance will be affected. false: No topology will be returned, and the performance will not be affected.

ci_type

Yes

String

Node type. Options: application, sub_application, component, and environment.

ci_region

No

String

Region associated with the environment. If this parameter is left blank, it represents all regions.

ci_ids

No

Array of strings

Node ID list. If both ci_ids and ci_id are specified, ci_ids will be used. They cannot be empty at the same time.

ci_id

No

String

Node ID list. If both ci_ids and ci_id are specified, ci_ids will be used. They cannot be empty at the same time. However, batch application query is not supported.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

data

Array of objects

Data displayed during page query.

page_info

Object

Pagination information.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_code

String

AOM.30005001

error_msg

String

Invalid parameters.

Status code: 403

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

AOM.30001005

error_msg

String

No permissions.

Example Requests

Obtain the resource list of a node.

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

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

Example Responses

Status code: 200

Information about the related resources is returned.

{
  "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" : "Component 99",
      "env_id" : "63c2195e9da846258b113205184b2b53",
      "env_name" : "Environment 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" : "Component 99",
      "env_id" : "63c2195e9da846258b113205184b2b53",
      "env_name" : "Environment 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 Sample Code

The SDK sample code is as follows.

Java

Obtain the resource list of a node.

 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
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();
        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());
        }
    }
}

Python

Obtain the resource list of a node.

 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
# 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()
        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)

Go

Obtain the resource list of a node.

 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
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{}
	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)
    }
}

More

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Information about the related resources is returned.

400

Invalid parameters.

403

No permissions.

Error Codes

See Error Codes.