Beispiel #1
0
 def _initialize_connection(self, volume_id, initiator):
     cherrypy.response.headers['Content-Type'] = 'application/json'
     res = find_volume(volume_id)
     params = dict(volume_id=volume_id, initiator=initiator)
     ret = playcaller.PlayCaller(res.type, 'initialize_connection',
                                 params).run()
     return json.dumps(dict(connection_info=ret['connection_info']))
Beispiel #2
0
    def _create_volume(self):
        cherrypy.response.headers['Content-Type'] = 'application/json'
        volume_id = str(uuid.uuid4())
        volume_type = cherrypy.request.json['volume']['volume_type']
        volume_size = cherrypy.request.json['volume']['size']
        source_volid = cherrypy.request.json['volume'].get('source_volid')
        snapshot_id = cherrypy.request.json['volume'].get('snapshot_id')

        if volume_type not in volume_types():
            raise cherrypy.HTTPError(400, "Unsupported volume type")

        params = dict(
            volume_id=volume_id,
            volume_size=volume_size,
            source_volid=source_volid,
            snapshot_id=snapshot_id,
        )

        if source_volid and snapshot_id:
            raise cherrypy.HTTPError(
                401, "Only one of source_volid and "
                "snapshot_id is allowed")

        playcaller.PlayCaller(volume_type, 'create_volume', params).run()
        cherrypy.response.status = 202  # Accepted
        return json.dumps(
            dict(volume=dict(
                status="creating",
                id=volume_id,
                size=params['volume_size'],
                volume_type=volume_type,
                source_volid=source_volid,
                snapshot_id=snapshot_id,
            )))
Beispiel #3
0
def find_snapshot(snapshot_id):
    for volume_type in volume_types():
        params = dict(
            snapshot_id=snapshot_id,
            volume_id=None,  # Will be looked up
        )
        cherrypy.log("Searching backend %s for snapshot %s" %
                     (volume_type, snapshot_id))
        ret = playcaller.PlayCaller(volume_type, 'get_snapshot', params).run()
        if ret["state"] == 'present':
            return DiscoveredResource(volume_type, ret)
    else:
        raise cherrypy.HTTPError(404, "Snapshot not found")
Beispiel #4
0
def find_volume(volume_id):
    for volume_type in volume_types():
        params = dict(
            volume_id=volume_id,
            volume_size=0,
        )
        cherrypy.log("Searching backend %s for volume %s" %
                     (volume_type, volume_id))
        ret = playcaller.PlayCaller(volume_type, 'get_volume', params).run()
        if ret['state'] == 'present':
            return DiscoveredResource(volume_type, ret)
    else:
        raise cherrypy.HTTPError(404, "Volume not found")
Beispiel #5
0
    def _create_snapshot(self):
        cherrypy.response.headers['Content-Type'] = 'application/json'
        snapshot_id = str(uuid.uuid4())
        volume_id = cherrypy.request.json['snapshot']['volume_id']
        res = find_volume(volume_id)
        params = dict(volume_id=volume_id, snapshot_id=snapshot_id)

        playcaller.PlayCaller(res.type, 'create_snapshot', params).run()
        cherrypy.response.status = 202  # Accepted
        return json.dumps(
            dict(snapshot=dict(
                status="creating",
                id=snapshot_id,
                volume_id=volume_id,
            )))
Beispiel #6
0
 def _delete_snapshot(self, snapshot_id):
     cherrypy.response.headers['Content-Type'] = 'application/json'
     res = find_snapshot(snapshot_id)
     params = dict(snapshot_id=snapshot_id)
     playcaller.PlayCaller(res.type, 'delete_snapshot', params).run()
     cherrypy.response.status = 202  # Accepted
Beispiel #7
0
 def _terminate_connection(self, volume_id, initiator):
     cherrypy.response.headers['Content-Type'] = 'application/json'
     res = find_volume(volume_id)
     params = dict(volume_id=volume_id, initiator=initiator)
     playcaller.PlayCaller(res.type, 'terminate_connection', params).run()
Beispiel #8
0
 def _delete_volume(self, volume_id):
     cherrypy.response.headers['Content-Type'] = 'application/json'
     res = find_volume(volume_id)
     params = dict(volume_id=volume_id)
     playcaller.PlayCaller(res.type, 'delete_volume', params).run()
     cherrypy.response.status = 202  # Accepted