【问题标题】:Openstack Python SDK - Glance does not return image MD5Openstack Python SDK - Glance 不返回图像 MD5
【发布时间】:2016-09-01 22:26:30
【问题描述】:

我正在尝试仅使用 Openstack Python SDK 从 Glance 下载 OpenStack 映像,但我只收到此错误:

Traceback (most recent call last):
  File "/home/openstack/discovery/discovery.py", line 222, in <module>
    main(sys.argv[1:])
  File "/home/openstack/discovery/discovery.py", line 117, in main
    image_service.download_image(image)
  File "/usr/local/lib/python2.7/dist-packages/openstack/image/v2/_proxy.py", line 72, in download_image
    return image.download(self.session)
  File "/usr/local/lib/python2.7/dist-packages/openstack/image/v2/image.py", line 166, in download
    checksum = resp.headers["Content-MD5"]
  File "/usr/local/lib/python2.7/dist-packages/requests/structures.py", line 54, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'content-md5'

奇怪的是,如果我使用 IDE(带有远程调试的 PyCharm)或作为脚本(python script.py -i ...)运行代码,我会收到错误,但如果我使用python解释器(ipython/python)不会发生错误!不知道为什么。

这是我正在使用的代码:

...
image_name = node.name + "_" + time.strftime("%Y-%m-%d_%H-%M-%S")
print "Getting data from", node.name
compute_service.create_server_image(node, image_name)
image = image_service.find_image(image_name)
image_service.wait_for_status(image, 'active')
fileName = "%s.img" % image.name

with open(str(fileName), 'w+') as imgFile:
    imgFile.write(image.download(conn.image.session))
...

这段代码最终调用了这个文件/usr/local/lib/python2.7/dist-packages/openstack/image/v2/image.py中的API,用这个方法:

def download(self, session):
    """Download the data contained in an image"""
    # TODO(briancurtin): This method should probably offload the get
    # operation into another thread or something of that nature.
    url = utils.urljoin(self.base_path, self.id, 'file')
    resp = session.get(url, endpoint_filter=self.service)

    checksum = resp.headers["Content-MD5"]
    digest = hashlib.md5(resp.content).hexdigest()
    if digest != checksum:
        raise exceptions.InvalidResponse("checksum mismatch")

    return resp.content

resp.headers 变量没有键“Content-MD5”。这是我为它找到的价值:

{'Date': 'Thu, 01 Sep 2016 20:17:01 GMT', 'Transfer-Encoding': 'chunked', 
 'Connection': 'keep-alive', 'Content-Type': 'application/octet-stream', 
 'X-Openstack-Request-Id': 'req-9eb16897-1398-4ab2-9cd4-45706e92819c'}

但根据 REST API 文档,响应应返回密钥 Content-MD5: http://developer.openstack.org/api-ref/image/v2/?expanded=download-binary-image-data-detail

如果我只是评论 MD5,请检查下载是否正常,但这是在 SDK 中,所以我不能/不应该更改它。有人对如何使用 OpenStack Python SDK 实现这一点有任何建议吗?这是 SDK 错误吗?

【问题讨论】:

    标签: python openstack openstack-glance openstack-api


    【解决方案1】:

    原来这确实是一个错误 SDK/Glance。可以在此处找到有关它的更多详细信息: https://bugs.launchpad.net/python-openstacksdk/+bug/1619675

    并且可以在此处看到已实施的修复: https://github.com/openstack/python-openstacksdk/commit/759651f4a9eae2ba546f46613550a4cb10ddd964

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 2023-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多