Merge lp:~rackspace-titan/nova/glance-client-keystone into lp:~hudson-openstack/nova/trunk

Proposed by Dan Prince
Status: Merged
Approved by: Brian Waldon
Approved revision: 1548
Merged at revision: 1556
Proposed branch: lp:~rackspace-titan/nova/glance-client-keystone
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 751 lines (+124/-168)
19 files modified
nova/api/auth.py (+1/-0)
nova/api/openstack/create_instance_helper.py (+2/-1)
nova/compute/api.py (+2/-1)
nova/compute/manager.py (+2/-1)
nova/context.py (+6/-3)
nova/image/__init__.py (+3/-53)
nova/image/glance.py (+68/-23)
nova/tests/api/openstack/fakes.py (+1/-1)
nova/tests/glance/stubs.py (+3/-3)
nova/tests/integrated/integrated_helpers.py (+1/-1)
nova/tests/test_xenapi.py (+2/-1)
nova/virt/images.py (+2/-1)
nova/virt/libvirt/connection.py (+2/-2)
nova/virt/vmwareapi/fake.py (+3/-3)
nova/virt/vmwareapi/vmops.py (+3/-1)
nova/virt/vmwareapi/vmware_images.py (+9/-60)
nova/virt/xenapi/vm_utils.py (+7/-10)
nova/virt/xenapi/vmops.py (+2/-2)
plugins/xenserver/xenapi/etc/xapi.d/plugins/glance (+5/-1)
To merge this branch: bzr merge lp:~rackspace-titan/nova/glance-client-keystone
Reviewer Review Type Date Requested Status
Brian Waldon (community) Approve
Vish Ishaya (community) Approve
Review via email: mp+74889@code.launchpad.net

Description of the change

Update GlanceClient, GlanceImageService, and Glance Xen plugin to work with Glance keystone.

To post a comment you must log in.
Revision history for this message
Vish Ishaya (vishvananda) wrote :

This seems very important to get in diablo as well. Can you create a backported version off of 1541?

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

> This seems very important to get in diablo as well. Can you create a
> backported version off of 1541?

Should apply cleanly. I created a branch here based on 1541 with the glance keystone client changes:

  lp:~rackspace-titan/nova/glance-client-keystone-diablo

1548. By Dan Prince

pep8 fix.

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

