~cbehrens/nova/servers-search

« back to all changes in this revision

Viewing changes to plugins/xenserver/xenapi/etc/xapi.d/plugins/glance

  • Committer: Chris Behrens
  • Date: 2011-08-04 21:58:42 UTC
  • mfrom: (1250.1.127 nova)
  • Revision ID: cbehrens@codestud.com-20110804215842-nfykqar8k74l33tj
merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
248
248
    using chunked-transfer-encoded HTTP.
249
249
    """
250
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
264
    # NOTE(sirp): httplib under python2.4 won't accept a file-like object
252
265
    # to request
253
266
    conn.putrequest('PUT', '/v1/images/%s' % image_id)
260
273
    #   2. We're currently uploading a vanilla tarball. In order to be OVF/OVA
261
274
    #      compliant, we'll need to embed a minimal OVF manifest as the first
262
275
    #      file.
263
 
    headers = {
 
276
    ovf_headers = {
264
277
        'content-type': 'application/octet-stream',
265
278
        'transfer-encoding': 'chunked',
266
279
        'x-image-meta-is-public': 'True',
271
284
 
272
285
    # If we have an auth_token, set an x-auth-token header
273
286
    if auth_token:
274
 
        headers['x-auth-token'] = auth_token
 
287
        ovf_headers['x-auth-token'] = auth_token
 
288
 
 
289
    headers.update(ovf_headers)
275
290
 
276
291
    for header, value in headers.iteritems():
277
292
        conn.putheader(header, value)