I have a working Python program using the OpenStack API to create instances, list the instances, etc. The authentication is working well ;).
I would like to get the CPU, memory and HDD information of a specific host. According to the python-novaclient documentation, the method get(host)
is what I need.
A Python example:
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
I get the following error:
Compute host < Host: my-host.example.com > could not be found. (HTTP 404) (Request-ID: req-338f5bdd-b9ec-49cf-8f5c-59eb825de2c7)
EDIT: my-host.example.com is normal, I changed it for privacy reasons.
Am I doing things right? I find the documentation pretty empty. I'm looking for a more detailed documentation but I feel like this is the only one.
Any help will be greatly appreciated.
UPDATE:
The nova host-list
command (on the controller) gives me this output (edited for privacy reason):
+-----------------------+-------------+----------+
| 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 |
+-----------------------+-------------+----------+
And when I execute nova host-describe my-host-A.example.com
, I get:
ERROR: Compute host my-host-A.example.com could not be found. (HTTP 404) (Request-ID: req-5563c44b-b784-420a-bd73-68c546240076)
But when I execute the same command for host-B and host-C, I get:
+---------------------------+------------+-----+-----------+---------+
| 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 |
+---------------------------+------------+-----+-----------+---------+
I conclude that only the hosts with a compute service should work, which seems normal. So I changed my Python example like this:
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)
Indeed, I get the same 404 error when I try to get info from host-A. But I also get an error for the remaining hosts:
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
The error host_name is not really understandable.
OS_AUTH_URL
, it works well (used for the authentication). Then I don't have access to the URL used for the Nova service but I saw on the logs that it is using the correct URL and the correct port (8774). And I know the URL works because I can get the list of host as shown in the snippet of code.my-host.example.com
?cl.hosts.list()
contains all of my machines.nova list
on console ?