Example #1
0
    def on_patch(self, request, response, project_id, flavor):
        """Allows one to update a flavors's pool and/or capabilities.

        This method expects the user to submit a JSON object
        containing at least one of: 'pool', 'capabilities'. 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 flavor - name: %s', flavor)
        data = wsgi_utils.load(request)

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

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

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

        try:
            self._ctrl.update(flavor, project=project_id, **fields)
        except errors.FlavorDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
Example #2
0
    def on_put(self, request, response, project_id, flavor):
        """Registers a new flavor. Expects the following input:

        ::

            {"pool_group": "my-pool-group",
              "pool_list": [], "capabilities": {}}

        A capabilities object may also be provided.

        :returns: HTTP | [201, 400]
        """

        LOG.debug(u'PUT flavor - name: %s', flavor)

        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        LOG.debug(u'The pool_group will be removed in Rocky release.')
        pool_group = data.get('pool_group') or data.get('pool')
        pool_list = data.get('pool_list')
        if pool_list is not None:
            self._on_put_by_pool_list(request, response, project_id, flavor,
                                      pool_list)
        else:
            self._on_put_by_group(request, response, project_id, flavor,
                                  pool_group)
Example #3
0
    def on_patch(self, request, response, project_id, flavor):
        """Allows one to update a flavors's pool and/or capabilities.

        This method expects the user to submit a JSON object
        containing at least one of: 'pool', 'capabilities'. 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 flavor - name: %s', flavor)
        data = wsgi_utils.load(request)

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

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

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

        try:
            self._ctrl.update(flavor, project=project_id, **fields)
        except errors.FlavorDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
Example #4
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)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        try:
            self._ctrl.create(pool, weight=data['weight'],
                              uri=data['uri'],
                              group=data.get('group'),
                              options=data.get('options', {}))
            response.status = falcon.HTTP_201
            response.location = request.path
        except errors.PoolCapabilitiesMismatch as e:
            LOG.exception(e)
            title = _(u'Unable to create pool')
            raise falcon.HTTPBadRequest(title, six.text_type(e))
        except errors.PoolAlreadyExists as e:
            LOG.exception(e)
            raise wsgi_errors.HTTPConflict(six.text_type(e))
Example #5
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)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        try:
            self._ctrl.create(pool, weight=data['weight'],
                              uri=data['uri'],
                              group=data.get('group'),
                              options=data.get('options', {}))
            response.status = falcon.HTTP_201
            response.location = request.path
        except errors.PoolCapabilitiesMismatch as e:
            LOG.exception(e)
            title = _(u'Unable to create pool')
            raise falcon.HTTPBadRequest(title, six.text_type(e))
        except errors.PoolAlreadyExists as e:
            LOG.exception(e)
            raise wsgi_errors.HTTPConflict(six.text_type(e))
Example #6
0
    def on_patch(self, request, response, project_id, flavor):
        """Allows one to update a flavors'pool list.

        This method expects the user to submit a JSON object
        containing 'pool list'. If none 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(u'PATCH flavor - name: %s', flavor)
        data = wsgi_utils.load(request)
        field = 'pool_list'
        if field not in data:
            LOG.debug(u'PATCH flavor, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                '`pool_list` needs to be specified'
            )

        wsgi_utils.validate(self._validators[field], data)
        pool_list = data.get('pool_list')
        # NOTE(gengchc2): If pool_list is not None, configuration flavor is
        # used by the new schema.
        # a list of pools is required.
        if pool_list is not None:
            self._on_patch_by_pool_list(request, response, project_id,
                                        flavor, pool_list)
Example #7
0
    def on_put(self, request, response, project_id, flavor):
        """Registers a new flavor. Expects the following input:

        ::

            {"pool": "my-pool", "capabilities": {}}

        A capabilities object may also be provided.

        :returns: HTTP | [201, 400]
        """

        LOG.debug(u'PUT flavor - name: %s', flavor)

        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)

        try:
            self._ctrl.create(flavor,
                              pool=data['pool'],
                              project=project_id)
            response.status = falcon.HTTP_201
            response.location = request.path
        except errors.PoolDoesNotExist as ex:
            LOG.exception(ex)
            description = (_(u'Flavor {flavor} could not be created. '
                             u'Pool {pool} does not exist') %
                           dict(flavor=flavor, pool=data['pool']))
            raise falcon.HTTPBadRequest(_('Unable to create'), description)
Example #8
0
    def on_patch(self, request, response, project_id, flavor):
        """Allows one to update a flavors'pool list.

        This method expects the user to submit a JSON object
        containing 'pool_group' or 'pool list'. If none 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(u'PATCH flavor - name: %s', flavor)
        data = wsgi_utils.load(request)
        # NOTE(gengchc2): remove pool_group in R release.
        EXPECT = ('pool_group', 'pool', 'pool_list')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH flavor, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                '`pool_group` or `pool` or `pool_list` needs to be specified')

        for field in EXPECT:
            wsgi_utils.validate(self._validators[field], data)
        LOG.debug(u'The pool_group will be removed in Rocky release.')
        pool_group = data.get('pool_group') or data.get('pool')
        pool_list = data.get('pool_list')
        # NOTE(gengchc2): If pool_list is not None, configuration flavor is
        # used by the new schema.
        # a list of pools is required.
        if pool_list is not None:
            self._on_patch_by_pool_list(request, response, project_id, flavor,
                                        pool_list)
        else:
            self._on_patch_by_group(request, response, project_id, flavor,
                                    pool_group)
