Esempio n. 1
0
class LocalVolumeSnapshottingController(object):
    """Local volume controller for OS API"""
    def __init__(self):
        self.local_volume_api = LocalAPI()

    def create(self, req, body):
        context = req.environ['nova.context']
        try:
            volume_id = body["volume_id"]
            image_name = body["name"]
            force_snapshot = body.get("force_snapshot", False)

        except KeyError:
            msg = _("Creating snapshot requires snapshot name, volume_id attributes")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        except TypeError:
            msg = _("Malformed body data")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            self.local_volume_api.snapshot(context,
                volume_id,
                image_name,
                force_snapshot)
        except exception.InstanceBusy:
            msg = _("Server is currently creating an image. Please wait.")
            raise webob.exc.HTTPConflict(explanation=msg)

        resp = webob.Response(status_int=202)
        return resp