【发布时间】:2015-03-11 13:01:33
【问题描述】:
我有一个使用 OpenStack API 来创建实例、列出实例等的 Python 程序。身份验证运行良好;)。
我想获取特定主机的 CPU、内存和 HDD 信息。根据python-novaclient 文档,get(host) 方法是我所需要的。
一个 Python 示例:
from novaclient.client import Client
cl = Client(VERSION, USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
hosts_list = cl.hosts.list()
for h in hosts_list:
print h # this works and there are elements in hosts_list
cl.hosts.get(hosts_list[0]) # this does not work
我收到以下错误:
无法找到计算主机 。 (HTTP 404)(请求 ID:req-338f5bdd-b9ec-49cf-8f5c-59eb825de2c7)
EDIT:my-host.example.com 是正常的,我出于隐私原因更改了它。
我做对了吗?我发现文档很空。我正在寻找更详细的文档,但我觉得这是唯一的文档。
任何帮助将不胜感激。
更新:
nova host-list 命令(在控制器上)给了我这个输出(出于隐私原因编辑):
+-----------------------+-------------+----------+
| host_name | service | zone |
+-----------------------+-------------+----------+
| my-host-A.example.com | consoleauth | internal |
| my-host-A.example.com | scheduler | internal |
| my-host-A.example.com | conductor | internal |
| my-host-A.example.com | cert | internal |
| my-host-B.example.com | compute | nova |
| my-host-B.example.com | cert | internal |
| my-host-C.example.com | compute | nova |
| my-host-C.example.com | cert | internal |
| my-host-B.example.com | network | internal |
| my-host-C.example.com | network | internal |
+-----------------------+-------------+----------+
当我执行nova host-describe my-host-A.example.com 时,我得到:
ERROR: Compute host my-host-A.example.com could not be found. (HTTP 404) (Request-ID: req-5563c44b-b784-420a-bd73-68c546240076)
但是当我对 host-B 和 host-C 执行相同的命令时,我得到:
+---------------------------+------------+-----+-----------+---------+
| HOST | PROJECT | cpu | memory_mb | disk_gb |
+---------------------------+------------+-----+-----------+---------+
| my-host-{B,C}.example.com | (total) | 4 | 7987 | 206 |
| my-host-{B,C}.example.com | (used_now) | 0 | 512 | 0 |
| my-host-{B,C}.example.com | (used_max) | 0 | 0 | 0 |
+---------------------------+------------+-----+-----------+---------+
我的结论是只有具有 compute 服务的主机才能工作,这似乎很正常。所以我像这样改变了我的 Python 示例:
for h in hosts_list:
try:
hostname = str(h.host_name)
print "Try to get system info from: " + hostname
print cl.hosts.get(hostname)
except Exception as e:
logger.error(e)
确实,当我尝试从主机 A 获取信息时,我得到了相同的 404 错误。但我也收到剩余主机的错误:
Try to get system info from: my-host-{B,C}.example.com
2015-03-11 15:24:22 my-host-{B,C}.example.com urllib3.connectionpool[24249] DEBUG Setting read timeout to None
2015-03-11 15:24:22 my-host-{B,C}.example.com urllib3.connectionpool[24249] DEBUG "GET /v2/951c7a1decb44b4e8fcab59e49f2932f/os-hosts/my-host-{B,C}.example.com HTTP/1.1" 200 413
2015-03-11 15:24:22 my-host-{B,C}.example.com mylogger[24249] ERROR host_name
错误 host_name 不是很容易理解。
【问题讨论】:
-
检查 auth url,是否可以访问。
-
如果你谈论
OS_AUTH_URL,它工作得很好(用于身份验证)。然后我无法访问用于 Nova 服务的 URL,但我在日志中看到它使用了正确的 URL 和正确的端口 (8774)。而且我知道 URL 有效,因为我可以得到主机列表,如代码的 sn-p 所示。 -
为什么显示
my-host.example.com? -
我更改为不透露我正在使用的机器。我不知道我是否被允许公开提供这些信息。我可以判断给定的机器是正确的,
cl.hosts.list()给出的列表包含我所有的机器。 -
你能在控制台上运行
nova list吗?