Esempio n. 1
0
    def on_patch(self, request, response, partition):
        """Allows one to update a partition's weight and/or hosts.

        This method expects the user to submit a JSON object
        containing both or either of 'hosts' and 'weight'. If neither
        is found, the request is flagged as bad. There is also strict
        format checking through the use of jsonschema. Appropriate
        errors are returned in each case for badly formatted input.

        :returns: HTTP | 200,400

        """
        LOG.debug('PATCH partition - name: {0}'.format(partition))
        data = utils.load(request)

        if 'weight' not in data and 'hosts' not in data:
            LOG.debug('PATCH partition, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `hosts` or `weight` needs to be specified')

        utils.validate(self._weight_validator, data)
        utils.validate(self._hosts_validator, data)
        try:
            fields = dict((k, v) for k, v in six.iteritems(data)
                          if k in ('hosts', 'weight') and v is not None)

            self._ctrl.update(partition, **fields)
        except exceptions.PartitionNotFound as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
Esempio n. 2
0
    def on_patch(self, request, response, shard):
        """Allows one to update a shard's weight, location, and/or options.

        This method expects the user to submit a JSON object
        containing atleast one of: 'hosts', 'weight', 'options'. If
        none are found, the request is flagged as bad. There is also
        strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """
        LOG.debug(u'PATCH shard - name: %s', shard)
        data = utils.load(request)

        EXPECT = ('weight', 'location', 'options')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH shard, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `location`, `weight`, or `options` needs '
                'to be specified')

        for field in EXPECT:
            utils.validate(self._validators[field], data)

        try:
            fields = dict((k, v) for k, v in data.items()
                          if k in EXPECT and v is not None)

            self._ctrl.update(shard, **fields)
        except exceptions.ShardDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
Esempio n. 3
0
    def on_patch(self, request, response, partition):
        """Allows one to update a partition's weight and/or hosts.

        This method expects the user to submit a JSON object
        containing both or either of 'hosts' and 'weight'. If neither
        is found, the request is flagged as bad. There is also strict
        format checking through the use of jsonschema. Appropriate
        errors are returned in each case for badly formatted input.

        :returns: HTTP | 200,400

        """
        LOG.debug('PATCH partition - name: {0}'.format(partition))
        data = utils.load(request)

        if 'weight' not in data and 'hosts' not in data:
            LOG.debug('PATCH partition, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `hosts` or `weight` needs to be specified'
            )

        utils.validate(self._weight_validator, data)
        utils.validate(self._hosts_validator, data)
        try:
            fields = dict((k, v) for k, v in six.iteritems(data)
                          if k in ('hosts', 'weight')
                          and v is not None)

            self._ctrl.update(partition, **fields)
        except errors.PartitionNotFound as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
Esempio n. 4
0
    def on_patch(self, request, response, project_id, shard):
        """Allows one to update a shard's weight, uri, and/or options.

        This method expects the user to submit a JSON object
        containing atleast one of: 'uri', 'weight', 'options'. If
        none are found, the request is flagged as bad. There is also
        strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """
        LOG.debug(u'PATCH shard - name: %s', shard)
        data = utils.load(request)

        EXPECT = ('weight', 'uri', 'options')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH shard, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `uri`, `weight`, or `options` needs '
                'to be specified'
            )

        for field in EXPECT:
            utils.validate(self._validators[field], data)

        fields = common_utils.fields(data, EXPECT,
                                     pred=lambda v: v is not None)

        try:
            self._ctrl.update(shard, **fields)
        except errors.ShardDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
Esempio n. 5
0
    def on_put(self, request, response, project_id, shard):
        """Registers a new shard. Expects the following input:

        {"weight": 100, "uri": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """
        LOG.debug(u'PUT shard - name: %s', shard)

        data = utils.load(request)
        utils.validate(self._validators['create'], data)
        self._ctrl.create(shard, weight=data['weight'],
                          uri=data['uri'],
                          options=data.get('options', {}))
        response.status = falcon.HTTP_201
        response.location = request.path
