コード例 #1
0
ファイル: extension.py プロジェクト: dblundell/veta
 def __init__(self):
     super(VetaServerControllerExtension, self).__init__()
     self.backup_api = API()
コード例 #2
0
ファイル: extension.py プロジェクト: dblundell/veta
class VetaServerControllerExtension(wsgi.Controller):
    """
    The OpenStack Extension definition for Veta Backup capabilities.
    """

    def __init__(self):
        super(VetaServerControllerExtension, self).__init__()
        self.backup_api = API()

    @wsgi.action('backup_schedule_list')
    @convert_exception
    @authorize
    def _backup_schedule_list(self, req, id, body):
        context = req.environ["nova.context"]
        result = self.backup_api.backup_schedule_list(context, id)
        return self._build_schedule(req, result)

    @wsgi.action('backup_schedule_add')
    @convert_exception
    @authorize
    def _backup_schedule_add(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('backup_schedule_add', {})
        result = self.backup_api.backup_schedule_add(context, id, params)
        return self._build_schedule(req, result)

    @wsgi.action('backup_schedule_update')
    @convert_exception
    @authorize
    def _backup_schedule_update(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('backup_schedule_update', {})
        result = self.backup_api.backup_schedule_update(context, id, params)
        return self._build_schedule(req, result)

    @wsgi.action('backup_schedule_delete')
    @convert_exception
    @authorize
    def _backup_schedule_del(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('backup_schedule_delete', {})
        result = self.backup_api.backup_schedule_del(context, id, params)
        return self._build_schedule(req, result)

    @wsgi.action('backup_schedule_enable')
    @convert_exception
    @authorize
    def _backup_schedule_enable(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('backup_schedule_enable', {})
        params.update({ "active" : 1 })
        result = self.backup_api.backup_schedule_set_active(context, id, params)
        return self._build_schedule(req, result)

    @wsgi.action('backup_schedule_disable')
    @convert_exception
    @authorize
    def _backup_schedule_disable(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('backup_schedule_disable', {})
        params.update({ "active" : 0 })
        result = self.backup_api.backup_schedule_set_active(context, id, params)
        return self._build_schedule(req, result)

    @wsgi.action('backup_schedule_clear')
    @convert_exception
    @authorize
    def _backup_schedule_clear(self, req, id, body):
        context = req.environ["nova.context"]
        result = self.backup_api.backup_schedule_clear(context, id)
        return self._build_schedule(req, result)

    @wsgi.action('backup_schedule_list_backups')
    @convert_exception
    @authorize
    def _backup_schedule_list_backups(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('backup_schedule_list_backups', {})
        result = self.backup_api.backup_schedule_list_backups(context, id,
                                                              params)
        return self._build_instance_list(req, result)

    def _build_schedule(self, req, schedule):
        return webob.Response(status_int=200, body=json.dumps(schedule))

    def _build_instance_list(self, req, instances):
        return webob.Response(status_int=200, body=json.dumps(instances))