summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJohn Tran <jtran@attinteractive.com>2011-05-02 14:25:21 -0700
committerJohn Tran <jtran@attinteractive.com>2011-05-02 14:25:21 -0700
commit10db492376a8bb8409e3fb3c33707865ac0f3ee7 (patch)
tree64a27733499ffbdaf5b3e84d6da3c30ac6907813 /nova/api
parent655eb8fbd21376e694f8134e42f10ddbc1aafb0e (diff)
implemented review suggestion EAFP style, and fixed test stub fake_show needs to have image_state = available or other tests will fail
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/cloud.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 0ea0e3603..5dc608139 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -815,17 +815,21 @@ 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 not image:
raise exception.NotFound(_('Image %s not found') %
kwargs['image_id'])
- if not 'properties' in image or \
- (not 'image_state' in image['properties']) or \
- (image['properties']['image_state'] is not 'available'):
+ try:
+ available = (image['properties']['image_state'] == 'available')
+ except KeyError:
+ available = False
+
+ if not available:
raise exception.ApiError(_('Image must be available'))
+
instances = self.compute_api.create(context,
instance_type=instance_types.get_by_type(
kwargs.get('instance_type', None)),
- image_id = image['id'],
+ image_id=image['id'],
min_count=int(kwargs.get('min_count', max_count)),
max_count=max_count,
kernel_id=kwargs.get('kernel_id'),