Skip to content

Instantly share code, notes, and snippets.

@j-griffith
Created May 2, 2014 19:02
Show Gist options
  • Save j-griffith/11483417 to your computer and use it in GitHub Desktop.
Save j-griffith/11483417 to your computer and use it in GitHub Desktop.
diff --git a/cinder/api/contrib/admin_actions.py b/cinder/api/contrib/admin_actions.py
index 2766d35..5aa9bcb 100644
--- a/cinder/api/contrib/admin_actions.py
+++ b/cinder/api/contrib/admin_actions.py
@@ -33,13 +33,10 @@ class AdminController(wsgi.Controller):
collection = None # api collection to extend
- # FIXME(clayg): this will be hard to keep up-to-date
- # Concrete classes can expand or over-ride
- valid_status = set(['creating',
- 'available',
- 'deleting',
- 'error',
- 'error_deleting', ])
+ valid_status = {
+ 'status': ['creating', 'available',
+ 'deleting', 'error',
+ 'error_deleting']}
def __init__(self, *args, **kwargs):
super(AdminController, self).__init__(*args, **kwargs)
@@ -57,13 +54,16 @@ class AdminController(wsgi.Controller):
raise NotImplementedError()
def validate_update(self, body):
- update = {}
- try:
- update['status'] = body['status']
- except (TypeError, KeyError):
- raise exc.HTTPBadRequest("Must specify 'status'")
- if update['status'] not in self.valid_status:
- raise exc.HTTPBadRequest("Must specify a valid status")
+ for status in self.valid_status.iterkeys():
+ update = {}
+ status_input = body.get(status)
+ if status_input:
+ if status_input in self.valid_status[status]:
+ update[status] = status_input
+ else:
+ raise exc.HTTPBadRequest('Invalid state argument %s' % status_input)
+ else:
+ raise exc.HTTPBadRequest('Must specify one or more of: %s' % self.valid_status)
return update
def authorize(self, context, action_name):
@@ -114,20 +114,6 @@ class VolumeAdminController(AdminController):
collection = 'volumes'
- # FIXME(jdg): We're appending additional valid status
- # entries to the set we declare in the parent class
- # this doesn't make a ton of sense, we should probably
- # look at the structure of this whole process again
- # Perhaps we don't even want any definitions in the abstract
- # parent class?
- valid_status = AdminController.valid_status.union(
- set(['attaching', 'in-use', 'detaching']))
-
- valid_attach_status = set(['detached', 'attached', ])
- valid_migration_status = set(['migrating', 'error',
- 'completing', 'none',
- 'starting', ])
-
def _update(self, *args, **kwargs):
db.volume_update(*args, **kwargs)
@@ -138,35 +124,10 @@ class VolumeAdminController(AdminController):
return self.volume_api.delete(*args, **kwargs)
def validate_update(self, body):
- update = {}
- status = body.get('status', None)
- attach_status = body.get('attach_status', None)
- migration_status = body.get('migration_status', None)
-
- valid = False
- if status:
- valid = True
- update = super(VolumeAdminController, self).validate_update(body)
-
- if attach_status:
- valid = True
- update['attach_status'] = attach_status
- if update['attach_status'] not in self.valid_attach_status:
- raise exc.HTTPBadRequest("Must specify a valid attach status")
-
- if migration_status:
- valid = True
- update['migration_status'] = migration_status.lower()
- if update['migration_status'] not in self.valid_migration_status:
- raise exc.HTTPBadRequest("Must specify a valid migration "
- "status")
- if update['migration_status'] == 'none':
- update['migration_status'] = None
-
- if not valid:
- raise exc.HTTPBadRequest("Must specify 'status', 'attach_status' "
- "or 'migration_status' for update.")
- return update
+ self.valid_status['status'].extend(['attaching', 'in-use', 'detaching'])
+ self.valid_status['attach_status'] = ['detached', 'attached']
+ self.valid_status['migration_status'] = ['migrating', 'error', 'completing', 'none', 'starting']
+ return super(VolumeAdminController, self).validate_update(body)
@wsgi.action('os-force_detach')
def _force_detach(self, req, id, body):
@@ -237,6 +198,10 @@ class SnapshotAdminController(AdminController):
collection = 'snapshots'
+ def validate_update(self, body):
+ self.valid_status = super(SnapshotAdminController, self).valid_status
+ return super(SnapshotAdminController, self).validate_update(body)
+
def _update(self, *args, **kwargs):
db.snapshot_update(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment