Example 3: Querying the Host List of a Specified Host Cluster
Scenario
This section uses a CodeArts user as an example to describe how to use an API to query the hosts in the specified host cluster.
For details on how to call APIs, see Calling APIs.
Prerequisite
You have created a CodeArts project and the project has a host cluster.
Approach
Use a user token to query the host group cluster, and use group_id to query the host list of the specified host cluster. The procedure is as follows:
- Query all host clusters of a user.
- Query the host list of 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 the Host List
- API information:
URI: GET /v2/host-groups/{group_id}/hosts
- Request example:
GET https://{endpoint}/v2/host-groups/ab7647b0863c4e969c8949d38d591339/hosts?offset=0&limit=10&sort_key=AS_PROXY&sort_dir=asc&with_auth=false - Response example:
{ "hosts" : [ { "hostname" : "100.101.28.203", "ip" : "100.101.28.203", "port" : 22, "os" : "linux", "authorization" : { "username" : "root", "password" : null, "private_key" : null, "trusted_type" : 0 }, "permission" : { "can_view" : true, "can_edit" : true, "can_delete" : true, "can_add_host" : true, "can_connection_test" : true }, "nickName" : "A/B_side_account", "id" : 200001149, "host_id" : "2cc913cc9a494f09b7320801ebacad02", "group_id" : "ab7647b0863c4e969c8949d38d591339", "as_proxy" : false, "proxy_host_id" : null, "owner_id" : "6baa7454109d47c192f22078fe6cda20", "owner_name" : "devcloud_devcloud_l00490255_01", "updator_id" : "6baa7454109d47c192f22078fe6cda20", "updator_name" : "devcloud_devcloud_l00490255_01", "connection_status" : "success", "install_icagent" : false, "create_time" : "2021-04-15 11:01:51", "update_time" : "2021-04-21 15:04:24", "connection_result" : "Connected", "lastest_connection_time" : "2021-04-15 11:02:00", "nick_name" : "A/B_side_account", "proxy_host" : null, "group_name" : null, "project_id" : "6039d4480efc4dddb178abff98719913", "project_name" : null } ], "total" : 1, "group_name" : "test" }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot