0

我正在使用 novaclient 从 Openstack 获取详细信息。我能够检索信息,但是我想将其转换为 json 格式。我正在使用“to_dic()”,但它在“server_details = server_id_name.to_dict()”上抛出“属性”错误,不知道为什么。

AttributeError: "'tuple' object has no attribute 'to_dict'"

代码如下,

from novaclient import client as novaclient
import json

nova = novaclient.Client(version='2.0',username='xxxx',api_key='xxxx',project_id='xxxx',auth_url='http://192.168.12.3:5000/v2.0/',insecure='True')

server_details = dict()
server = nova.servers.list()
for server in nova.servers.list():
    print server.id, server.name
    server_id_name = server.id, server.name
    server_details = server_id_name.to_dict()
    for network in server.networks.items():
        print network
4

1 回答 1

1

这是您的python代码中的错误。你应该使用

server_details[server.id] = server.name

替换你的代码

server_id_name = server.id, server.name
server_details = server_id_name.to_dict()

顺便说一句,您应该了解有关 python 的更多信息。如果要将元组更改为字典,您应该看到python-tuple-to-dict

于 2016-09-08T02:26:56.460 回答