From eed626753c23bb82453bc5176193831fbb9e538c Mon Sep 17 00:00:00 2001 From: Michael Still Date: Tue, 20 Nov 2012 16:51:40 +1100 Subject: Map cinder snapshot statuses to ec2. EC2 has way fewer statuses than cinder does, so we need to map them to valid entries. Resolves bug 1080284. DocImpact. Change-Id: I73bb2905577fb6f727c0a805df2654ad1bb4ad72 --- nova/api/ec2/cloud.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 8155efb10..796505b57 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -345,14 +345,34 @@ class CloudController(object): snapshots.append(snapshot) else: snapshots = self.volume_api.get_all_snapshots(context) - snapshots = [self._format_snapshot(context, s) for s in snapshots] - return {'snapshotSet': snapshots} + + formatted_snapshots = [] + for s in snapshots: + formatted = self._format_snapshot(context, s) + if formatted: + formatted_snapshots.append(formatted) + return {'snapshotSet': formatted_snapshots} def _format_snapshot(self, context, snapshot): + # NOTE(mikal): this is just a set of strings in cinder. If they + # implement an enum, then we should move this code to use it. The + # valid ec2 statuses are "pending", "completed", and "error". + status_map = {'new': 'pending', + 'creating': 'pending', + 'available': 'completed', + 'active': 'completed', + 'deleting': 'pending', + 'deleted': None, + 'error': 'error'} + + mapped_status = status_map.get(snapshot['status'], snapshot['status']) + if not mapped_status: + return None + s = {} s['snapshotId'] = ec2utils.id_to_ec2_snap_id(snapshot['id']) s['volumeId'] = ec2utils.id_to_ec2_vol_id(snapshot['volume_id']) - s['status'] = snapshot['status'] + s['status'] = mapped_status s['startTime'] = snapshot['created_at'] s['progress'] = snapshot['progress'] s['ownerId'] = snapshot['project_id'] -- cgit