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
1=== modified file 'plugins/xenserver/xenapi/etc/xapi.d/plugins/glance'
2--- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance 2011-07-27 18:13:04 +0000
3+++ plugins/xenserver/xenapi/etc/xapi.d/plugins/glance 2011-08-04 14:45:51 +0000
4@@ -248,6 +248,19 @@
5 using chunked-transfer-encoded HTTP.
6 """
7 conn = httplib.HTTPConnection(glance_host, glance_port)
8+
9+ # NOTE(dprince): We need to resend any existing Glance meta/property
10+ # headers so they are preserved in Glance. We obtain them here with a
11+ # HEAD request.
12+ conn.request('HEAD', '/v1/images/%s' % image_id)
13+ resp = conn.getresponse()
14+ if resp.status != httplib.OK:
15+ raise Exception("Unexpected response from Glance %i" % resp.status)
16+ headers = {}
17+ for header, value in resp.getheaders():
18+ if header.lower().startswith("x-image-meta-property-"):
19+ headers[header.lower()] = value
20+
21 # NOTE(sirp): httplib under python2.4 won't accept a file-like object
22 # to request
23 conn.putrequest('PUT', '/v1/images/%s' % image_id)
24@@ -260,7 +273,7 @@
25 # 2. We're currently uploading a vanilla tarball. In order to be OVF/OVA
26 # compliant, we'll need to embed a minimal OVF manifest as the first
27 # file.
28- headers = {
29+ ovf_headers = {
30 'content-type': 'application/octet-stream',
31 'transfer-encoding': 'chunked',
32 'x-image-meta-is-public': 'True',
33@@ -271,7 +284,9 @@
34
35 # If we have an auth_token, set an x-auth-token header
36 if auth_token:
37- headers['x-auth-token'] = auth_token
38+ ovf_headers['x-auth-token'] = auth_token
39+
40+ headers.update(ovf_headers)
41
42 for header, value in headers.iteritems():
43 conn.putheader(header, value)