diff options
| author | Dan Prince <dan.prince@rackspace.com> | 2011-06-07 21:20:55 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-06-07 21:20:55 +0000 |
| commit | 762afdd426c35d1fc82cb7a17683a50ff21e717e (patch) | |
| tree | bcc67641b338d020d4fd33665e1e9b99fe927c8f /nova/api | |
| parent | 11b9bb69513686015067a6405f343c1be508a5eb (diff) | |
| parent | 8f93aa59aca5440a4d9668942703bf235379ed59 (diff) | |
| download | nova-762afdd426c35d1fc82cb7a17683a50ff21e717e.tar.gz nova-762afdd426c35d1fc82cb7a17683a50ff21e717e.tar.xz nova-762afdd426c35d1fc82cb7a17683a50ff21e717e.zip | |
DRY up the image_state logic. Fix an issue where glance style images (which aren't required to have an 'image_state' property) couldn't be used to run instances on the EC2 controller.
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/ec2/cloud.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index ac73cd595..316298c39 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -136,6 +136,13 @@ class CloudController(object): return services[0]['availability_zone'] return 'unknown zone' + def _get_image_state(self, image): + # NOTE(vish): fallback status if image_state isn't set + state = image.get('status') + if state == 'active': + state = 'available' + return image['properties'].get('image_state', state) + def get_metadata(self, address): ctxt = context.get_admin_context() instance_ref = self.compute_api.get_all(ctxt, fixed_ip=address) @@ -896,14 +903,13 @@ class CloudController(object): ramdisk = self._get_image(context, kwargs['ramdisk_id']) kwargs['ramdisk_id'] = ramdisk['id'] image = self._get_image(context, kwargs['image_id']) - if not image: + + if image: + image_state = self._get_image_state(image) + else: raise exception.ImageNotFound(image_id=kwargs['image_id']) - try: - available = (image['properties']['image_state'] == 'available') - except KeyError: - available = False - if not available: + if image_state != 'available': raise exception.ApiError(_('Image must be available')) instances = self.compute_api.create(context, @@ -1021,11 +1027,8 @@ class CloudController(object): get('image_location'), name) else: i['imageLocation'] = image['properties'].get('image_location') - # NOTE(vish): fallback status if image_state isn't set - state = image.get('status') - if state == 'active': - state = 'available' - i['imageState'] = image['properties'].get('image_state', state) + + i['imageState'] = self._get_image_state(image) i['displayName'] = name i['description'] = image.get('description') display_mapping = {'aki': 'kernel', |
