如何使用REST API列出按元数据过滤的Rackspace服务器?

时间:2016-06-10 11:37:12

标签: rest rackspace-cloud rackspace

我可以看到可以向Rackspace虚拟机实例添加元数据。

我想获得一个正在运行的实例列表,按特定的元标记值进行过滤。

但是我无法在文档中看到如何这样做。

有可能吗?

1 个答案:

答案 0 :(得分:0)

你应该能够使用openstack客户端这样做......但这取决于你感兴趣的metatag。

您可以获取所有服务器的列表:

openstack server list

会吐出像

这样的东西
+--------------------------------------+------------------+--------+-----------------------------------------------------------------------------------------------------------+
| ID                                   | Name             | Status | Networks                                                                                                  |
+--------------------------------------+------------------+--------+-----------------------------------------------------------------------------------------------------------+
| 97606ae9-7f18-4a3c-903a-1583d446119b | trysmallwin      | ERROR  |                                                                                                           |
| cb78b8d5-2f03-4a3f-ab26-f389acbd0b76 | Win-try again    | ERROR  | public=2607:f298:5:101d:f816:3eff:fe9e:5cd4, 208.113.133.90, 2607:f298:5:101d:f816:3eff:fe36:da45,        |
|                                      |                  |        | 208.113.133.93, 2607:f298:5:101d:f816:3eff:fe40:57d5, 208.113.133.95                                      |
| 040751d1-c4c5-47aa-8dec-1d69a468be1c | hnxhdkwskrvwvdwr | ACTIVE | public=2607:f298:5:101d:f816:3eff:fe60:324, 208.113.130.52                                                |
+--------------------------------------+------------------+--------+-----------------------------------------------------------------------------------------------------------+

记下服务器的ID并深入调查:

openstack server show 040751d1-c4c5-47aa-8dec-1d69a468be1c
+--------------------------------------+------------------------------------------------------------+
| Field                                | Value                                                      |
+--------------------------------------+------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                     |
| OS-EXT-AZ:availability_zone          | iad-2                                                      |
| OS-EXT-STS:power_state               | Running                                                    |
| OS-EXT-STS:task_state                | None                                                       |
| OS-EXT-STS:vm_state                  | active                                                     |
| OS-SRV-USG:launched_at               | 2016-07-26T17:32:01.000000                                 |
| OS-SRV-USG:terminated_at             | None                                                       |
| accessIPv4                           |                                                            |
| accessIPv6                           |                                                            |
| addresses                            | public=2607:f298:5:101d:f816:3eff:fe60:324, 208.113.130.52 |
| config_drive                         | True                                                       |
| created                              | 2016-07-26T17:31:51Z                                       |
| flavor                               | gp1.semisonic (50)                                         |
| hostId                               | e1efd75d1e8f6a7f5bb228a35db13647281996087d39c65af8ce83d9   |
| id                                   | 040751d1-c4c5-47aa-8dec-1d69a468be1c                       |
| image                                | Ubuntu-14.04 (03f89ff2-d66e-49f5-ae61-656a006bbbe9)        |
| key_name                             | stef                                                       |
| name                                 | hnxhdkwskrvwvdwr                                           |
| os-extended-volumes:volumes_attached | []                                                         |
| progress                             | 0                                                          |
| project_id                           | d2fb6996496044158cf977c2129c8660                           |
| properties                           |                                                            |
| security_groups                      | [{u'name': u'default'}]                                    |
| status                               | ACTIVE                                                     |
| updated                              | 2016-07-26T17:32:01Z                                       |
| user_id                              | 5b2ca246f39a425f9a833460bf322603                           |
+--------------------------------------+------------------------------------------------------------+

openstack --f json将以json格式输出相同的内容,以便您可以更容易地以编程方式进行操作。

HTH