How to get the openstacksdk returned openstack.compute.v2.server.ServerDetail
data?
The bellow is the openstack.compute.v2.server.ServerDetail
instance data:
[openstack.compute.v2.server.ServerDetail(
OS-EXT-AZ:availability_zone=,
key_name=None,
hostId=,
os-extended-volumes:volumes_attached=[],
OS-SRV-USG:launched_at=None,
OS-EXT-STS:vm_state=error,
flavor={'id': '5c5dca53-9f96-4851-afd4-60de75faf896', 'links': [{'href': 'http://controller:8774/233cf23186bf4c52afc464ee008cdf7f/flavors/5c5dca53-9f96-4851-afd4-60de75faf896', 'rel': 'bookmark'}]}, updated=2017-11-27T10:29:50Z,
accessIPv4=,
image={'id': '60f4005e-5daf-4aef-a018-4c6b2ff06b40', 'links': [{'href': 'http://controller:8774/233cf23186bf4c52afc464ee008cdf7f/images/60f4005e-5daf-4aef-a018-4c6b2ff06b40', 'rel': 'bookmark'}]},
created=2017-11-27T10:29:49Z,
metadata={},
links=[{'href': 'http://controller:8774/v2.1/233cf23186bf4c52afc464ee008cdf7f/servers/3db46b7b-a641-49ce-97ef-f17c9a11f58a', 'rel': 'self'}, {'href': 'http://controller:8774/233cf23186bf4c52afc464ee008cdf7f/servers/3db46b7b-a641-49ce-97ef-f17c9a11f58a', 'rel': 'bookmark'}],
OS-DCF:diskConfig=MANUAL,
id=3db46b7b-a641-49ce-97ef-f17c9a11f58a, user_id=41bb48ee30e449d5868f7af9e6251156,
OS-SRV-USG:terminated_at=None,
name=123456,
config_drive=,
accessIPv6=,
OS-EXT-STS:power_state=0,
addresses={},
OS-EXT-STS:task_state=None,
status=ERROR,
tenant_id=233cf23186bf4c52afc464ee008cdf7f),]
You see, I can use instance.property
to get the value, bellow server_generator
is the generator of openstack servers:
for sd in server_generator:
print (sd.addresses)
But, however there are two point I can not deal with:
how to deal with
OS-EXT-STS:power_state
key oros-extended-volumes:volumes_attached
key?when I use
sd.hostId
there will report error, says there is no hostId.
you must first use
to_dict
function to get dict objcet.then you can get what you want.