我一直在尝试使用 OpenStack Unified SDK ( https://github.com/openstack/python-openstacksdk ) 创建一个通知内核 ID 和 Ramdisk ID 的 OpenStack 映像,但没有成功。我知道这是可能的,因为 OpenStack CLI 具有此参数,如本页 ( http://docs.openstack.org/cli-reference/glance.html#glance-image-create ) 所示,其中 CLI 具有“--kernel-id”和“--ramdisk-id”参数。我已经在终端中使用了这个参数并确认它们可以工作,但是我需要在 python 中使用它们。
我正在尝试使用 upload_method,如此处所述http://developer.openstack.org/sdks/python/openstacksdk/users/proxies/image.html#image-api-v2但我无法获取 attrs 参数正确的。文档只说它应该是一本字典。这是我正在使用的代码
...
atrib = {
'properties': {
'kernel_id': 'd84e1f2b-8d8c-4a4a-8858-77a8d5a93cb1',
'ramdisk_id': 'cfef18e0-006e-477a-a098-593d43435a1e'
}
}
with open(file) as fimage:
image = image_service.upload_image(
name=name,
data=fimage,
disk_format='qcow2',
container_format='bare',
**atrib)
....
这是我得到的错误:
File "builder.py", line 121, in main
**atrib
File "/usr/lib/python2.7/site-packages/openstack/image/v2/_proxy.py", line 51, in upload_image
**attrs)
File "/usr/lib/python2.7/site-packages/openstack/proxy2.py", line 193, in _create
return res.create(self.session)
File "/usr/lib/python2.7/site-packages/openstack/resource2.py", line 570, in create
json=request.body, headers=request.headers)
File "/usr/lib/python2.7/site-packages/keystoneauth1/session.py", line 675, in post
return self.request(url, 'POST', **kwargs)
File "/usr/lib/python2.7/site-packages/openstack/session.py", line 52, in map_exceptions_wrapper
http_status=e.http_status, cause=e)
openstack.exceptions.HttpException: HttpException: Bad Request, 400 Bad Request
Provided object does not match schema 'image': {u'kernel_id': u'd84e1f2b-8d8c-4a4a-8858-77a8d5a93cb1', u'ramdisk_id': u'cfef18e0-006e-477a-a098-593d43435a1e'} is not of type 'string' Failed validating 'type' in schema['additionalProperties']: {'type': 'string'} On instance[u'properties']: {u'kernel_id': u'd84e1f2b-8d8c-4a4a-8858-77a8d5a93cb1', u'ramdisk_id': u'cfef18e0-006e-477a-a098-593d43435a1e'}
已经尝试使用 update_image 方法,但没有成功,将内核 id 和 ramdisk id 作为字符串传递会创建实例,但它不会启动。有谁知道如何解决这个问题?