示例#1
0
    def _sof_container_update(self, request, resp):
        """
        SOF specific metadata is set in DiskFile.open()._filter_metadata()
        This method internally invokes Swift's container_update() method.
        """
        device, partition, account, container, obj, policy_idx = \
            get_name_and_placement(request, 5, 5, True)

        # The container_update() method requires certain container
        # specific headers. The proxy object controller appends these
        # headers for PUT backend request but not for HEAD/GET requests.
        # Thus, we populate the required information in request
        # and then invoke container_update()
        container_partition, container_nodes = \
            self.get_container_ring().get_nodes(account, container)
        request.headers['X-Container-Partition'] = container_partition
        for node in container_nodes:
            request.headers['X-Container-Host'] = csv_append(
                request.headers.get('X-Container-Host'),
                '%(ip)s:%(port)s' % node)
            request.headers['X-Container-Device'] = csv_append(
                request.headers.get('X-Container-Device'), node['device'])

        self.container_update(
            'PUT', account, container, obj, request,
            HeaderKeyDict({
                'x-size': resp.headers['Content-Length'],
                'x-content-type': resp.headers['Content-Type'],
                'x-timestamp': resp.headers['X-Timestamp'],
                'x-etag': resp.headers['ETag']}),
            device, policy_idx)
示例#2
0
文件: obj.py 项目: saebyuk/swift
    def _backend_requests(self, req, n_outgoing,
                          container_partition, containers,
                          delete_at_partition=None, delete_at_nodes=None):
        headers = [dict(req.headers.iteritems())
                   for _junk in range(n_outgoing)]

        for header in headers:
            header['Connection'] = 'close'

        for i, container in enumerate(containers):
            i = i % len(headers)

            headers[i]['X-Container-Partition'] = container_partition
            headers[i]['X-Container-Host'] = csv_append(
                headers[i].get('X-Container-Host'),
                '%(ip)s:%(port)s' % container)
            headers[i]['X-Container-Device'] = csv_append(
                headers[i].get('X-Container-Device'),
                container['device'])

        for i, node in enumerate(delete_at_nodes or []):
            i = i % len(headers)

            headers[i]['X-Delete-At-Partition'] = delete_at_partition
            headers[i]['X-Delete-At-Host'] = csv_append(
                headers[i].get('X-Delete-At-Host'),
                '%(ip)s:%(port)s' % node)
            headers[i]['X-Delete-At-Device'] = csv_append(
                headers[i].get('X-Delete-At-Device'),
                node['device'])

        return headers
示例#3
0
    def _backend_requests(self,
                          req,
                          n_outgoing,
                          account_partition,
                          accounts,
                          policy_index=None):
        additional = {'X-Timestamp': Timestamp.now().internal}
        if policy_index is None:
            additional['X-Backend-Storage-Policy-Default'] = \
                int(POLICIES.default)
        else:
            additional['X-Backend-Storage-Policy-Index'] = str(policy_index)
        headers = [
            self.generate_request_headers(req,
                                          transfer=True,
                                          additional=additional)
            for _junk in range(n_outgoing)
        ]

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]['X-Account-Partition'] = account_partition
            headers[i]['X-Account-Host'] = csv_append(
                headers[i].get('X-Account-Host'), '%(ip)s:%(port)s' % account)
            headers[i]['X-Account-Device'] = csv_append(
                headers[i].get('X-Account-Device'), account['device'])

        return headers
示例#4
0
文件: obj.py 项目: dpgoetz/swift
    def _backend_requests(self, req, n_outgoing,
                          container_partition, containers,
                          delete_at_container=None, delete_at_partition=None,
                          delete_at_nodes=None):
        headers = [self.generate_request_headers(req, additional=req.headers)
                   for _junk in range(n_outgoing)]

        for i, container in enumerate(containers):
            i = i % len(headers)

            headers[i]['X-Container-Partition'] = container_partition
            headers[i]['X-Container-Host'] = csv_append(
                headers[i].get('X-Container-Host'),
                '%(ip)s:%(port)s' % container)
            headers[i]['X-Container-Device'] = csv_append(
                headers[i].get('X-Container-Device'),
                container['device'])

        for i, node in enumerate(delete_at_nodes or []):
            i = i % len(headers)

            headers[i]['X-Delete-At-Container'] = delete_at_container
            headers[i]['X-Delete-At-Partition'] = delete_at_partition
            headers[i]['X-Delete-At-Host'] = csv_append(
                headers[i].get('X-Delete-At-Host'),
                '%(ip)s:%(port)s' % node)
            headers[i]['X-Delete-At-Device'] = csv_append(
                headers[i].get('X-Delete-At-Device'),
                node['device'])

        return headers
