Merge lp:~rackspace-titan/nova/glance_xen_plugin_preserve_headers into lp:~hudson-openstack/nova/trunk

Proposed by Dan Prince
Status: Merged
Approved by: Brian Waldon
Approved revision: 1365
Merged at revision: 1374
Proposed branch: lp:~rackspace-titan/nova/glance_xen_plugin_preserve_headers
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 43 lines (+17/-2)
1 file modified
plugins/xenserver/xenapi/etc/xapi.d/plugins/glance (+17/-2)
To merge this branch: bzr merge lp:~rackspace-titan/nova/glance_xen_plugin_preserve_headers
Reviewer Review Type Date Requested Status
Brian Waldon (community) Approve
Rick Harris (community) Approve
Review via email: mp+70446@code.launchpad.net

Description of the change

Updates to the XenServer glance plugin so that it obtains the set of
existing headers and sends them along with the request to PUT a
snapshotted image into glance.

To post a comment you must log in.
Revision history for this message
Rick Harris (rconradharris) wrote :

Looks good, thanks for the fix Dan.

Aside:

It's really too bad we have to do this. We're planning to decouple the API from the Registry so that the API will no longer have to handle metadata.

Perhaps in that effort we can have the Registry use the "PATCH" HTTP method so we don't have to pass back the entire metadata structure; instead, we'd only pass the metadata items that were changing.

review: Approve
Revision history for this message
Dan Prince (dan-prince) wrote :

Agreed. We've also talked about a sub-resource to manage the registry metadata. In any case the metadata/properties are currently a bit overloaded in the existing implementation. Using headers to maintain the metadata is nice in that its lightweight but it leaves some things to be desired with regard to maintenance of the metadata/properties of images.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Awesome.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/xenserver/xenapi/etc/xapi.d/plugins/glance'
--- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance 2011-07-27 18:13:04 +0000
+++ plugins/xenserver/xenapi/etc/xapi.d/plugins/glance 2011-08-04 14:45:51 +0000
@@ -248,6 +248,19 @@
248 using chunked-transfer-encoded HTTP.248 using chunked-transfer-encoded HTTP.
249 """249 """
250 conn = httplib.HTTPConnection(glance_host, glance_port)250 conn = httplib.HTTPConnection(glance_host, glance_port)
251
252 # NOTE(dprince): We need to resend any existing Glance meta/property
253 # headers so they are preserved in Glance. We obtain them here with a
254 # HEAD request.
255 conn.request('HEAD', '/v1/images/%s' % image_id)
256 resp = conn.getresponse()
257 if resp.status != httplib.OK:
258 raise Exception("Unexpected response from Glance %i" % resp.status)
259 headers = {}
260 for header, value in resp.getheaders():
261 if header.lower().startswith("x-image-meta-property-"):
262 headers[header.lower()] = value
263
251 # NOTE(sirp): httplib under python2.4 won't accept a file-like object264 # NOTE(sirp): httplib under python2.4 won't accept a file-like object
252 # to request265 # to request
253 conn.putrequest('PUT', '/v1/images/%s' % image_id)266 conn.putrequest('PUT', '/v1/images/%s' % image_id)
@@ -260,7 +273,7 @@
260 # 2. We're currently uploading a vanilla tarball. In order to be OVF/OVA273 # 2. We're currently uploading a vanilla tarball. In order to be OVF/OVA
261 # compliant, we'll need to embed a minimal OVF manifest as the first274 # compliant, we'll need to embed a minimal OVF manifest as the first
262 # file.275 # file.
263 headers = {276 ovf_headers = {
264 'content-type': 'application/octet-stream',277 'content-type': 'application/octet-stream',
265 'transfer-encoding': 'chunked',278 'transfer-encoding': 'chunked',
266 'x-image-meta-is-public': 'True',279 'x-image-meta-is-public': 'True',
@@ -271,7 +284,9 @@
271284
272 # If we have an auth_token, set an x-auth-token header285 # If we have an auth_token, set an x-auth-token header
273 if auth_token:286 if auth_token:
274 headers['x-auth-token'] = auth_token287 ovf_headers['x-auth-token'] = auth_token
288
289 headers.update(ovf_headers)
275290
276 for header, value in headers.iteritems():291 for header, value in headers.iteritems():
277 conn.putheader(header, value)292 conn.putheader(header, value)