Esempio n. 6
0
    def on_put(self, request, response, partition):
        """Creates a new partition. Expects the following input:

        {"weight": 100, "hosts": [""]}

        :returns: HTTP | [201, 204]
        """
        LOG.debug('PUT partition - name: {0}'.format(partition))
        if self._ctrl.exists(partition):
            LOG.debug('Partition {0} already exists'.format(partition))
            response.status = falcon.HTTP_204
            return

        data = utils.load(request)
        utils.validate(self._put_validator, data)
        self._ctrl.create(partition,
                          weight=data['weight'],
                          hosts=data['hosts'])
        response.status = falcon.HTTP_201
Esempio n. 7
0
    def on_put(self, request, response, partition):
        """Creates a new partition. Expects the following input:

        {"weight": 100, "hosts": [""]}

        :returns: HTTP | [201, 204]
        """
        LOG.debug('PUT partition - name: {0}'.format(partition))
        if self._ctrl.exists(partition):
            LOG.debug('Partition {0} already exists'.format(partition))
            response.status = falcon.HTTP_204
            return

        data = utils.load(request)
        utils.validate(self._put_validator, data)
        self._ctrl.create(partition,
                          weight=data['weight'],
                          hosts=data['hosts'])
        response.status = falcon.HTTP_201
Esempio n. 8
0
    def on_put(self, request, response, project_id, pool):
        """Registers a new pool. Expects the following input:

        {"weight": 100, "uri": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """
        LOG.debug(u'PUT pool - name: %s', pool)

        data = utils.load(request)
        utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri']):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        self._ctrl.create(pool, weight=data['weight'],
                          uri=data['uri'],
                          options=data.get('options', {}))
        response.status = falcon.HTTP_201
        response.location = request.path
Esempio n. 9
0
    def on_put(self, request, response, project_id, pool):
        """Registers a new pool. Expects the following input:

        {"weight": 100, "uri": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """
        LOG.debug(u'PUT pool - name: %s', pool)

        data = utils.load(request)
        utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri']):
            raise wsgi_errors.HTTPBadRequestBody('cannot connect to %s' %
                                                 data['uri'])
        self._ctrl.create(pool,
                          weight=data['weight'],
                          uri=data['uri'],
                          options=data.get('options', {}))
        response.status = falcon.HTTP_201
        response.location = request.path
Esempio n. 10
0
    def on_put(self, request, response, shard):
        """Registers a new shard. Expects the following input:

        {"weight": 100, "location": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """
        LOG.debug(u'PUT shard - name: %s', shard)
        if self._ctrl.exists(shard):
            LOG.debug(u'Shard %s already exists', shard)
            response.status = falcon.HTTP_204
            return

        data = utils.load(request)
        utils.validate(self._validators['create'], data)
        self._ctrl.create(shard,
                          weight=data['weight'],
                          location=data['location'],
                          options=data.get('options', {}))
        response.status = falcon.HTTP_201
        response.location = request.path
Esempio n. 11
0
    def on_patch(self, request, response, project_id, pool):
        """Allows one to update a pool's weight, uri, and/or options.

        This method expects the user to submit a JSON object
        containing at least one of: 'uri', 'weight', 'options'. If
        none are found, the request is flagged as bad. There is also
        strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """
        LOG.debug(u'PATCH pool - name: %s', pool)
        data = utils.load(request)

        EXPECT = ('weight', 'uri', 'options')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH pool, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `uri`, `weight`, or `options` needs '
                'to be specified')

        for field in EXPECT:
            utils.validate(self._validators[field], data)

        if 'uri' in data and not storage_utils.can_connect(data['uri']):
            raise wsgi_errors.HTTPBadRequestBody('cannot connect to %s' %
                                                 data['uri'])
        fields = common_utils.fields(data,
                                     EXPECT,
                                     pred=lambda v: v is not None)

        try:
            self._ctrl.update(pool, **fields)
        except errors.PoolDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()