Ask Your Question
1

How to get instance_action from python-novaclient?

asked 2015-04-02 07:57:49 -0500

Lera gravatar image

I have find code to get from novaclient.v2 instance_action.list, but this do not work:

 from novaclient.v2 import client as nova_v2
 nova=nova_v2.Client("*****", "**********", "*********", "*****************")
 server = nova.servers.get('8322c5d8-b925-0091-bbff-dac361260b50')
 nova.instance_action.list('8322c5d8-b925-0091-bbff-dac361260b50')

I have next mistake:

nova.instance_action.list('8322c5d8-b925-0091-bbff-dac361260b50')
AttributeError: 'Client' object has no attribute 'instance_action'

How I can get this Instance_action?? Thank you!

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2015-04-02 09:59:57 -0500

Ranjit gravatar image

updated 2015-04-02 10:00:36 -0500

There is no API instance_action() for nova object.

you have to use REST API mentioned in the http://developer.openstack.org/api-re... .

API: /v2.1/servers/​{server_id}​/os-instance-actions

get the keystone token and call curl request.

curl request: 
curl -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token:TOKEN" http://openstackJuno:8774/v2/TENANT_ID/servers/SERVER_ID/os-instance-actions

ex:
curl -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token:139737f049f14acaaa6cee278a4c45f8" http://openstackJuno:8774/v2/1d4bc7c6d14b4e01b85e906e3dcce806/servers/0ee0b42e-cd2f-46c6-8038-f9c2e0359dcc/os-instance-actions  | python -m json.tool

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   611  100   611    0     0  10461      0 --:--:-- --:--:-- --:--:-- 10534
{
    "instanceActions": [
        {
            "action": "reboot",
            "instance_uuid": "0ee0b42e-cd2f-46c6-8038-f9c2e0359dcc",
            "message": null,
            "project_id": "1d4bc7c6d14b4e01b85e906e3dcce806",
            "request_id": "req-2eccb5d4-c2d8-461f-8bf6-a1fd7440a92f",
            "start_time": "2015-04-02T14:21:23.000000",
            "user_id": "fb611d3c2c554b258d8c2f9dd88fbed0"
        },
        {
            "action": "create",
            "instance_uuid": "0ee0b42e-cd2f-46c6-8038-f9c2e0359dcc",
            "message": null,
            "project_id": "1d4bc7c6d14b4e01b85e906e3dcce806",
            "request_id": "req-6d255b38-b70e-4096-9cf6-a60f0f53dab3",
            "start_time": "2015-04-01T07:21:36.000000",
            "user_id": "fb611d3c2c554b258d8c2f9dd88fbed0"
        }
    ]
}
edit flag offensive delete link more

Comments

But how can I get it using Python?

Lera gravatar imageLera ( 2015-04-07 02:27:57 -0500 )edit
0

answered 2016-04-12 15:23:51 -0500

zarkone gravatar image

updated 2016-07-15 00:33:17 -0500

To use it from Python, you need to plug extension (because it's from contrib, as I understood):

from novaclient import extension
from novaclient.v2.contrib import instance_action

ia_extensions = [
        extension.Extension(instance_action.__name__.split(".")[-1],
                            instance_action),
]
nova = client.Client(some,auth,params,
                     extensions=ia_extensions)
...

nova.instance_action.list(vm)

Also:

https://github.com/openstack/python-novaclient/blob/85eb9f7236fdd4a1fc611c20ea3b25f053180aa1/novaclient/tests/unit/v2/contrib/test_instance_actions.py (example usage in test for novaclient)

https://github.com/openstack/python-novaclient/blob/a7bffe8a71bb051b8c4df873fb8cb187c0f83643/novaclient/v2/contrib/instance_action.py (source code)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2015-04-02 07:57:49 -0500

Seen: 862 times

Last updated: Jul 15 '16