Updated on 2024-08-09 GMT+08:00

Querying BMSs (Native OpenStack API)

Function

This API is used to query BMSs.

Constraints

  • The query result returned by this interface includes both ECSs and BMSs. You need to filter out the BMSs using the flavor used to create the BMSs or the tags added to the BMSs during BMS creation.
  • If the image is used as the search criteria, other search criteria and pagination criteria are not supported. If both the image and other search criteria are used, the BMSs are filtered out by image. If the image is not used as the search criteria, this interface has no restrictions.

URI

GET /v2.1/{project_id}/servers{?changes-since={changes-since}&image={image}&flavor={flavor}&name={name}&status={status}&limit={limit}&marker={marker}&tags={tags}&not-tags={not-tags}&reservation_id={reservation_id}&sort_key={sort_key}&sort_dir={sort_dir}}

Table 1 lists the parameters.

Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Specifies the project ID.

For details about how to obtain the project ID, see Obtaining a Project ID.

Request Parameters

Parameter

Mandatory

Type

Description

changes-since

No

String

Specifies the timestamp of the last BMS status update. The parameter is in ISO 8601 time format, for example, 2013-06-09T06:42:18Z.

image

No

String

Specifies the image ID.

You can obtain the image ID from the IMS console or by calling the Querying Images API.

NOTE:

If the image is used as the search criteria, other search criteria and pagination criteria are not supported. If both the image and other search criteria are used, the BMS details are filtered out by image. If the image is not used as the search criteria, this interface has no restrictions.

flavor

No

String

Specifies the flavor ID.

You can obtain the flavor ID from the BMS console or using the Querying BMS Flavors (Native OpenStack API) API.

name

No

String

Specifies the BMS name. This parameter supports fuzzy matching.

For example, the regular expression ?name=bob will return both bob and bobb. To obtain only bob, you can use a regular expression matching the basic database syntax, such as MySQL or PostgreSQL (official website: https://www.postgresql.org/docs/9.2/static/functions-matching.html).

status

No

String

Specifies the BMS status.

Value range:

  • ACTIVE: Running, Stopping, Deleting
  • BUILD: Creating
  • ERROR: Faulty
  • HARD_REBOOT: Forcibly Restarting
  • REBOOT: Restarting
  • SHUTOFF: Stopped, Starting, Deleting, Rebuilding, Reinstalling OS, OS Reinstallation Failed, Frozen

limit

No

Integer

Specifies the number of BMSs displayed on each page.

marker

No

String

Specifies the BMS ID to which the marker corresponds. The query will start from the next ID.

tags

No

String

Queries the BMSs with specified tags.

Added in micro version 2.26.

not-tags

No

String

Queries the BMSs with tags not containing the specified value. The value is a list of tag keys.

NOTE:

If the tags added before the function upgrade are in the format of "Key.Value", query tags using "Key".

For example, an existing tag is a.b. After the tag function upgrade, query the tag using "not-tags=a".

Added in micro version 2.26.

reservation_id

No

String

Specifies the reserved ID, which can be used to query BMSs created in a batch.

Added in micro version 2.26.

sort_key

No

String

Specifies the BMS sorting attribute, which can be the BMS UUID (uuid), BMS status (vm_state), BMS name (display_name), BMS task status (task_state), power status (power_state), creation time (created_at), last time when the BMS is updated (updated_at), and AZ (availability_zone). You can specify multiple sort_key and sort_dir pairs.

The default sorting is the reverse order by created_at.

sort_dir

No

String

Specifies the sorting direction.

  • asc: The query results are displayed in ascending order.
  • desc (default value): The query results are displayed in descending order.

Example Request

  • Querying BMSs
    1
    GET https://{ECS Endpoint}/v2.1/bbf1946d374b44a0a2a95533562ba954/servers
    
  • Querying BMSs with the __type_baremetal tag
    1
    GET https://{ECS Endpoint}/v2.1/bbf1946d374b44a0a2a95533562ba954/servers?tags=__type_baremetal
    
  • Querying BMSs with the __type_baremetal tag and with bms-test01 contained in the name
    1
    GET https://{ECS Endpoint}/v2.1/bbf1946d374b44a0a2a95533562ba954/servers?tags=__type_baremetal&name=bms-test01
    

Response Parameters

Parameter

Type

Description

servers

Array of objects

Specifies the BMS list. For details, see Table 2.

Table 2 servers field data structure description

Parameter

Type

Description

name

String

Specifies the BMS name.

id

String

Specifies the unique ID of the BMS.

links

Array of objects

Specifies shortcut links of the BMS. For details, see Table 3.

Table 3 links field data structure description

Parameter

Type

Description

rel

String

Specifies the shortcut link marker name. The value can be:

  • self: resource link that contains the version number. It is used when immediate tracing is required.
  • bookmark: resource link that can be stored for a long time.

href

String

Specifies the corresponding shortcut link.

Example Response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{
    "servers": [
        {
            "name": "bms",
            "links": [
                {
                    "rel": "self",
                    "href": "https://openstack.example.com/v2.1/c685484a8cc2416b97260938705deb65/servers/820abbd0-2d8b-4bc5-ae46-69cacfd4fbaa"
                },
                {
                    "rel": "bookmark",
                    "href": "https://openstack.example.com/c685484a8cc2416b97260938705deb65/servers/820abbd0-2d8e-4bc5-ae46-69cacfd4fbaa"
                }
            ],
            "id": "820abbd0-2d8e-4bc5-ae46-69cacfd4fbaa"
        }
    ]
}

Returned Values

Normal values

Returned Values

Description

200

The request has been successfully processed.

For details about other returned values, see Status Codes.

Error Codes

See Error Codes.