Excellent. Definitely need this now that Glance has been updated.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/auth.py'
2--- nova/api/auth.py 2011-08-22 21:24:59 +0000
3+++ nova/api/auth.py 2011-09-12 19:20:51 +0000
4@@ -70,6 +70,7 @@
5 project_id,
6 roles=roles,
7 auth_token=auth_token,
8+ strategy='keystone',
9 remote_address=remote_address)
10
11 req.environ['nova.context'] = ctx
12
13=== modified file 'nova/api/openstack/create_instance_helper.py'
14--- nova/api/openstack/create_instance_helper.py 2011-09-07 14:32:00 +0000
15+++ nova/api/openstack/create_instance_helper.py 2011-09-12 19:20:51 +0000
16@@ -92,7 +92,8 @@
17 if str(image_href).startswith(req.application_url):
18 image_href = image_href.split('/').pop()
19 try:
20- image_service, image_id = nova.image.get_image_service(image_href)
21+ image_service, image_id = nova.image.get_image_service(context,
22+ image_href)
23 kernel_id, ramdisk_id = self._get_kernel_ramdisk_from_image(
24 req, image_service, image_id)
25 images = set([str(x['id']) for x in image_service.index(context)])
26
27=== modified file 'nova/compute/api.py'
28--- nova/compute/api.py 2011-09-08 21:10:03 +0000
29+++ nova/compute/api.py 2011-09-12 19:20:51 +0000
30@@ -202,7 +202,8 @@
31 self._check_injected_file_quota(context, injected_files)
32 self._check_requested_networks(context, requested_networks)
33
34- (image_service, image_id) = nova.image.get_image_service(image_href)
35+ (image_service, image_id) = nova.image.get_image_service(context,
36+ image_href)
37 image = image_service.show(context, image_id)
38
39 config_drive_id = None
40
41=== modified file 'nova/compute/manager.py'
42--- nova/compute/manager.py 2011-09-08 21:10:03 +0000
43+++ nova/compute/manager.py 2011-09-12 19:20:51 +0000
44@@ -322,7 +322,8 @@
45 # used by the image service. This should be refactored to be
46 # consistent.
47 image_href = instance['image_ref']
48- image_service, image_id = nova.image.get_image_service(image_href)
49+ image_service, image_id = nova.image.get_image_service(context,
50+ image_href)
51 image_meta = image_service.show(context, image_id)
52
53 try:
54
55=== modified file 'nova/context.py'
56--- nova/context.py 2011-08-30 02:27:28 +0000
57+++ nova/context.py 2011-09-12 19:20:51 +0000
58@@ -32,7 +32,7 @@
59
60 def __init__(self, user_id, project_id, is_admin=None, read_deleted=False,
61 roles=None, remote_address=None, timestamp=None,
62- request_id=None, auth_token=None):
63+ request_id=None, auth_token=None, strategy='noauth'):
64 self.user_id = user_id
65 self.project_id = project_id
66 self.roles = roles or []
67@@ -50,6 +50,7 @@
68 request_id = unicode(uuid.uuid4())
69 self.request_id = request_id
70 self.auth_token = auth_token
71+ self.strategy = strategy
72
73 def to_dict(self):
74 return {'user_id': self.user_id,
75@@ -60,7 +61,8 @@
76 'remote_address': self.remote_address,
77 'timestamp': utils.strtime(self.timestamp),
78 'request_id': self.request_id,
79- 'auth_token': self.auth_token}
80+ 'auth_token': self.auth_token,
81+ 'strategy': self.strategy}
82
83 @classmethod
84 def from_dict(cls, values):
85@@ -77,7 +79,8 @@
86 remote_address=self.remote_address,
87 timestamp=self.timestamp,
88 request_id=self.request_id,
89- auth_token=self.auth_token)
90+ auth_token=self.auth_token,
91+ strategy=self.strategy)
92
93
94 def get_admin_context(read_deleted=False):
95
96=== modified file 'nova/image/__init__.py'
97--- nova/image/__init__.py 2011-08-03 23:17:08 +0000
98+++ nova/image/__init__.py 2011-09-12 19:20:51 +0000
99@@ -16,70 +16,20 @@
100 # under the License.
101
102
103-from urlparse import urlparse
104-
105 import nova
106-from nova import exception
107 from nova import utils
108 from nova import flags
109-from nova.image import glance as glance_image_service
110+from nova.image import glance
111
112 FLAGS = flags.FLAGS
113
114
115-GlanceClient = utils.import_class('glance.client.Client')
116-
117-
118-def _parse_image_ref(image_href):
119- """Parse an image href into composite parts.
120-
121- :param image_href: href of an image
122- :returns: a tuple of the form (image_id, host, port)
123- :raises ValueError
124-
125- """
126- o = urlparse(image_href)
127- port = o.port or 80
128- host = o.netloc.split(':', 1)[0]
129- image_id = int(o.path.split('/')[-1])
130- return (image_id, host, port)
131-
132-
133 def get_default_image_service():
134 ImageService = utils.import_class(FLAGS.image_service)
135 return ImageService()
136
137
138-# FIXME(sirp): perhaps this should be moved to nova/images/glance so that we
139-# keep Glance specific code together for the most part
140-def get_glance_client(image_href):
141- """Get the correct glance client and id for the given image_href.
142-
143- The image_href param can be an href of the form
144- http://myglanceserver:9292/images/42, or just an int such as 42. If the
145- image_href is an int, then flags are used to create the default
146- glance client.
147-
148- :param image_href: image ref/id for an image
149- :returns: a tuple of the form (glance_client, image_id)
150-
151- """
152- image_href = image_href or 0
153- if str(image_href).isdigit():
154- glance_host, glance_port = \
155- glance_image_service.pick_glance_api_server()
156- glance_client = GlanceClient(glance_host, glance_port)
157- return (glance_client, int(image_href))
158-
159- try:
160- (image_id, host, port) = _parse_image_ref(image_href)
161- except ValueError:
162- raise exception.InvalidImageRef(image_href=image_href)
163- glance_client = GlanceClient(host, port)
164- return (glance_client, image_id)
165-
166-
167-def get_image_service(image_href):
168+def get_image_service(context, image_href):
169 """Get the proper image_service and id for the given image_href.
170
171 The image_href param can be an href of the form
172@@ -94,6 +44,6 @@
173 if str(image_href).isdigit():
174 return (get_default_image_service(), int(image_href))
175
176- (glance_client, image_id) = get_glance_client(image_href)
177+ (glance_client, image_id) = glance.get_glance_client(context, image_href)
178 image_service = nova.image.glance.GlanceImageService(glance_client)
179 return (image_service, image_id)
180
181=== modified file 'nova/image/glance.py'
182--- nova/image/glance.py 2011-09-01 19:19:38 +0000
183+++ nova/image/glance.py 2011-09-12 19:20:51 +0000
184@@ -23,6 +23,7 @@
185 import datetime
186 import json
187 import random
188+from urlparse import urlparse
189
190 from glance.common import exception as glance_exception
191
192@@ -42,6 +43,35 @@
193 GlanceClient = utils.import_class('glance.client.Client')
194
195
196+def _parse_image_ref(image_href):
197+ """Parse an image href into composite parts.
198+
199+ :param image_href: href of an image
200+ :returns: a tuple of the form (image_id, host, port)
201+ :raises ValueError
202+
203+ """
204+ o = urlparse(image_href)
205+ port = o.port or 80
206+ host = o.netloc.split(':', 1)[0]
207+ image_id = int(o.path.split('/')[-1])
208+ return (image_id, host, port)
209+
210+
211+def _create_glance_client(context, host, port):
212+ if context.strategy == 'keystone':
213+ # NOTE(dprince): Glance client just needs auth_tok right? Should we
214+ # add username and tenant to the creds below?
215+ creds = {'strategy': 'keystone',
216+ 'username': context.user_id,
217+ 'tenant': context.project_id}
218+ glance_client = GlanceClient(host, port, auth_tok=context.auth_token,
219+ creds=creds)
220+ else:
221+ glance_client = GlanceClient(host, port)
222+ return glance_client
223+
224+
225 def pick_glance_api_server():
226 """Return which Glance API server to use for the request
227
228@@ -57,6 +87,33 @@
229 return host, port
230
231
232+def get_glance_client(context, image_href):
233+ """Get the correct glance client and id for the given image_href.
234+
235+ The image_href param can be an href of the form
236+ http://myglanceserver:9292/images/42, or just an int such as 42. If the
237+ image_href is an int, then flags are used to create the default
238+ glance client.
239+
240+ :param image_href: image ref/id for an image
241+ :returns: a tuple of the form (glance_client, image_id)
242+
243+ """
244+ image_href = image_href or 0
245+ if str(image_href).isdigit():
246+ glance_host, glance_port = pick_glance_api_server()
247+ glance_client = _create_glance_client(context, glance_host,
248+ glance_port)
249+ return (glance_client, int(image_href))
250+
251+ try:
252+ (image_id, host, port) = _parse_image_ref(image_href)
253+ except ValueError:
254+ raise exception.InvalidImageRef(image_href=image_href)
255+ glance_client = _create_glance_client(context, glance_host, glance_port)
256+ return (glance_client, image_id)
257+
258+
259 class GlanceImageService(service.BaseImageService):
260 """Provides storage and retrieval of disk image objects within Glance."""
261
262@@ -71,23 +128,14 @@
263 def __init__(self, client=None):
264 self._client = client
265
266- def _get_client(self):
267+ def _get_client(self, context):
268 # NOTE(sirp): we want to load balance each request across glance
269 # servers. Since GlanceImageService is a long-lived object, `client`
270 # is made to choose a new server each time via this property.
271 if self._client is not None:
272 return self._client
273 glance_host, glance_port = pick_glance_api_server()
274- return GlanceClient(glance_host, glance_port)
275-
276- def _set_client(self, client):
277- self._client = client
278-
279- client = property(_get_client, _set_client)
280-
281- def _set_client_context(self, context):
282- """Sets the client's auth token."""
283- self.client.set_auth_token(context.auth_token)
284+ return _create_glance_client(context, glance_host, glance_port)
285
286 def index(self, context, **kwargs):
287 """Calls out to Glance for a list of images available."""
288@@ -128,14 +176,14 @@
289
290 def _get_images(self, context, **kwargs):
291 """Get image entitites from images service"""
292- self._set_client_context(context)
293
294 # ensure filters is a dict
295 kwargs['filters'] = kwargs.get('filters') or {}
296 # NOTE(vish): don't filter out private images
297 kwargs['filters'].setdefault('is_public', 'none')
298
299- return self._fetch_images(self.client.get_images_detailed, **kwargs)
300+ client = self._get_client(context)
301+ return self._fetch_images(client.get_images_detailed, **kwargs)
302
303 def _fetch_images(self, fetch_func, **kwargs):
304 """Paginate through results from glance server"""
305@@ -168,9 +216,8 @@
306
307 def show(self, context, image_id):
308 """Returns a dict with image data for the given opaque image id."""
309- self._set_client_context(context)
310 try:
311- image_meta = self.client.get_image_meta(image_id)
312+ image_meta = self._get_client(context).get_image_meta(image_id)
313 except glance_exception.NotFound:
314 raise exception.ImageNotFound(image_id=image_id)
315
316@@ -192,9 +239,9 @@
317
318 def get(self, context, image_id, data):
319 """Calls out to Glance for metadata and data and writes data."""
320- self._set_client_context(context)
321 try:
322- image_meta, image_chunks = self.client.get_image(image_id)
323+ client = self._get_client(context)
324+ image_meta, image_chunks = client.get_image(image_id)
325 except glance_exception.NotFound:
326 raise exception.ImageNotFound(image_id=image_id)
327
328@@ -210,7 +257,6 @@
329 :raises: AlreadyExists if the image already exist.
330
331 """
332- self._set_client_context(context)
333 # Translate Base -> Service
334 LOG.debug(_('Creating image in Glance. Metadata passed in %s'),
335 image_meta)
336@@ -218,7 +264,7 @@
337 LOG.debug(_('Metadata after formatting for Glance %s'),
338 sent_service_image_meta)
339
340- recv_service_image_meta = self.client.add_image(
341+ recv_service_image_meta = self._get_client(context).add_image(
342 sent_service_image_meta, data)
343
344 # Translate Service -> Base
345@@ -233,12 +279,12 @@
346 :raises: ImageNotFound if the image does not exist.
347
348 """
349- self._set_client_context(context)
350 # NOTE(vish): show is to check if image is available
351 self.show(context, image_id)
352 image_meta = _convert_to_string(image_meta)
353 try:
354- image_meta = self.client.update_image(image_id, image_meta, data)
355+ client = self._get_client(context)
356+ image_meta = client.update_image(image_id, image_meta, data)
357 except glance_exception.NotFound:
358 raise exception.ImageNotFound(image_id=image_id)
359
360@@ -251,11 +297,10 @@
361 :raises: ImageNotFound if the image does not exist.
362
363 """
364- self._set_client_context(context)
365 # NOTE(vish): show is to check if image is available
366 self.show(context, image_id)
367 try:
368- result = self.client.delete_image(image_id)
369+ result = self._get_client(context).delete_image(image_id)
370 except glance_exception.NotFound:
371 raise exception.ImageNotFound(image_id=image_id)
372 return result
373
374=== modified file 'nova/tests/api/openstack/fakes.py'
375--- nova/tests/api/openstack/fakes.py 2011-09-01 04:55:12 +0000
376+++ nova/tests/api/openstack/fakes.py 2011-09-12 19:20:51 +0000
377@@ -124,7 +124,7 @@
378
379
380 def stub_out_image_service(stubs):
381- def fake_get_image_service(image_href):
382+ def fake_get_image_service(context, image_href):
383 return (nova.image.fake.FakeImageService(), image_href)
384 stubs.Set(nova.image, 'get_image_service', fake_get_image_service)
385 stubs.Set(nova.image, 'get_default_image_service',
386
387=== modified file 'nova/tests/glance/stubs.py'
388--- nova/tests/glance/stubs.py 2011-08-04 15:40:10 +0000
389+++ nova/tests/glance/stubs.py 2011-09-12 19:20:51 +0000
390@@ -16,14 +16,14 @@
391
392 import StringIO
393
394-import nova.image
395+from nova.image import glance
396
397
398 def stubout_glance_client(stubs):
399- def fake_get_glance_client(image_href):
400+ def fake_get_glance_client(context, image_href):
401 image_id = int(str(image_href).split('/')[-1])
402 return (FakeGlance('foo'), image_id)
403- stubs.Set(nova.image, 'get_glance_client', fake_get_glance_client)
404+ stubs.Set(glance, 'get_glance_client', fake_get_glance_client)
405
406
407 class FakeGlance(object):
408
409=== modified file 'nova/tests/integrated/integrated_helpers.py'
410--- nova/tests/integrated/integrated_helpers.py 2011-08-18 03:22:30 +0000
411+++ nova/tests/integrated/integrated_helpers.py 2011-09-12 19:20:51 +0000
412@@ -64,7 +64,7 @@
413 self.flags(**f)
414 self.flags(verbose=True)
415
416- def fake_get_image_service(image_href):
417+ def fake_get_image_service(context, image_href):
418 image_id = int(str(image_href).split('/')[-1])
419 return (nova.image.fake.FakeImageService(), image_id)
420 self.stubs.Set(nova.image, 'get_image_service', fake_get_image_service)
421
422=== modified file 'nova/tests/test_xenapi.py'
423--- nova/tests/test_xenapi.py 2011-09-06 21:41:35 +0000
424+++ nova/tests/test_xenapi.py 2011-09-12 19:20:51 +0000
425@@ -932,8 +932,9 @@
426 self.fake_instance.architecture = 'x86-64'
427
428 def assert_disk_type(self, disk_type):
429+ ctx = context.RequestContext('fake', 'fake')
430 dt = vm_utils.VMHelper.determine_disk_image_type(
431- self.fake_instance)
432+ self.fake_instance, ctx)
433 self.assertEqual(disk_type, dt)
434
435 def test_instance_disk(self):
436
437=== modified file 'nova/virt/images.py'
438--- nova/virt/images.py 2011-07-29 21:58:27 +0000
439+++ nova/virt/images.py 2011-09-12 19:20:51 +0000
440@@ -37,7 +37,8 @@
441 # when it is added to glance. Right now there is no
442 # auth checking in glance, so we assume that access was
443 # checked before we got here.
444- (image_service, image_id) = nova.image.get_image_service(image_href)
445+ (image_service, image_id) = nova.image.get_image_service(context,
446+ image_href)
447 with open(path, "wb") as image_file:
448 metadata = image_service.get(context, image_id, image_file)
449 return metadata
450
451=== modified file 'nova/virt/libvirt/connection.py'
452--- nova/virt/libvirt/connection.py 2011-09-10 00:48:53 +0000
453+++ nova/virt/libvirt/connection.py 2011-09-12 19:20:51 +0000
454@@ -398,10 +398,10 @@
455 virt_dom = self._lookup_by_name(instance['name'])
456
457 (image_service, image_id) = nova.image.get_image_service(
458- instance['image_ref'])
459+ context, instance['image_ref'])
460 base = image_service.show(context, image_id)
461 (snapshot_image_service, snapshot_image_id) = \
462- nova.image.get_image_service(image_href)
463+ nova.image.get_image_service(context, image_href)
464 snapshot = snapshot_image_service.show(context, snapshot_image_id)
465
466 metadata = {'is_public': False,
467
468=== modified file 'nova/virt/vmwareapi/fake.py'
469--- nova/virt/vmwareapi/fake.py 2011-07-27 00:40:50 +0000
470+++ nova/virt/vmwareapi/fake.py 2011-09-12 19:20:51 +0000
471@@ -412,7 +412,7 @@
472 return [{'type': 'fake'}]
473
474
475-def fake_fetch_image(image, instance, **kwargs):
476+def fake_fetch_image(context, image, instance, **kwargs):
477 """Fakes fetch image call. Just adds a reference to the db for the file."""
478 ds_name = kwargs.get("datastore_name")
479 file_path = kwargs.get("file_path")
480@@ -420,12 +420,12 @@
481 _add_file(ds_file_path)
482
483
484-def fake_upload_image(image, instance, **kwargs):
485+def fake_upload_image(context, image, instance, **kwargs):
486 """Fakes the upload of an image."""
487 pass
488
489
490-def fake_get_vmdk_size_and_properties(image_id, instance):
491+def fake_get_vmdk_size_and_properties(context, image_id, instance):
492 """Fakes the file size and properties fetch for the image file."""
493 props = {"vmware_ostype": "otherGuest",
494 "vmware_adaptertype": "lsiLogic"}
495
496=== modified file 'nova/virt/vmwareapi/vmops.py'
497--- nova/virt/vmwareapi/vmops.py 2011-07-29 21:58:27 +0000
498+++ nova/virt/vmwareapi/vmops.py 2011-09-12 19:20:51 +0000
499@@ -157,7 +157,7 @@
500 repository.
501 """
502 image_size, image_properties = \
503- vmware_images.get_vmdk_size_and_properties(
504+ vmware_images.get_vmdk_size_and_properties(context,
505 instance.image_ref, instance)
506 vmdk_file_size_in_kb = int(image_size) / 1024
507 os_type = image_properties.get("vmware_ostype", "otherGuest")
508@@ -282,6 +282,7 @@
509 # Upload the -flat.vmdk file whose meta-data file we just created
510 # above
511 vmware_images.fetch_image(
512+ context,
513 instance.image_ref,
514 instance,
515 host=self._session._host_ip,
516@@ -448,6 +449,7 @@
517 # Upload the contents of -flat.vmdk file which has the disk data.
518 LOG.debug(_("Uploading image %s") % snapshot_name)
519 vmware_images.upload_image(
520+ context,
521 snapshot_name,
522 instance,
523 os_type=os_type,
524
525=== modified file 'nova/virt/vmwareapi/vmware_images.py'
526--- nova/virt/vmwareapi/vmware_images.py 2011-08-04 00:26:37 +0000
527+++ nova/virt/vmwareapi/vmware_images.py 2011-09-12 19:20:51 +0000
528@@ -20,15 +20,13 @@
529
530 from nova import exception
531 from nova import flags
532-import nova.image
533+from nova.image import glance
534 from nova import log as logging
535 from nova.virt.vmwareapi import io_util
536 from nova.virt.vmwareapi import read_write_util
537
538 LOG = logging.getLogger("nova.virt.vmwareapi.vmware_images")
539
540-FLAGS = flags.FLAGS
541-
542 QUEUE_BUFFER_SIZE = 10
543
544
545@@ -87,36 +85,10 @@
546 write_file_handle.close()
547
548
549-def fetch_image(image, instance, **kwargs):
550- """Fetch an image for attaching to the newly created VM."""
551- # Depending upon the image service, make appropriate image service call
552- if FLAGS.image_service == "nova.image.glance.GlanceImageService":
553- func = _get_glance_image
554- elif FLAGS.image_service == "nova.image.s3.S3ImageService":
555- func = _get_s3_image
556- else:
557- raise NotImplementedError(_("The Image Service %s is not implemented")
558- % FLAGS.image_service)
559- return func(image, instance, **kwargs)
560-
561-
562-def upload_image(image, instance, **kwargs):
563- """Upload the newly snapshotted VM disk file."""
564- # Depending upon the image service, make appropriate image service call
565- if FLAGS.image_service == "nova.image.glance.GlanceImageService":
566- func = _put_glance_image
567- elif FLAGS.image_service == "nova.image.s3.S3ImageService":
568- func = _put_s3_image
569- else:
570- raise NotImplementedError(_("The Image Service %s is not implemented")
571- % FLAGS.image_service)
572- return func(image, instance, **kwargs)
573-
574-
575-def _get_glance_image(image, instance, **kwargs):
576+def fetch_image(context, image, instance, **kwargs):
577 """Download image from the glance image server."""
578 LOG.debug(_("Downloading image %s from glance image server") % image)
579- (glance_client, image_id) = nova.image.get_glance_client(image)
580+ (glance_client, image_id) = glance.get_glance_client(context, image)
581 metadata, read_iter = glance_client.get_image(image_id)
582 read_file_handle = read_write_util.GlanceFileRead(read_iter)
583 file_size = int(metadata['size'])
584@@ -132,17 +104,7 @@
585 LOG.debug(_("Downloaded image %s from glance image server") % image)
586
587
588-def _get_s3_image(image, instance, **kwargs):
589- """Download image from the S3 image server."""
590- raise NotImplementedError
591-
592-
593-def _get_local_image(image, instance, **kwargs):
594- """Download image from the local nova compute node."""
595- raise NotImplementedError
596-
597-
598-def _put_glance_image(image, instance, **kwargs):
599+def upload_image(context, image, instance, **kwargs):
600 """Upload the snapshotted vm disk file to Glance image server."""
601 LOG.debug(_("Uploading image %s to the Glance image server") % image)
602 read_file_handle = read_write_util.VmWareHTTPReadFile(
603@@ -152,7 +114,7 @@
604 kwargs.get("cookies"),
605 kwargs.get("file_path"))
606 file_size = read_file_handle.get_size()
607- (glance_client, image_id) = nova.image.get_glance_client(image)
608+ (glance_client, image_id) = glance.get_glance_client(context, image)
609 # The properties and other fields that we need to set for the image.
610 image_metadata = {"is_public": True,
611 "disk_format": "vmdk",
612@@ -168,17 +130,7 @@
613 LOG.debug(_("Uploaded image %s to the Glance image server") % image)
614
615
616-def _put_local_image(image, instance, **kwargs):
617- """Upload the snapshotted vm disk file to the local nova compute node."""
618- raise NotImplementedError
619-
620-
621-def _put_s3_image(image, instance, **kwargs):
622- """Upload the snapshotted vm disk file to S3 image server."""
623- raise NotImplementedError
624-
625-
626-def get_vmdk_size_and_properties(image, instance):
627+def get_vmdk_size_and_properties(context, image, instance):
628 """
629 Get size of the vmdk file that is to be downloaded for attach in spawn.
630 Need this to create the dummy virtual disk for the meta-data file. The
631@@ -186,12 +138,9 @@
632 """
633
634 LOG.debug(_("Getting image size for the image %s") % image)
635- if FLAGS.image_service == "nova.image.glance.GlanceImageService":
636- (glance_client, image_id) = nova.image.get_glance_client(image)
637- meta_data = glance_client.get_image_meta(image_id)
638- size, properties = meta_data["size"], meta_data["properties"]
639- elif FLAGS.image_service == "nova.image.s3.S3ImageService":
640- raise NotImplementedError
641+ (glance_client, image_id) = glance.get_glance_client(context, image)
642+ meta_data = glance_client.get_image_meta(image_id)
643+ size, properties = meta_data["size"], meta_data["properties"]
644 LOG.debug(_("Got image size of %(size)s for the image %(image)s") %
645 locals())
646 return size, properties
647
648=== modified file 'nova/virt/xenapi/vm_utils.py'
649--- nova/virt/xenapi/vm_utils.py 2011-08-23 05:17:51 +0000
650+++ nova/virt/xenapi/vm_utils.py 2011-09-12 19:20:51 +0000
651@@ -31,12 +31,10 @@
652 import uuid
653 from xml.dom import minidom
654
655-import glance.client
656 from nova import db
657 from nova import exception
658 from nova import flags
659-import nova.image
660-from nova.image import glance as glance_image_service
661+from nova.image import glance
662 from nova import log as logging
663 from nova import utils
664 from nova.compute import instance_types
665@@ -383,8 +381,7 @@
666
667 os_type = instance.os_type or FLAGS.default_os_type
668
669- glance_host, glance_port = \
670- glance_image_service.pick_glance_api_server()
671+ glance_host, glance_port = glance.pick_glance_api_server()
672 params = {'vdi_uuids': vdi_uuids,
673 'image_id': image_id,
674 'glance_host': glance_host,
675@@ -447,8 +444,7 @@
676 # pass them as arguments
677 uuid_stack = [str(uuid.uuid4()) for i in xrange(2)]
678
679- glance_host, glance_port = \
680- glance_image_service.pick_glance_api_server()
681+ glance_host, glance_port = glance.pick_glance_api_server()
682 params = {'image_id': image,
683 'glance_host': glance_host,
684 'glance_port': glance_port,
685@@ -546,7 +542,7 @@
686 else:
687 sr_ref = safe_find_sr(session)
688
689- glance_client, image_id = nova.image.get_glance_client(image)
690+ glance_client, image_id = glance.get_glance_client(context, image)
691 glance_client.set_auth_token(getattr(context, 'auth_token', None))
692 meta, image_file = glance_client.get_image(image_id)
693 virtual_size = int(meta['size'])
694@@ -606,7 +602,7 @@
695 raise e
696
697 @classmethod
698- def determine_disk_image_type(cls, instance):
699+ def determine_disk_image_type(cls, instance, context):
700 """Disk Image Types are used to determine where the kernel will reside
701 within an image. To figure out which type we're dealing with, we use
702 the following rules:
703@@ -639,7 +635,8 @@
704 'vhd': ImageType.DISK_VHD,
705 'iso': ImageType.DISK_ISO}
706 image_ref = instance.image_ref
707- glance_client, image_id = nova.image.get_glance_client(image_ref)
708+ glance_client, image_id = glance.get_glance_client(context,
709+ image_ref)
710 meta = glance_client.get_image_meta(image_id)
711 disk_format = meta['disk_format']
712 try:
713
714=== modified file 'nova/virt/xenapi/vmops.py'
715--- nova/virt/xenapi/vmops.py 2011-09-08 21:10:45 +0000
716+++ nova/virt/xenapi/vmops.py 2011-09-12 19:20:51 +0000
717@@ -135,7 +135,7 @@
718 self._session.call_xenapi('VM.start', vm_ref, False, False)
719
720 def _create_disks(self, context, instance):
721- disk_image_type = VMHelper.determine_disk_image_type(instance)
722+ disk_image_type = VMHelper.determine_disk_image_type(instance, context)
723 vdis = VMHelper.fetch_image(context, self._session,
724 instance, instance.image_ref,
725 instance.user_id, instance.project_id,
726@@ -176,7 +176,7 @@
727 power_state.SHUTDOWN)
728 return
729
730- disk_image_type = VMHelper.determine_disk_image_type(instance)
731+ disk_image_type = VMHelper.determine_disk_image_type(instance, context)
732 kernel = None
733 ramdisk = None
734 try:
735
736=== modified file 'plugins/xenserver/xenapi/etc/xapi.d/plugins/glance'
737--- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance 2011-08-05 00:12:19 +0000
738+++ plugins/xenserver/xenapi/etc/xapi.d/plugins/glance 2011-09-12 19:20:51 +0000
739@@ -252,7 +252,11 @@
740 # NOTE(dprince): We need to resend any existing Glance meta/property
741 # headers so they are preserved in Glance. We obtain them here with a
742 # HEAD request.
743- conn.request('HEAD', '/v1/images/%s' % image_id)
744+ conn.putrequest('HEAD', '/v1/images/%s' % image_id)
745+ if auth_token:
746+ conn.putheader('x-auth-token', auth_token)
747+ conn.endheaders()
748+
749 resp = conn.getresponse()
750 if resp.status != httplib.OK:
751 raise Exception("Unexpected response from Glance %i" % resp.status)