Ask Your Question
0

OpenStack task_state in Python API

asked 2017-11-06 04:07:32 -0500

FilipGontko gravatar image

updated 2017-11-06 04:10:42 -0500

Hello guys!

I have a problem that I need to get task_state of a VM via Python but I don't know how. Here's the thing:

{
"server": {
    "OS-DCF:diskConfig": "AUTO",
    "OS-EXT-AZ:availability_zone": "nova",
    "OS-EXT-SRV-ATTR:host": "compute",
    "OS-EXT-SRV-ATTR:hostname": "new-server-test",
    "OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
    "OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
    "OS-EXT-SRV-ATTR:kernel_id": "",
    "OS-EXT-SRV-ATTR:launch_index": 0,
    "OS-EXT-SRV-ATTR:ramdisk_id": "",
    "OS-EXT-SRV-ATTR:reservation_id": "r-ov3q80zj",
    "OS-EXT-SRV-ATTR:root_device_name": "/dev/sda",
    "OS-EXT-SRV-ATTR:user_data": "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==",
    "OS-EXT-STS:power_state": 1,
    "OS-EXT-STS:task_state": null,
    "OS-EXT-STS:vm_state": "active",
    "OS-SRV-USG:launched_at": "2017-02-14T19:23:59.895661",
    "OS-SRV-USG:terminated_at": null,
    "accessIPv4": "1.2.3.4",
    "accessIPv6": "80fe::",
    "addresses": {
        "private": [
            {
                "OS-EXT-IPS-MAC:mac_addr": "aa:bb:cc:dd:ee:ff",
                "OS-EXT-IPS:type": "fixed",
                "addr": "192.168.0.3",
                "version": 4
            }
        ]
    },
    "config_drive": "",
    "created": "2017-02-14T19:23:58Z",
    "description": null,
    }
 }

If I want to get e.g. created I can use this:

return server.created

but when I want to use task_state I cannot use this:

return server.OS-EXT-STS:task_state

Can you please give me some ideas how to solve this ?

I already tried to iterate through the keys but it says that Server (object) is not iterable, neither has keys() nor values(). I ran out of ideas :D Here's my code:

def server_exists(name, smn=False):
    # create a session
    nova_client = Client_nova(session=get_session(), version=2)
    # creates a list of servers
    servers_list = nova_client.servers.list()
    # search the server in the list
    for s in servers_list:
        if s.name == name:
            return s
    return False


def get_node_task(node_cloud_id):
    server = server_exists(node_cloud_id)
    if not server:
        raise RuntimeError("Server does not exist")
    else:
        #TODO

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-14 05:18:47 -0500

FilipGontko gravatar image

I solved the problem :)

def get_node_task(node_cloud_id):
server = server_exists(node_cloud_id)
if not server:
    raise RuntimeError("Server does not exist")
else:
    for attr, value in vars(server).items():
        if attr == 'OS-EXT-STS:task_state':
            return value
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: 2017-11-06 04:07:32 -0500

Seen: 189 times

Last updated: Dec 14 '17