2

我正在编写 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>>

我该如何从上面提取接口数据?通过参考如何从 <Server: ubuntu12_6>> 的 <bound method Server.diagnostics 中提取值?,我在 i.interface_list() 中添加了括号。它给出了 AttributeError: 名称。那么,如何从上面得到完整的接口信息呢?

以下是 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
4

0 回答 0