Creating a Query

Scenarios

Before using Advanced Queries to query how a specific Huawei Cloud resource is configured, you need to create your own query and customize query statements based on resource configuration attributes.

Procedure

  1. Log in to the management console.
  2. In the upper right corner of the page, choose Resources > My Resources.

    Figure 1 RMS service entry

    If the resolution of the screen is low, in the upper right corner of the page, choose More > Resources > My Resources.

    Figure 2 RMS service entry (low resolution)

    Alternatively, click in the upper left corner of the page. In the service list that is displayed, under Management & Governance, select Resource Management.

  3. In the navigation pane on the left, choose Advanced Queries.
  4. Click Create Query in the upper right corner of the page.
  5. In the query editor, enter the query statement as prompted.

    For details, see Configuration Examples of Advanced Queries.

    Figure 3 Query Editor

  6. Click Save Query and enter the query name and description.

    The query name can contain only digits, letters, underscores (_), and hyphens (-).

  7. Click OK.

    Figure 4 Save Query

    If the maximum number of custom queries has been reached, you cannot click Save Query. In addition, message The maximum number of custom queries has been reached. Delete unnecessary queries. is displayed in the upper right corner of the page.

    When the maximum number of custom queries has been reached, you can run the queries and export the query results.

  8. Click Run and then view the query results. Only the first 1000 query results can be displayed and saved.
  9. Click Export and select the format of the file to be exported (CSV or JSON).

Other Operations

You can modify the name, description, and query statement of a query. After you click Save As, a new query is created. The following procedure uses a default query as an example to describe how to modify a query.

  1. In the navigation pane on the left, choose Advanced Queries.

    By default, the default query list is displayed.

    Figure 5 Default Queries

  2. Locate the default query and click Query in the Operation.

    Alternatively, click the query name to go to the query overview page, and then click Query in the lower right corner to go to the Query page.

  3. In the query editor, modify the query statement as prompted.

    For details, see Configuration Examples of Advanced Queries.

  4. Click Save As and enter the query name and description.
  5. In the dialog box that is displayed, click OK.

    New queries generated through the Save As operation is updated in the custom query list.

Configuration Examples of Advanced Queries

ResourceQL uses a subset of the SQL SELECT syntax to query how your Huawei Cloud resources are configured and how they are related to one another. You do not need to call specific APIs for the query or use multiple APIs to download full data and manually analyze the data. ResourceQL can only query data from the resources table.

Table 1 Parameter descriptions in table resources

Parameter

Type

Description

id

String

Specifies the resource ID.

name

String

Specifies the resource name.

provider

String

Specifies the cloud service name.

type

String

Specifies the resource type.

region_id

String

Specifies the region ID.

project_id

String

Specifies the project ID.

ep_id

String

Specifies the enterprise project ID.

checksum

String

Specifies the resource checksum.

created

Date

Specifies the time when the resource was created.

updated

Date

Specifies the time when the resource was updated.

provisioning_state

String

Specifies the status of the operation that causes the resource change.

tag

Array(Map<String,String>)

Specifies the resource tag.

properties

Map<String,Object>

Specifies the detailed properties of the resource.

Example quires are as follows:

  • Example 1: List ECSs in the Stopped state.
    SELECT name
    FROM resources
    WHERE provider = 'ecs'
    	AND type = 'cloudservers'
    	AND properties.status = 'SHUTOFF'
  • Example 2: List EVS disks with certain specifications.
    SELECT *
    FROM resources
    WHERE provider = 'evs'
    	AND type = 'volumes'
    	AND properties.size = 100
  • Example 3: List OBS buckets queried by fuzzy search.
    SELECT *
    FROM resources
    WHERE provider = 'obs'
    	AND 'type' = 'buckets'
    	AND name LIKE '%figure%'
  • Example 4: List ECSs and the EVS disks attached to each ECS.
    SELECT ECS_EVS.id AS ecs_id, EVS.id AS evs_id
    FROM (
        SELECT id, evs_id
        FROM (
    	SELECT id, transform(properties.ExtVolumesAttached, x -> x.id) AS evs_list
    	FROM resources
    	WHERE provider = 'ecs'
    		AND type = 'cloudservers'
    	) ECS
    	   CROSS JOIN UNNEST(evs_list) AS t (evs_id)
    ) ECS_EVS, (
    	SELECT id
    	FROM resources
    	WHERE provider = 'evs'
    		AND type = 'volumes'
    	) EVS
    WHERE ECS_EVS.evs_id = EVS.id
  • Example 5: List ECSs and the EIPs bound to each ECS.
    SELECT ECS.id AS ECS_id, publicIpAddress AS ip_address
    FROM (
        SELECT id, transform(properties.addresses, x -> x.addr) AS ip_list
        FROM resources
        WHERE provider = 'ecs'
            AND type = 'cloudservers'
    ) ECS, (
            SELECT name, properties.publicIpAddress
            FROM resources
            WHERE provider = 'vpc'
                AND type = 'publicips'
                AND properties.type = 'EIP'
                AND properties.status = 'ACTIVE'
        ) EIP
    WHERE CONTAINS (ECS.ip_list, EIP.name)
  • Example 6: List resources with a quantity greater than 100 in each region.
    WITH counts AS (
        SELECT region_id, provider, type, count(*) AS number
        FROM resources
        GROUP BY region_id, provider, type
    )
    SELECT *
    FROM counts
    WHERE number > 100

    For details about query statements, see ResourceQL Syntax.