我正在编写python脚本以从OpenStack安装程序获取信息。要获取与VM接口相关的信息,我们需要使用“interface-list”。我的代码是
#!/usr/bin/env python
import novaclient.v1_1.client as nvclient
from credentials import get_nova_creds
creds = get_nova_creds()
#print creds
nova = nvclient.Client(**creds)
instances = nova.servers.list()
val_list = []
for i in instances:
stat = i.interface_list
print stat
这使输出为
<bound method Server.interface_list of <Server: ubuntu12_6>>
<bound method Server.interface_list of <Server: ubuntu12_5>>
<bound method Server.interface_list of <Server: ubuntu12_4>>
<bound method Server.interface_list of <Server: ubuntu12_3>>
<bound method Server.interface_list of <Server: ubuntu12_1>>
如何从上面提取界面数据? 通过引用how to extract values from <bound method Server.diagnostics of <Server: ubuntu12_6>>?,我向i.interface_list()添加了括号。它给出了AttributeError:name。 那么,如何从上面获取界面的完整信息呢?
以下是stat = i.interface_list()
的完整追溯[Traceback (most recent call last):
File "mac.py", line 12, in <module>
print stat
File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/servers.py", line 36, in __repr__
return "<Server: %s>" % self.name
File "/usr/lib/python2.7/dist-packages/novaclient/base.py", line 458, in __getattr__
raise AttributeError(k)
AttributeError: name