Help Center/ CodeArts Deploy/ API Reference/ Application Examples/ Example 2: Querying Host Cluster Details by ID
Updated on 2024-07-04 GMT+08:00

Example 2: Querying Host Cluster Details by ID

Scenario

This section uses a CodeArts user as an example to guide you using an API to query details about a specified host cluster.

For details on how to call APIs, see Calling APIs.

Prerequisite

You have created a CodeArts project, and host clusters exist in the project.

Approach

Use an API to query the list of all host clusters, obtain group_id of the target host cluster, and use group_id to query details about the host cluster details. The procedure is as follows:

  1. Query all host clusters of a user.
  2. Query details about a host cluster.

Step 1: Querying All Host Clusters of a User

  • API information:
    URI: GET /v2/host-groups
  • Request example:
    GET  https://{endpoint}/v2/host-groups?region_name=ap-southeast-3&project_id=6039d4480efc4dddb178abff98719913&offset=1&limit=10&sort_key=create_time&sort_dir=DESC
  • Response example:
    { 
      "total" : 1, 
      "host_groups" : [ { 
        "name" : "testwyk", 
        "description" : "11122211", 
        "os" : "linux", 
        "nick_name" : "A/B_side_account",
        "id" : 200001291, 
        "group_id" : "ab7647b0863c4e969c8949d38d591339", 
        "region_name" : "ap-southeast-3",
        "project_id" : "6039d4480efc4dddb178abff98719913", 
        "permission" : { 
          "can_view" : true, 
          "can_edit" : true, 
          "can_delete" : true, 
          "can_add_host" : true, 
          "can_manage" : true 
        }, 
        "created_by" : { 
          "user_id" : "6baa7454109d47c192f22078fe6cda20", 
          "user_name" : "devcloud_devcloud_l00490255_01" 
        }, 
        "updated_by" : { 
          "user_id" : "6baa7454109d47c192f22078fe6cda20", 
          "user_name" : "devcloud_devcloud_l00490255_01" 
        }, 
        "auto_connection_test_switch" : 0, 
        "slave_cluster_id" : "", 
        "created_time" : "2021-04-01 17:05:53", 
        "updated_time" : "2021-04-21 14:29:14", 
        "host_count" : 1, 
        "project_name" : null 
      } ] 
    }

Step 2: Querying Details About a Host Cluster

  • API information:
    URI: GET /v2/host-groups/{group_id}
  • Request example:
    GET  https://{endpoint}/v2/host-groups/ab7647b0863c4e969c8949d38d591339
  • Response example:
    { 
      "name" : "test", 
      "description" : "11122211", 
      "os" : "linux", 
      "region_name" : "ap-southeast-3", 
      "project_id" : "6039d4480efc4dddb178abff98719913", 
      "created_by" : { 
        "user_id" : "6baa7454109d47c192f22078fe6cda20", 
        "user_name" : "devcloud_devcloud_l00490255_01" 
      }, 
      "updated_by" : { 
        "user_id" : "6baa7454109d47c192f22078fe6cda20", 
        "user_name" : "devcloud_devcloud_l00490255_01" 
      }, 
      "permission" : { 
        "can_view" : true, 
        "can_edit" : true, 
        "can_delete" : true, 
        "can_add_host" : true, 
        "can_manage" : true 
      }, 
      "auto_connection_test_switch" : 0, 
      "slave_cluster_id" : "", 
      "nick_name" : "A/B_side_account", 
      "group_id" : "ab7647b0863c4e969c8949d38d591339", 
      "created_time" : "2021-04-01 17:05:53", 
      "updated_time" : "2021-04-21 14:29:14", 
      "host_count" : 1 
    }