Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The usage.get(...) call returns a ComputeUsage object. You can see the available methods and attributes on that object like this:

>>> usage_report = nc.usage.get(tenant_id, now, later)
>>> dir(usage_report)

Which gets you:

['HUMAN_ID', 'NAME_ATTR', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_add_details', '_info', '_init_completion_cache', '_loaded', 'get', 'human_id', 'is_loaded', 'manager', 'server_usages', 'set_loaded', 'start', 'stop', 'tenant_id', 'to_dict', 'total_hours', 'total_local_gb_usage', 'total_memory_mb_usage', 'total_vcpus_usage']

Which means you can useful information doing something like:

>>> usage_report.total_hours
43.58250000000001

Or extract everything as a dictionary, which will looking something like this:

>>> pprint.pprint(usage_report.to_dict())
{u'server_usages': [{u'ended_at': u'2015-02-11T04:57:21.000000',
                     u'flavor': u'm1.small',
                     u'hours': 28.955833333333334,
                     u'instance_id': u'00d9e81b-5878-4fb4-b05e-b0cea16fe9eb',
                     u'local_gb': 20,
                     u'memory_mb': 2048,
                     u'name': u'test1',
                     u'started_at': u'2015-02-09T21:59:44.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 111457,
                     u'vcpus': 1},
                    {u'ended_at': u'2015-02-11T18:08:35.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 2.9794444444444443,
                     u'instance_id': u'fa18f51f-4e03-40d2-af8a-7e46159f18ec',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack-nd',
                     u'started_at': u'2015-02-11T15:09:49.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 10726,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-11T21:07:13.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 2.955277777777778,
                     u'instance_id': u'45c7e90b-3af2-4177-a0b0-459e14b63c0f',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack-nd',
                     u'started_at': u'2015-02-11T18:09:54.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 10639,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-12T03:33:57.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 5.8475,
                     u'instance_id': u'5adbc459-4533-455f-b851-1f6ae7cee9a0',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack',
                     u'started_at': u'2015-02-11T21:43:06.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 21051,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-12T03:33:57.000000',
                     u'flavor': u'm1.small',
                     u'hours': 1.4552777777777777,
                     u'instance_id': u'3cb010c8-45a3-458c-8181-455b2d969509',
                     u'local_gb': 20,
                     u'memory_mb': 2048,
                     u'name': u'coreos',
                     u'started_at': u'2015-02-12T02:06:38.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 5239,
                     u'vcpus': 1},
                    {u'ended_at': u'2015-02-12T04:31:18.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 0.9466666666666667,
                     u'instance_id': u'e87682c7-0549-4b1e-ba12-fbe958a340b3',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack',
                     u'started_at': u'2015-02-12T03:34:30.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 3408,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-12T04:31:21.000000',
                     u'flavor': u'm1.small',
                     u'hours': 0.4425,
                     u'instance_id': u'76ee0564-0718-4c8a-afd2-0c7766b8dfeb',
                     u'local_gb': 20,
                     u'memory_mb': 2048,
                     u'name': u'atomic',
                     u'started_at': u'2015-02-12T04:04:48.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 1593,
                     u'vcpus': 1}],
 u'start': u'2015-02-10T00:00:00.000000',
 u'stop': u'2015-02-12T10:17:19.948670',
 u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
 u'total_hours': 43.58250000000001,
 u'total_local_gb_usage': 1126.2277777777776,
 u'total_memory_mb_usage': 115325.72444444445,
 u'total_vcpus_usage': 56.31138888888889}

The usage.get(...) call returns a ComputeUsage object. You can see the available methods and attributes on that object like this:

>>> usage_report = nc.usage.get(tenant_id, now, later)
>>> dir(usage_report)

Which gets you:

['HUMAN_ID', 'NAME_ATTR', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_add_details', '_info', '_init_completion_cache', '_loaded', 'get', 'human_id', 'is_loaded', 'manager', 'server_usages', 'set_loaded', 'start', 'stop', 'tenant_id', 'to_dict', 'total_hours', 'total_local_gb_usage', 'total_memory_mb_usage', 'total_vcpus_usage']

Which means you can useful information doing something like:

>>> usage_report.total_hours
43.58250000000001

Or extract everything as a dictionary, which will looking something like this:

>>> pprint.pprint(usage_report.to_dict())
{u'server_usages': [{u'ended_at': u'2015-02-11T04:57:21.000000',
                     u'flavor': u'm1.small',
                     u'hours': 28.955833333333334,
                     u'instance_id': u'00d9e81b-5878-4fb4-b05e-b0cea16fe9eb',
                     u'local_gb': 20,
                     u'memory_mb': 2048,
                     u'name': u'test1',
                     u'started_at': u'2015-02-09T21:59:44.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 111457,
                     u'vcpus': 1},
                    {u'ended_at': u'2015-02-11T18:08:35.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 2.9794444444444443,
                     u'instance_id': u'fa18f51f-4e03-40d2-af8a-7e46159f18ec',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack-nd',
                     u'started_at': u'2015-02-11T15:09:49.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 10726,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-11T21:07:13.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 2.955277777777778,
                     u'instance_id': u'45c7e90b-3af2-4177-a0b0-459e14b63c0f',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack-nd',
                     u'started_at': u'2015-02-11T18:09:54.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 10639,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-12T03:33:57.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 5.8475,
                     u'instance_id': u'5adbc459-4533-455f-b851-1f6ae7cee9a0',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack',
                     u'started_at': u'2015-02-11T21:43:06.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 21051,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-12T03:33:57.000000',
                     u'flavor': u'm1.small',
                     u'hours': 1.4552777777777777,
                     u'instance_id': u'3cb010c8-45a3-458c-8181-455b2d969509',
                     u'local_gb': 20,
                     u'memory_mb': 2048,
                     u'name': u'coreos',
                     u'started_at': u'2015-02-12T02:06:38.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 5239,
                     u'vcpus': 1},
                    {u'ended_at': u'2015-02-12T04:31:18.000000',
                     u'flavor': u'm1.medium',
                     u'hours': 0.9466666666666667,
                     u'instance_id': u'e87682c7-0549-4b1e-ba12-fbe958a340b3',
                     u'local_gb': 40,
                     u'memory_mb': 4096,
                     u'name': u'devstack',
                     u'started_at': u'2015-02-12T03:34:30.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 3408,
                     u'vcpus': 2},
                    {u'ended_at': u'2015-02-12T04:31:21.000000',
                     u'flavor': u'm1.small',
                     u'hours': 0.4425,
                     u'instance_id': u'76ee0564-0718-4c8a-afd2-0c7766b8dfeb',
                     u'local_gb': 20,
                     u'memory_mb': 2048,
                     u'name': u'atomic',
                     u'started_at': u'2015-02-12T04:04:48.000000',
                     u'state': u'terminated',
                     u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
                     u'uptime': 1593,
                     u'vcpus': 1}],
 u'start': u'2015-02-10T00:00:00.000000',
 u'stop': u'2015-02-12T10:17:19.948670',
 u'tenant_id': u'95d9bbd9b446438a89a353d8adb60704',
 u'total_hours': 43.58250000000001,
 u'total_local_gb_usage': 1126.2277777777776,
 u'total_memory_mb_usage': 115325.72444444445,
 u'total_vcpus_usage': 56.31138888888889}

Update

This works for me just fine with devstack/Icehouse. I booted Ubuntu 14.04 (Trusty), then ran:

$ git clone https://git.openstack.org/openstack-dev/devstack
$ cd devstack/
$ git checkout stable/icehouse
$ curl -o local.conf http://chunk.io/f/11e3b2ff83244ed19fb350640b88808f
$ HOST_IP=10.0.0.239 ./stack.sh

And once the install was finished, I grabbed some credentails:

$ . openrc admin

And booted a Cirros image so there would be some statistics:

$ nova boot ...
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import novaclient.v1_1.client as novaclient
>>> import datetime
>>> import os
>>> e = os.environ
>>> nc = novaclient.Client(e['OS_USERNAME'], e['OS_PASSWORD'], '', e['OS_AUTH_URL'], tenant_id='68a7289a39e2497493b00ae1b11d34b4')
>>> earlier = datetime.datetime.strptime('2015-02-11', '%Y-%m-%d')
>>> now = datetime.datetime.now()
>>> u = nc.usage.get('68a7289a39e2497493b00ae1b11d34b4', earlier, now)
>>> u.total_hours
0.12116079722222223
>>> u.total_memory_mb_usage
62.03432817777778
>>>

I had to lookup the value for tenant_id with keystone token-get; without specifying a tenant_id I was not able to obtain a valid token.