OpenStack PythonNova API正在获取特定的限制值?

2024-10-03 04:30:30 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

但是我只需要limits.get()中的特定值,即totalRAMUsed和{}。互联网上似乎很少有关于使用pythonapi(主要是关于CLI)的。有没有一种方法可以避免显示所有的值?在


Tags: 代码nameinpythonapiforgetvalue互联网
1条回答
网友
1楼 · 发布于 2024-10-03 04:30:30

只能显示一个特定值:

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。例如:

^{pr2}$

相关问题 更多 >