如何获取openstacksdk返回的openstack.compute.v2.server.ServerDetail
数据?
下面是openstack.compute.v2.server.ServerDetail
实例数据:
[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),]
你看,我可以instance.property
用来获取值,下面server_generator
是 openstack 服务器的生成器:
for sd in server_generator:
print (sd.addresses)
但是,有两点我无法处理:
如何处理
OS-EXT-STS:power_state
key或os-extended-volumes:volumes_attached
key?我用
sd.hostId
的时候会报错,说没有hostId。