2016-08-24 27 views
0

Openstackから詳細を取得するには、novaclientを使用しています。私は情報を取得することができますが、私はjson形式に変換したいです。私は "to_dic()"を使用していますが、 "server_details = server_id_name.to_dict()"に "Attribute"というエラーがスローされました。コードは以下のとおりであるjson形式のOpenstack出力

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 

答えて

1

は、それはあなたのpythonのコードのエラーです。 あなたはところで、あなたのpythonについての詳細を学ぶべき

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

あなたのコードを置き換えるために

server_details[server.id] = server.name 

を使用する必要があります。タプルをdictに変更したい場合は、python-tuple-to-dict

+0

ありがとうございます。私はPythonの新機能です! – tgcloud