示例#5
0
    def _backend_requests(
        self,
        req,
        n_outgoing,
        container_partition,
        containers,
        delete_at_container=None,
        delete_at_partition=None,
        delete_at_nodes=None,
    ):
        headers = [self.generate_request_headers(req, additional=req.headers) for _junk in range(n_outgoing)]

        for header in headers:
            header["Connection"] = "close"

        for i, container in enumerate(containers):
            i = i % len(headers)

            headers[i]["X-Container-Partition"] = container_partition
            headers[i]["X-Container-Host"] = csv_append(
                headers[i].get("X-Container-Host"), "%(ip)s:%(port)s" % container
            )
            headers[i]["X-Container-Device"] = csv_append(headers[i].get("X-Container-Device"), container["device"])

        for i, node in enumerate(delete_at_nodes or []):
            i = i % len(headers)

            headers[i]["X-Delete-At-Container"] = delete_at_container
            headers[i]["X-Delete-At-Partition"] = delete_at_partition
            headers[i]["X-Delete-At-Host"] = csv_append(headers[i].get("X-Delete-At-Host"), "%(ip)s:%(port)s" % node)
            headers[i]["X-Delete-At-Device"] = csv_append(headers[i].get("X-Delete-At-Device"), node["device"])

        return headers
示例#6
0
    def _backend_requests(self, req, n_outgoing,
                          container_partition, containers,
                          delete_at_container=None, delete_at_partition=None,
                          delete_at_nodes=None):
        headers = [self.generate_request_headers(req, additional=req.headers)
                   for _junk in range(n_outgoing)]

        for header in headers:
            header['Connection'] = 'close'

        for i, container in enumerate(containers):
            i = i % len(headers)

            headers[i]['X-Container-Partition'] = container_partition
            headers[i]['X-Container-Host'] = csv_append(
                headers[i].get('X-Container-Host'),
                '%(ip)s:%(port)s' % container)
            headers[i]['X-Container-Device'] = csv_append(
                headers[i].get('X-Container-Device'),
                container['device'])

        for i, node in enumerate(delete_at_nodes or []):
            i = i % len(headers)

            headers[i]['X-Delete-At-Container'] = delete_at_container
            headers[i]['X-Delete-At-Partition'] = delete_at_partition
            headers[i]['X-Delete-At-Host'] = csv_append(
                headers[i].get('X-Delete-At-Host'),
                '%(ip)s:%(port)s' % node)
            headers[i]['X-Delete-At-Device'] = csv_append(
                headers[i].get('X-Delete-At-Device'),
                node['device'])

        return headers
示例#7
0
    def _backend_requests(self, req, n_outgoing, account_partition, accounts):
        headers = [self.generate_request_headers(req, transfer=True) for _junk in range(n_outgoing)]

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]["X-Account-Partition"] = account_partition
            headers[i]["X-Account-Host"] = csv_append(headers[i].get("X-Account-Host"), "%(ip)s:%(port)s" % account)
            headers[i]["X-Account-Device"] = csv_append(headers[i].get("X-Account-Device"), account["device"])

        return headers
示例#8
0
    def _backend_requests(self, req, n_outgoing, account_partition, accounts):
        headers = [
            self.generate_request_headers(req, transfer=True)
            for _junk in range(n_outgoing)
        ]

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]['X-Account-Partition'] = account_partition
            headers[i]['X-Account-Host'] = csv_append(
                headers[i].get('X-Account-Host'), '%(ip)s:%(port)s' % account)
            headers[i]['X-Account-Device'] = csv_append(
                headers[i].get('X-Account-Device'), account['device'])

        return headers
示例#9
0
    def _backend_requests(self, req, n_outgoing, account_partition, accounts, policy_index=None):
        additional = {"X-Timestamp": Timestamp(time.time()).internal}
        if policy_index is None:
            additional["X-Backend-Storage-Policy-Default"] = int(POLICIES.default)
        else:
            additional["X-Backend-Storage-Policy-Index"] = str(policy_index)
        headers = [
            self.generate_request_headers(req, transfer=True, additional=additional) for _junk in range(n_outgoing)
        ]

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]["X-Account-Partition"] = account_partition
            headers[i]["X-Account-Host"] = csv_append(headers[i].get("X-Account-Host"), "%(ip)s:%(port)s" % account)
            headers[i]["X-Account-Device"] = csv_append(headers[i].get("X-Account-Device"), account["device"])

        return headers
示例#10
0
    def _backend_requests(self, req, n_outgoing,
                          account_partition, accounts):
        additional = {'X-Timestamp': normalize_timestamp(time.time())}
        headers = [self.generate_request_headers(req, transfer=True,
                                                 additional=additional)
                   for _junk in range(n_outgoing)]

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]['X-Account-Partition'] = account_partition
            headers[i]['X-Account-Host'] = csv_append(
                headers[i].get('X-Account-Host'),
                '%(ip)s:%(port)s' % account)
            headers[i]['X-Account-Device'] = csv_append(
                headers[i].get('X-Account-Device'),
                account['device'])

        return headers
