我们在我们的OpenStack中有名为<OS> <version>:<build no>
的图像(例如,CentOS 7.2.0:160708.0
)。与the Python novaclient,我可以使用client.glance.find_image
与三鹰之前的版本。为什么冒号打破novaclient的glance.find_image?
$ cat test.py
#! /usr/bin/env python3
import os
import sys
from novaclient import client
nova = client.Client("2",
os.environ["OS_USERNAME"],
os.environ["OS_PASSWORD"],
os.environ["OS_TENANT_ID"],
os.environ["OS_AUTH_URL"],
cacert=os.environ["OS_CACERT"])
print(nova.glance.find_image(sys.argv[1]))
随着自由:
$ python3 test.py "CentOS 7.2.0:170210.0"
<Image: CentOS 7.2.0:170210.0>
随着三鹰:
$ python3 test.py "CentOS 7.2.0:170210.0"
Traceback (most recent call last):
File "test.py", line 11, in <module>
print(nova.glance.find_image(sys.argv[1]))
File "/usr/local/lib/python3.6/site-packages/novaclient/v2/images.py", line 53, in find_image
"images")
File "/usr/local/lib/python3.6/site-packages/novaclient/base.py", line 254, in _list
resp, body = self.api.client.get(url)
File "/usr/local/lib/python3.6/site-packages/keystoneauth1/adapter.py", line 223, in get
return self.request(url, 'GET', **kwargs)
File "/usr/local/lib/python3.6/site-packages/novaclient/client.py", line 80, in request
raise exceptions.from_response(resp, body, url, method)
novaclient.exceptions.BadRequest: Unable to filter by unknown operator 'CentOS 7.2.0'.<br /><br />
(HTTP 400)
注意,当这个名字的图像不存在的错误是不同的:
$ python3 test.py "CentOS 7.2.0"
Traceback (most recent call last):
File "test.py", line 11, in <module>
print(nova.glance.find_image(sys.argv[1]))
File "/usr/local/lib/python3.6/site-packages/novaclient/v2/images.py", line 58, in find_image
raise exceptions.NotFound(404, msg)
novaclient.exceptions.NotFound: No Image matching CentOS 7.2.0. (HTTP 404)
这就好像find_image
一样期望的形式operator: value
的字符串,但the documentation has only this to say about find_image
:
find_image
(name_or_id)
通过名称或ID(用户提供的输入)找到的图像。
如何在使用三鹰时找到名称中包含冒号的图像?
$ nova --version
8.0.0
过滤列表可能是低效的,但它比'find_image'更灵活,它需要一个精确的图像名称。并且'in:“...”'方式在旧版本中不起作用,所以它不是很有用。感谢您的信息! – muru