Revision history [back]

click to hide/show revision 1
initial version

OpenStack node_task in Python API

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'đ 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!

OpenStack node_task in Python API

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'đ 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! Thanks!

OpenStack node_task in Python API

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!

OpenStack node_task in Python API

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!