Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenStack Python Nova API是否获得特定的限制值?_Python_Openstack_Openstack Nova - Fatal编程技术网

OpenStack Python Nova API是否获得特定的限制值?

OpenStack Python Nova API是否获得特定的限制值?,python,openstack,openstack-nova,Python,Openstack,Openstack Nova,我一直在使用以下代码来获取限制: compute_limits = novaClient.limits.get().absolute for s in compute_limits: print s.name + " = " + str(s.value) 但是,我只需要来自limits.get()的特定值,即totalRAMUsed和maxTotalRAMSize。互联网上似乎很少有关于使用Python API的内容(主要是关于CLI)。有没有办法获取这些特定值以避免显示所有限值?您只

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

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

但是,我只需要来自
limits.get()
的特定值,即
totalRAMUsed
maxTotalRAMSize
。互联网上似乎很少有关于使用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\u limits
generator
,您不能通过限制名称只接收一个特定值。但您可以将
compute\u 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']

这就是为什么我不能只得到一个值而没有其他值的原因。把它转换成字典是个好主意!