OpenStack Python Nova API 获取特定的限制值?

OpenStack Python Nova API Getting Specific Limit Values?

我一直在使用以下代码来获取限制:

compute_limits = novaClient.limits.get().absolute
for s in compute_limits:
    print s.name + " = " + str(s.value)

但是我只想要 limits.get() 中的特定值,即 totalRAMUsedmaxTotalRAMSize。互联网上似乎很少有关于使用 Python API 的内容(主要是关于 CLI)。有没有办法获取这些特定值以避免显示所有限制值?

您只能显示一个特定值:

compute_limits = novaClient.limits.get().absolute
for s in compute_limits:
    if s.name == 'totalRAMUsed':
        print s.name + " = " + str(s.value)
        break

compute_limitsgenerator,您不能通过限制名称只接收一个特定值。但是您可以将 compute_limits 转换为 dict。例如:

compute_limits = novaClient.limits.get().absolute
l = list(compute_limits)
limits = dict(map(lambda x: (x.name, x.value), l))
print limits['totalRAMUsed']