示例#11
0
    def _backend_requests(self, req, n_outgoing, account_partition, accounts):
        headers = [{
            'Connection': 'close',
            'X-Timestamp': normalize_timestamp(time.time()),
            'x-trans-id': self.trans_id
        } for _junk in range(n_outgoing)]

        for header in headers:
            self.transfer_headers(req.headers, header)

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]['X-Account-Partition'] = account_partition
            headers[i]['X-Account-Host'] = csv_append(
                headers[i].get('X-Account-Host'), '%(ip)s:%(port)s' % account)
            headers[i]['X-Account-Device'] = csv_append(
                headers[i].get('X-Account-Device'), account['device'])

        return headers
示例#12
0
    def _backend_requests(self, req, n_outgoing, account_partition, accounts,
                          policy_index=None):
        additional = {'X-Timestamp': normalize_timestamp(time.time())}
        if policy_index is not None:
            additional[POLICY_INDEX] = str(policy_index)
        headers = [self.generate_request_headers(req, transfer=True,
                                                 additional=additional)
                   for _junk in range(n_outgoing)]

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]['X-Account-Partition'] = account_partition
            headers[i]['X-Account-Host'] = csv_append(
                headers[i].get('X-Account-Host'),
                '%(ip)s:%(port)s' % account)
            headers[i]['X-Account-Device'] = csv_append(
                headers[i].get('X-Account-Device'),
                account['device'])

        return headers
示例#13
0
    def _backend_requests(self, req, n_outgoing,
                          account_partition, accounts):
        headers = [{'Connection': 'close',
                    'X-Timestamp': normalize_timestamp(time.time()),
                    'x-trans-id': self.trans_id}
                   for _junk in range(n_outgoing)]

        for header in headers:
            self.transfer_headers(req.headers, header)

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]['X-Account-Partition'] = account_partition
            headers[i]['X-Account-Host'] = csv_append(
                headers[i].get('X-Account-Host'),
                '%(ip)s:%(port)s' % account)
            headers[i]['X-Account-Device'] = csv_append(
                headers[i].get('X-Account-Device'),
                account['device'])

        return headers
示例#14
0
    def _backend_requests(self, req, n_outgoing, account_partition, accounts,
                          policy_index=None):
        additional = {'X-Timestamp': Timestamp.now().internal}
        if policy_index is None:
            additional['X-Backend-Storage-Policy-Default'] = \
                int(POLICIES.default)
        else:
            additional['X-Backend-Storage-Policy-Index'] = str(policy_index)
        headers = [self.generate_request_headers(req, transfer=True,
                                                 additional=additional)
                   for _junk in range(n_outgoing)]

        for i, account in enumerate(accounts):
            i = i % len(headers)

            headers[i]['X-Account-Partition'] = account_partition
            headers[i]['X-Account-Host'] = csv_append(
                headers[i].get('X-Account-Host'),
                '%(ip)s:%(port)s' % account)
            headers[i]['X-Account-Device'] = csv_append(
                headers[i].get('X-Account-Device'),
                account['device'])

        return headers
示例#15
0
def update_ignore_range_header(req, name):
    """
    Helper function to update an X-Backend-Ignore-Range-If-Metadata-Present
    header whose value is a list of header names which, if any are present
    on an object, mean the object server should respond with a 200 instead
    of a 206 or 416.

    :param req: a swob Request
    :param name: name of a header which, if found, indicates the proxy will
                 want the whole object
    """
    if ',' in name:
        # HTTP header names should not have commas but we'll check anyway
        raise ValueError('Header name must not contain commas')
    hdr = 'X-Backend-Ignore-Range-If-Metadata-Present'
    req.headers[hdr] = csv_append(req.headers.get(hdr), name)
示例#16
0
def update_etag_is_at_header(req, name):
    """
    Helper function to update an X-Backend-Etag-Is-At header whose value is a
    list of alternative header names at which the actual object etag may be
    found. This informs the object server where to look for the actual object
    etag when processing conditional requests.

    Since the proxy server and/or middleware may set alternative etag header
    names, the value of X-Backend-Etag-Is-At is a comma separated list which
    the object server inspects in order until it finds an etag value.

    :param req: a swob Request
    :param name: name of a sysmeta where alternative etag may be found
    """
    if ',' in name:
        # HTTP header names should not have commas but we'll check anyway
        raise ValueError('Header name must not contain commas')
    existing = req.headers.get("X-Backend-Etag-Is-At")
    req.headers["X-Backend-Etag-Is-At"] = csv_append(existing, name)
示例#17
0
def update_etag_is_at_header(req, name):
    """
    Helper function to update an X-Backend-Etag-Is-At header whose value is a
    list of alternative header names at which the actual object etag may be
    found. This informs the object server where to look for the actual object
    etag when processing conditional requests.

    Since the proxy server and/or middleware may set alternative etag header
    names, the value of X-Backend-Etag-Is-At is a comma separated list which
    the object server inspects in order until it finds an etag value.

    :param req: a swob Request
    :param name: name of a sysmeta where alternative etag may be found
    """
    if "," in name:
        # HTTP header names should not have commas but we'll check anyway
        raise ValueError("Header name must not contain commas")
    existing = req.headers.get("X-Backend-Etag-Is-At")
    req.headers["X-Backend-Etag-Is-At"] = csv_append(existing, name)