Example #9
0
    def on_patch(self, request, response, project_id, flavor):
        """Allows one to update a flavors'pool list.

        This method expects the user to submit a JSON object
        containing 'pool list'. If none 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(u'PATCH flavor - name: %s', flavor)
        data = wsgi_utils.load(request)
        field = 'pool_list'
        if field not in data:
            LOG.debug(u'PATCH flavor, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                '`pool_list` needs to be specified')

        wsgi_utils.validate(self._validators[field], data)
        pool_list = data.get('pool_list')
        # NOTE(gengchc2): If pool_list is not None, configuration flavor is
        # used by the new schema.
        # a list of pools is required.
        if pool_list is not None:
            self._on_patch_by_pool_list(request, response, project_id, flavor,
                                        pool_list)
Example #10
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)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            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
Example #11
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)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            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
Example #12
0
    def on_put(self, request, response, project_id, flavor):
        """Registers a new flavor. Expects the following input:

        ::

            {"pool": "my-pool", "capabilities": {}}

        A capabilities object may also be provided.

        :returns: HTTP | [201, 400]
        """

        LOG.debug(u'PUT flavor - name: %s', flavor)

        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)

        try:
            self._ctrl.create(flavor,
                              pool=data['pool'],
                              project=project_id,
                              capabilities=data['capabilities'])
            response.status = falcon.HTTP_201
            response.location = request.path
        except errors.PoolDoesNotExist as ex:
            LOG.exception(ex)
            description = (_(u'Flavor %(flavor)s could not be created. '
                             u'Pool %(pool)s does not exist') %
                           dict(flavor=flavor, pool=data['pool']))
            raise falcon.HTTPBadRequest(_('Unable to create'), description)
Example #13
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', 'flavor',
        '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 = wsgi_utils.load(request)

        EXPECT = ('weight', 'uri', 'flavor', '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`, `flavor`,'
                ' or `options` needs '
                'to be specified'
            )

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

        conf = self._ctrl.driver.conf
        if 'uri' in data and not storage_utils.can_connect(data['uri'],
                                                           conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        fields = common_utils.fields(data, EXPECT,
                                     pred=lambda v: v is not None)
        resp_data = None
        try:
            self._ctrl.update(pool, **fields)
            resp_data = self._ctrl.get(pool, False)
        except errors.PoolDoesNotExist as ex:
            LOG.exception('Pool "%s" does not exist', pool)
            raise wsgi_errors.HTTPNotFound(six.text_type(ex))

        resp_data['href'] = request.path
        response.body = transport_utils.to_json(resp_data)
Example #14
0
    def on_patch(self, request, response, project_id, flavor):
        """Allows one to update a flavors's pool_group.

        This method expects the user to submit a JSON object
        containing 'pool_group'. If none 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(u'PATCH flavor - name: %s', flavor)
        data = wsgi_utils.load(request)

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

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

        fields = common_utils.fields(data,
                                     EXPECT,
                                     pred=lambda v: v is not None)
        # NOTE(wanghao): remove this in Newton.
        if fields.get('pool') and fields.get('pool_group') is None:
            fields['pool_group'] = fields.get('pool')
            fields.pop('pool')

        resp_data = None
        try:
            self._ctrl.update(flavor, project=project_id, **fields)
            resp_data = self._ctrl.get(flavor, project=project_id)
            capabilities = self._pools_ctrl.capabilities(
                group=resp_data['pool_group'])
            resp_data['capabilities'] = [
                str(cap).split('.')[-1] for cap in capabilities
            ]
        except errors.FlavorDoesNotExist as ex:
            LOG.exception(ex)
            raise wsgi_errors.HTTPNotFound(six.text_type(ex))
        resp_data['href'] = request.path
        response.body = transport_utils.to_json(resp_data)
