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)
+ 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):
return dict(rv.iteritems())
def delete(self, context, backup_id):
- """
- Make the RPC call to delete a volume backup.
- """
+ """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']:
backup['id'])
# TODO(moorehef): Add support for search_opts, discarded atm
- def get_all(self, context, search_opts={}):
+ def get_all(self, context, search_opts=None):
+ if search_opts is None:
+ search_opts = {}
check_policy(context, 'get_all')
if context.is_admin:
backups = self.db.backup_get_all(context)
return backups
def _check_backup_service(self, volume):
- """
- Check if there is an backup service available
- """
+ """Check if there is an backup service available"""
topic = CONF.backup_topic
ctxt = context.get_admin_context()
services = self.db.service_get_all_by_topic(ctxt, topic)
def create(self, context, name, description, volume_id,
container, availability_zone=None):
- """
- Make the RPC call to create a volume backup.
- """
+ """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":
return backup
def restore(self, context, backup_id, volume_id=None):
- """
- Make the RPC call to restore a volume backup.
- """
+ """Make the RPC call to restore a volume backup."""
check_policy(context, 'restore')
backup = self.get(context, backup_id)
if backup['status'] != 'available':
self.delete_backup(ctxt, backup['id'])
def create_backup(self, context, backup_id):
- """
- Create volume backups using configured backup service.
- """
+ """Create volume backups using configured backup service."""
backup = self.db.backup_get(context, backup_id)
volume_id = backup['volume_id']
volume = self.db.volume_get(context, volume_id)
LOG.info(_('create_backup finished. backup: %s'), backup_id)
def restore_backup(self, context, backup_id, volume_id):
- """
- Restore volume backups from configured backup service.
- """
+ """Restore volume backups from configured backup service."""
LOG.info(_('restore_backup started, restoring backup: %(backup_id)s'
' to volume: %(volume_id)s') %
{'backup_id': backup_id, 'volume_id': volume_id})
{'backup_id': backup_id, 'volume_id': volume_id})
def delete_backup(self, context, backup_id):
- """
- Delete volume backup from configured backup service.
- """
+ """Delete volume backup from configured backup service."""
backup = self.db.backup_get(context, backup_id)
LOG.info(_('delete_backup started, backup: %s'), backup_id)
self.db.backup_update(context, backup_id, {'host': self.host})