Querying Resources
Function
This API is used to query instances of a specified resource type by project ID.
By default, resources and resource tags are in descending order of their creation time.
URI
POST /autoscaling-api/v1/{project_id}/{resource_type}/resource_instances/action
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Specifies the project ID. |
resource_type |
Yes |
String |
Specifies the resource type. An example value is scaling_group_tag. |
Request Message
- Request parameters
Table 2 Request parameters Parameter
Mandatory
Type
Description
tags
No
Array
Specifies filter criteria with tags included. A maximum of 10 keys can be contained. The structure body must be complete. For details, see Table 3.
tags_any
No
Array
Specifies filter criteria with any tag included. A maximum of 10 keys can be contained. For details, see Table 3.
not_tags
No
Array
Specifies filter criteria without tags included. A maximum of 10 keys can be contained. For details, see Table 3.
not_tags_any
No
Array
Specifies filter criteria without any tag included. A maximum of 10 keys can be contained. For details, see Table 3.
limit
No
String
Specifies the maximum number of query records. The maximum value is 1000, and the minimum value is 1.
- If the action value is count, this parameter is invalid.
- If the action value is filter, the default value is 1000.
action
Yes
String
Specifies the operation, which can be filter or count.
- filter: indicates that resources are filtered by tag and the resources meeting the search criteria are returned on pages.
- count: indicates that resources are searched by tag and the number of resources meeting the search criteria is returned.
offset
No
String
Specifies the index position. The query starts from the next image indexed by this parameter. The value must be a non-negative number.
You do not need to specify this parameter when querying resources on the first page. When you query resources on subsequent pages, set the value of offset to the location returned in the response body for the previous query.
- If the action value is count, this parameter is invalid.
- If the action value is filter, the default value is 0.
matches
No
Array
Specifies fuzzy search. For details, see Table 4.
Table 3 Tag field description Parameter
Mandatory
Type
Description
key
Yes
String
Specifies the resource tag key. It contains a maximum of 127 Unicode characters. It cannot be left blank (This parameter is not verified in the search process.) A maximum of 10 keys are allowed and the key cannot be left blank or an empty string. Each key must be unique.
values
Yes
Array
Specifies resource tag values. A value contains a maximum of 255 Unicode characters. A key contains a maximum of 10 values. Each value of the same key must be unique.
- The asterisk (*) is reserved for the system. If the value starts with *, it indicates that fuzzy match is performed for the digits following *. The value cannot contain only asterisks (*).
- If the values are null (not default), it indicates any_value (querying any value). The resources contain one or multiple values listed in values will be found and displayed.
Table 4 match field description Parameter
Mandatory
Type
Description
key
Yes
String
Specifies the key parameter to be matched.
The parameter value can only be resource_name.
value
Yes
String
Specifies the value. The value is a fixed dictionary value. A value contains a maximum of 255 Unicode characters. If the value is an empty string or resource_id, exact match is used.
- Example request
- Example request when action is set to filter
This example shows how to query AS group resources of a tenant using the following search criteria: including tag (key = key1 and value = value), excluding tag (key = key2 and value = value2), index position 100, and maximum number of records 100.
POST https: //{Endpoint}/autoscaling-api/v1/{project_id}/scaling_group_tag/resource_instances/action { "offset": "100", "limit": "100", "action": "filter", "matches": [{ "key": "resource_name", "value": "resource1" }], "not_tags": [{ "key": "key2", "values": ["value2"] }], "tags": [{ "key": "key1", "values": ["value1"] }] }
- Example request when action is set to count
This example shows how to query the number of AS group resources for a tenant using the following search criteria: including the tag (key = key1 and value = value) and excluding the tag (key = key2 and value = value2).
POST https: //{Endpoint}/autoscaling-api/v1/{project_id}/scaling_group_tag/resource_instances/action { "action": "count", "not_tags": [{ "key": "key2", "values": ["value2"] }], "tags": [{ "key": "key1", "values": ["value1"] }, { "key": "key2", "values": ["value1", "value2"] }], "matches": [{ "key": "resource_name", "value": "resource1" }] }
- Example request when action is set to filter
Response Message
- Response parameters
Table 5 Response parameters Parameter
Type
Description
resources
Array
Specifies tag resources. For details, see Table 6.
total_count
Integer
Specifies the total number of records. When action is set to count, only this parameter is returned. The values of resources and marker are not returned.
marker
String
Specifies the paging location identifier.
Table 6 Resource field description Parameter
Type
Description
resource_id
String
Specifies the resource ID.
resource_detail
String
Specifies the resource details.
tags
Array
Specifies tags. If there is no tag, tags is taken as an empty array by default. For details, see Table 7.
resource_name
String
Specifies the resource name. If there is no resource, this parameter is an empty string by default.
- Example response
- Example response when action is set to filter
{ "resources": [{ "resource_id": "64af4b6f-ec51-4436-8004-7a8f30080c87", "resource_detail": "SCALING_GROUP_TAG", "tags": [{ "key": "key1","value": "value1" }], "resource_name": "as_scaling_group_1" }, { "resource_id": "7122ef51-604b-40e7-b9b2-1de4cd78dc60", "resource_detail": "SCALING_GROUP_TAG", "tags": [{ "key": "key1","value": "value1" }], "resource_name": "as_scaling_group_2" }, "marker": "2", "total_count": 2 }
- Example response when action is set to count
{ "total_count": 1000 }
- Example response when action is set to filter
Returned Values
- Normal
- Abnormal
Returned Values
Description
400 Bad Request
The server failed to process the request.
401 Unauthorized
You must enter the username and password to access the requested page.
403 Forbidden
You are forbidden to access the requested page.
404 Not Found
The server could not find the requested page.
405 Method Not Allowed
You are not allowed to use the method specified in the request.
406 Not Acceptable
The response generated by the server could not be accepted by the client.
407 Proxy Authentication Required
You must use the proxy server for authentication so that the request can be processed.
408 Request Timeout
The request timed out.
409 Conflict
The request could not be processed due to a conflict.
500 Internal Server Error
Failed to complete the request because of an internal service error.
501 Not Implemented
Failed to complete the request because the server does not support the requested function.
502 Bad Gateway
Failed to complete the request because the request is invalid.
503 Service Unavailable
Failed to complete the request because the system is unavailable.
504 Gateway Timeout
A gateway timeout error occurred.
Error Codes
See Error Codes.
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