Example #15
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', 'group', '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 = wsgi_utils.load(request)

        EXPECT = ('weight', 'uri', 'group', '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`, `group`, or `options` needs '
                'to be specified'
            )

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

        conf = self._ctrl.driver.conf
        if 'uri' in data and not storage_utils.can_connect(data['uri'],
                                                           conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        fields = common_utils.fields(data, EXPECT,
                                     pred=lambda v: v is not None)
        resp_data = None
        try:
            self._ctrl.update(pool, **fields)
            resp_data = self._ctrl.get(pool, False)
        except errors.PoolDoesNotExist as ex:
            LOG.exception(ex)
            raise wsgi_errors.HTTPNotFound(six.text_type(ex))

        resp_data['href'] = request.path
        response.body = transport_utils.to_json(resp_data)
Example #16
0
    def on_patch(self, request, response, project_id, flavor):
        """Allows one to update a flavors's pool_group.

        This method expects the user to submit a JSON object
        containing 'pool_group'. If none 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(u'PATCH flavor - name: %s', flavor)
        data = wsgi_utils.load(request)

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

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

        fields = common_utils.fields(data, EXPECT,
                                     pred=lambda v: v is not None)
        # NOTE(wanghao): remove this in Newton.
        if fields.get('pool') and fields.get('pool_group') is None:
            fields['pool_group'] = fields.get('pool')
            fields.pop('pool')

        resp_data = None
        try:
            self._ctrl.update(flavor, project=project_id, **fields)
            resp_data = self._ctrl.get(flavor, project=project_id)
            capabilities = self._pools_ctrl.capabilities(
                group=resp_data['pool_group'])
            resp_data['capabilities'] = [str(cap).split('.')[-1]
                                         for cap in capabilities]
        except errors.FlavorDoesNotExist as ex:
            LOG.exception(ex)
            raise wsgi_errors.HTTPNotFound(six.text_type(ex))
        resp_data['href'] = request.path
        response.body = transport_utils.to_json(resp_data)
Example #17
0
    def on_put(self, request, response, project_id, flavor):
        """Registers a new flavor. Expects the following input:

        ::

            {"pool_list": [], "capabilities": {}}

        A capabilities object may also be provided.

        :returns: HTTP | [201, 400]
        """

        LOG.debug(u'PUT flavor - name: %s', flavor)

        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        pool_list = data.get('pool_list')
        if pool_list is not None:
            self._on_put_by_pool_list(request, response, project_id, flavor,
                                      pool_list)
Example #18
0
    def on_put(self, request, response, project_id, flavor):
        """Registers a new flavor. Expects the following input:

        ::

            {"pool_list": [], "capabilities": {}}

        A capabilities object may also be provided.

        :returns: HTTP | [201, 400]
        """

        LOG.debug(u'PUT flavor - name: %s', flavor)

        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        pool_list = data.get('pool_list')
        if pool_list is not None:
            self._on_put_by_pool_list(request, response, project_id,
                                      flavor, pool_list)
Example #19
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', 'group', '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 = wsgi_utils.load(request)

        EXPECT = ("weight", "uri", "group", "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`, `group`, or `options` needs " "to be specified"
            )

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

        conf = self._ctrl.driver.conf
        if "uri" in data and not storage_utils.can_connect(data["uri"], conf=conf):
            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()