Search code examples
pythonopenstack-nova

How can I get VM instance running time in openstack via python API?


I need a small billing report for the usage of the VMs inside openstack after it is stopped, so far I already find the way to get flavor information (vCPU, disk, memory) from instance name.

And I want to know the VM's startup time to calculate now.

Are there any good ways to fetch it from openstack python API ?

It will be nice if you can paste the code as well.


Solution

  • (I got the answer from china-openstack community, and shared here)

    In the novaclient usage module, all the instance (active or terminated) can be fetched by list API, the detail information is fetched via get API, it is not clear what information are exposed via this python document.

    Fortunately the openstack api : os-simple-tenant-usage tells the data structure, the uptime is what I want.

     "tenant_usage": {
        "server_usages": [
            {
                ... (skipped)
                "uptime": 3600,
                "vcpus": 1
            }
        ],
    

    openstack dashboard (at least Folsom version) use this API as well.