Get Instance Status via Python API
Hello guys!
Please, is there a way to get a status of an instance via Python API but not using cmd in source code? I mean original Python API function. I was looking everywhere and I can not find it, but I am not sure wheter I am not searching good enough or it does not exist.
I created this:
def get_node_state(name):
# create a session
nova_client = Client_nova(session=get_session(), version=2)
# creates a list of servers
servers_list = nova_client.servers.list()
server_state = name
server_exists = False
# search the server in the list
for s in servers_list:
if s.name == server_state:
server_exists = True
break
if not server_exists:
print("server %s does not exist" % server_state)
status = None
else:
# runs a command to find status
status = os.popen("openstack server show -c status --format value %s" % name).read()
status = status.strip("\r\n")
return status
But I need to exchange the os.popen command.
Thank you!