コード例 #1
0
    def render_GET(self, request):
        # for now only support top-level capabilities
        _, __, fullpath = parse_path(request.path)

        body = get_common_body(request, None, fullpath)
        # is it request for a system-level capability?
        if fullpath == '/cdmi_capabilities':
            body['capabilities'] = capability_objects['system']
            body.update({
                'childrenrange': "0-2",
                'children': [
                    "dataobject/",
                    "container/",
                ]
            })
        elif fullpath.startswith('/cdmi_capabilities/dataobject'):
            body['capabilities'] = capability_objects['dataobject']
        elif fullpath.startswith('/cdmi_capabilities/container'):
            body['capabilities'] = capability_objects['container']

        # construct response
        request.setResponseCode(OK)
        request.setHeader('Content-Type', CDMI_CAPABILITY)
        request.setHeader('X-CDMI-Specification-Version', CDMI_VERSION)
        return json.dumps(body)
コード例 #2
0
ファイル: container.py プロジェクト: livenson/vcdm
    def render_PUT(self, request):
        name, container_path, fullpath = parse_path(request.path)
        log.msg("Creating container %s" % fullpath)
        req_length = request.getHeader("Content-Length")
        if req_length is None:
            request.setResponseCode(411)
            return ""

        req_length = int(req_length)
        request.content.seek(0, 0)
        # process json encoded request body
        body = request.content.read(req_length) if req_length > 0 else "{}"  # a workaround for a buggy curl behavior
        body = json.loads(body)
        metadata = {}
        if "metadata" in body:
            metadata = body["metadata"]
        status, vals = container.create_or_update(self.avatar, name, container_path, fullpath, metadata)
        children = vals["children"].values() if "children" in vals else {}
        request.setResponseCode(status)
        request.setHeader("Content-Type", CDMI_CONTAINER)
        set_common_headers(request)

        # and a body
        response_body = {
            "completionStatus": "Complete",
            "metadata": metadata,
            "children": children,
            "childrenrange": "" if len(children) == 0 else "0-%s" % len(children),
        }
        response_body.update(get_common_body(request, vals["uid"], fullpath))

        return json.dumps(response_body)
コード例 #3
0
ファイル: container.py プロジェクト: livenson/vcdm
    def render_GET(self, request):
        """GET operation corresponds to reading container's data"""
        # parse the request
        _, __, fullpath = parse_path(request.path)

        # contact the backend
        status, vals = container.read(self.avatar, fullpath)

        # create a header
        request.setResponseCode(status)
        request.setHeader("Content-Type", CDMI_CONTAINER)
        set_common_headers(request)

        # and a body
        if status == OK:
            request.setLastModified(float(vals["mtime"]))
            children = vals["children"].values()
            response_body = {
                "completionStatus": "Complete",
                "metadata": vals["metadata"],
                "children": children,
                "childrenrange": "" if len(children) == 0 else "0-%s" % len(children),
                "capabilitiesURI": "/cdmi_capabilities/container",
            }
            response_body.update(get_common_body(request, vals["uid"], fullpath))
            return json.dumps(response_body)
        else:
            return ""
コード例 #4
0
ファイル: capabilities.py プロジェクト: almaram/vcdm
    def render_GET(self, request):
        # for now only support top-level capabilities
        _, __, fullpath = parse_path(request.path)

        body = get_common_body(request, None, fullpath)
        # is it request for a system-level capability?
        if fullpath == '/cdmi_capabilities':
            body['capabilities'] = capability_objects['system']
            body.update({
                    'childrenrange': "0-2",
                    'children': [
                            "dataobject/",
                            "container/",
                        ]
                })
        elif fullpath.startswith('/cdmi_capabilities/dataobject'):
            body['capabilities'] = capability_objects['dataobject']
        elif fullpath.startswith('/cdmi_capabilities/container'):
            body['capabilities'] = capability_objects['container']

        # construct response
        request.setResponseCode(OK)
        request.setHeader('Content-Type', CDMI_CAPABILITY)
        request.setHeader('X-CDMI-Specification-Version', CDMI_VERSION)
        return json.dumps(body)
コード例 #5
0
    def render_GET(self, request, bodyless=False):
        """GET operation corresponds to reading of the blob object"""
        # process path and extract potential containers/fnm
        _, __, fullpath = parse_path(request.path)

        tre_header = request.getHeader('tre-enabled')
        tre_request = tre_header is not None and tre_header.lower() == 'true'
        log.msg("Request for TRE-enabled download received.")
        # perform operation on ADT
        status, vals = blob.read(self.avatar, fullpath, tre_request)
        # construct response
        request.setResponseCode(status)

        request.setHeader('Content-Type', CDMI_OBJECT)
        if tre_request and status == FOUND:
            request.setHeader('Location', "/".join([c('general', 'tre_server'),
                                                    str(vals['uid'])]))
            request.setLastModified(float(vals['mtime']))

        set_common_headers(request)
        if status == OK:
            request.setLastModified(float(vals['mtime']))
            if not bodyless:
                valueencoding = vals['valuetransferencoding']
                # for content we want to read in the full object into memory
                content = (vals['content'].read() if valueencoding == 'utf-8' else
                          base64.b64encode(vals['content'].read()))

                # construct body
                response_body = {
                                 'completionStatus': 'Complete',
                                 'mimetype': vals['mimetype'],
                                 'metadata': vals['metadata'],
                                 'valuetransferencoding': valueencoding,
                                 'value': content,
                                 'actual_uri': vals.get('actual_uri'),
                                 'capabilitiesURI': '/cdmi_capabilities/dataobject'
                                 }
                response_body.update(get_common_body(request, str(vals['uid']),
                                                     fullpath))
                return json.dumps(response_body)
        return ''
コード例 #6
0
    def render_PUT(self, request):
        """PUT corresponds to a create/update operation on a blob"""
        # process path and extract potential containers/fnm
        name, container_path, fullpath = parse_path(request.path)

        length = int(request.getHeader('Content-Length'))
        request.content.seek(0, 0)
        # process json encoded request body
        body = json.loads(request.content.read(length))
        # default values of mimetype and metadata
        mimetype = body.get('mimetype', 'text/plain')
        metadata = body.get('metadata', {})
        desired_backend = (metadata.get('desired_backend') or
                           request.getHeader('desired_backend'))
        valueencoding = body.get('valuetransferencoding', 'utf-8')
        body_value = body.get('value', '')
        value = (body_value if valueencoding == 'utf-8' else
                                  base64.b64decode(body_value))
        content = (StringIO(value), len(value))
        status, uid = blob.write(self.avatar, name, container_path, fullpath,
                                 mimetype, metadata, content, valueencoding,
                                 desired_backend=desired_backend)
        request.setResponseCode(status)
        request.setHeader('Content-Type', CDMI_OBJECT)
        set_common_headers(request)
        if status == OK or status == CREATED:
            response_body = {
                             'completionStatus': 'Complete',
                             'mimetype': mimetype,
                             'metadata': metadata,
                             }
            # add common elements
            response_body.update(get_common_body(request, uid, fullpath))
            return json.dumps(response_body)
        else:
            # error state
            return ''