from cinder import exception
from cinder import flags
from cinder.openstack.common import log as logging
+import cinder.policy
import cinder.volume
LOG = logging.getLogger(__name__)
+def check_policy(context, action):
+ target = {
+ 'project_id': context.project_id,
+ 'user_id': context.user_id,
+ }
+ _action = 'backup:%s' % action
+ cinder.policy.enforce(context, _action, target)
+
+
class API(base.Base):
"""API for interacting with the volume backup manager."""
super(API, self).__init__(db_driver)
def get(self, context, backup_id):
+ check_policy(context, 'get')
rv = self.db.backup_get(context, backup_id)
return dict(rv.iteritems())
"""
Make the RPC call to delete a volume backup.
"""
+ check_policy(context, 'delete')
backup = self.get(context, backup_id)
if backup['status'] not in ['available', 'error']:
msg = _('Backup status must be available or error')
# TODO(moorehef): Add support for search_opts, discarded atm
def get_all(self, context, search_opts={}):
+ check_policy(context, 'get_all')
if context.is_admin:
backups = self.db.backup_get_all(context)
else:
"""
Make the RPC call to create a volume backup.
"""
+ check_policy(context, 'create')
volume = self.volume_api.get(context, volume_id)
if volume['status'] != "available":
msg = _('Volume to be backed up must be available')
"""
Make the RPC call to restore a volume backup.
"""
+ check_policy(context, 'restore')
backup = self.get(context, backup_id)
if backup['status'] != 'available':
msg = _('Backup status must be available')