Ejemplo n.º 1
0
 def test_parse_bool(self):
     name = 'param'
     for value in ('True', 'true', 'TRUE', True):
         self.assertTrue(util.parse_bool_param(name, value))
     for value in ('False', 'false', 'FALSE', False):
         self.assertFalse(util.parse_bool_param(name, value))
     for value in ('foo', 't', 'f', 'yes', 'no', 'y', 'n', '1', '0', None):
         self.assertRaises(exc.HTTPBadRequest, util.parse_bool_param, name,
                           value)
Ejemplo n.º 2
0
    def index(self, req):
        whitelist = {
            consts.EVENT_OBJ_NAME: 'mixed',
            consts.EVENT_OBJ_TYPE: 'mixed',
            consts.EVENT_OBJ_ID: 'mixed',
            consts.EVENT_CLUSTER_ID: 'mixed',
            consts.EVENT_ACTION: 'mixed',
            consts.EVENT_LEVEL: 'mixed',
            consts.PARAM_LIMIT: 'single',
            consts.PARAM_MARKER: 'single',
            consts.PARAM_SORT: 'single',
            consts.PARAM_GLOBAL_PROJECT: 'single',
        }

        for key in req.params.keys():
            if key not in whitelist.keys():
                raise exc.HTTPBadRequest(_('Invalid parameter %s') % key)
        params = util.get_allowed_params(req.params, whitelist)

        project_safe = not util.parse_bool_param(
            consts.PARAM_GLOBAL_PROJECT,
            params.pop(consts.PARAM_GLOBAL_PROJECT, False))
        params['project_safe'] = project_safe

        obj = util.parse_request('EventListRequest', req, params)
        events = self.rpc_client.call2(req.context, "event_list2", obj)

        return {'events': events}
Ejemplo n.º 3
0
    def index(self, req):
        whitelist = {
            consts.NODE_CLUSTER_ID: 'single',
            consts.NODE_NAME: 'mixed',
            consts.NODE_STATUS: 'mixed',
            consts.PARAM_LIMIT: 'single',
            consts.PARAM_MARKER: 'single',
            consts.PARAM_SORT: 'single',
            consts.PARAM_GLOBAL_PROJECT: 'single'
        }
        for key in req.params.keys():
            if key not in whitelist.keys():
                raise exc.HTTPBadRequest(_('Invalid parameter %s') % key)
        params = util.get_allowed_params(req.params, whitelist)

        project_safe = not util.parse_bool_param(
            consts.PARAM_GLOBAL_PROJECT,
            params.pop(consts.PARAM_GLOBAL_PROJECT, False))
        params['project_safe'] = project_safe

        obj = util.parse_request('NodeListRequest', req, params)
        nodes = self.rpc_client.call(req.context, 'node_list', obj)

        nodes = [self._remove_tainted(req, n) for n in nodes]
        return {'nodes': nodes}
Ejemplo n.º 4
0
    def index(self, req):
        whitelist = {
            consts.RECEIVER_NAME: 'mixed',
            consts.RECEIVER_TYPE: 'mixed',
            consts.RECEIVER_CLUSTER_ID: 'mixed',
            consts.RECEIVER_USER_ID: 'mixed',
            consts.RECEIVER_ACTION: 'mixed',
            consts.PARAM_LIMIT: 'single',
            consts.PARAM_MARKER: 'single',
            consts.PARAM_SORT: 'single',
            consts.PARAM_GLOBAL_PROJECT: 'single',
        }
        for key in req.params.keys():
            if key not in whitelist.keys():
                raise exc.HTTPBadRequest(_('Invalid parameter %s') % key)

        params = util.get_allowed_params(req.params, whitelist)

        project_safe = not util.parse_bool_param(
            consts.PARAM_GLOBAL_PROJECT,
            params.pop(consts.PARAM_GLOBAL_PROJECT, False))
        params['project_safe'] = project_safe

        obj = util.parse_request('ReceiverListRequest', req, params)
        receivers = self.rpc_client.call(req.context, 'receiver_list', obj)

        return {'receivers': receivers}
Ejemplo n.º 5
0
    def index(self, req):
        whitelist = {
            consts.ACTION_NAME: 'mixed',
            consts.ACTION_TARGET: 'mixed',
            consts.ACTION_ACTION: 'mixed',
            consts.ACTION_STATUS: 'mixed',
            consts.PARAM_LIMIT: 'single',
            consts.PARAM_MARKER: 'single',
            consts.PARAM_SORT: 'single',
            consts.PARAM_GLOBAL_PROJECT: 'single',
        }
        for key in req.params.keys():
            if key not in whitelist.keys():
                raise exc.HTTPBadRequest(_('Invalid parameter %s') % key)
        params = util.get_allowed_params(req.params, whitelist)

        project_safe = not util.parse_bool_param(
            consts.PARAM_GLOBAL_PROJECT,
            params.pop(consts.PARAM_GLOBAL_PROJECT, False))
        params['project_safe'] = project_safe

        obj = util.parse_request('ActionListRequest', req, params)
        actions = self.rpc_client.call(req.context, "action_list", obj)

        return {'actions': actions}
Ejemplo n.º 6
0
    def get(self, req, node_id):
        params = {'identity': node_id}
        key = consts.PARAM_SHOW_DETAILS
        if key in req.params:
            params['show_details'] = util.parse_bool_param(
                key, req.params[key])

        obj = util.parse_request('NodeGetRequest', req, params)
        node = self.rpc_client.call(req.context, 'node_get', obj)
        return {'node': node}
Ejemplo n.º 7
0
    def delete(self, req, node_id, body=None):
        if body:
            force = body.get('force')
        else:
            force = False

        if force is not None:
            force = util.parse_bool_param(consts.NODE_DELETE_FORCE, force)

        params = {'identity': node_id, 'force': force}

        obj = util.parse_request('NodeDeleteRequest', req, params)
        res = self.rpc_client.call(req.context, 'node_delete', obj)
        action_id = res.pop('action')
        result = {'location': '/actions/%s' % action_id}
        return result
Ejemplo n.º 8
0
    def delete(self, req, cluster_id, body=None):
        if req.params.get('force') is not None:
            force = util.parse_bool_param(consts.CLUSTER_DELETE_FORCE,
                                          req.params.get('force'))
        elif body:
            force = body.get('force')
            if force is None:
                force = False
        else:
            force = False

        params = {'identity': cluster_id, 'force': force}
        obj = util.parse_request('ClusterDeleteRequest', req, params)
        res = self.rpc_client.call(req.context, 'cluster_delete', obj)

        action_id = res.pop('action')
        result = {'location': '/actions/%s' % action_id}
        return result
Ejemplo n.º 9
0
    def index(self, req):
        whitelist = {
            consts.POLICY_NAME: 'mixed',
            consts.POLICY_TYPE: 'mixed',
            consts.PARAM_LIMIT: 'single',
            consts.PARAM_MARKER: 'single',
            consts.PARAM_SORT: 'single',
            consts.PARAM_GLOBAL_PROJECT: 'single',
        }
        for key in req.params.keys():
            if key not in whitelist:
                raise exc.HTTPBadRequest(_('Invalid parameter %s') % key)

        params = util.get_allowed_params(req.params, whitelist)
        is_global = params.pop(consts.PARAM_GLOBAL_PROJECT, False)

        unsafe = util.parse_bool_param(consts.PARAM_GLOBAL_PROJECT, is_global)
        params['project_safe'] = not unsafe
        obj = util.parse_request('PolicyListRequest', req, params)
        policies = self.rpc_client.call2(req.context, 'policy_list2', obj)
        return {'policies': policies}
Ejemplo n.º 10
0
    def update(self, req, action_id, body):
        data = body.get('action')
        if data is None:
            raise exc.HTTPBadRequest(
                _("Malformed request data, missing "
                  "'action' key in request body."))
        force_update = req.params.get('force')

        if force_update is not None:
            force = util.parse_bool_param(consts.ACTION_UPDATE_FORCE,
                                          force_update)
        else:
            force = False

        data['force'] = force
        data['identity'] = action_id

        obj = util.parse_request('ActionUpdateRequest', req, data)
        self.rpc_client.call(req.context, 'action_update', obj)

        raise exc.HTTPAccepted
Ejemplo n.º 11
0
    def index(self, req):
        whitelist = {
            consts.CLUSTER_NAME: 'mixed',
            consts.CLUSTER_STATUS: 'mixed',
            consts.PARAM_LIMIT: 'single',
            consts.PARAM_MARKER: 'single',
            consts.PARAM_SORT: 'single',
            consts.PARAM_GLOBAL_PROJECT: 'single',
        }
        for key in req.params.keys():
            if key not in whitelist:
                raise exc.HTTPBadRequest(_("Invalid parameter '%s'") % key)

        params = util.get_allowed_params(req.params, whitelist)
        # Note: We have to do a boolean parsing here because 1) there is
        # a renaming, 2) the boolean is usually presented as a string.
        is_global = params.pop(consts.PARAM_GLOBAL_PROJECT, False)
        unsafe = util.parse_bool_param(consts.PARAM_GLOBAL_PROJECT, is_global)
        params['project_safe'] = not unsafe
        req_obj = util.parse_request('ClusterListRequest', req, params)
        clusters = self.rpc_client.call(req.context, 'cluster_list', req_obj)
        return {'clusters': clusters}
Ejemplo n.º 12
0
    def index(self, req, cluster_id):
        param_whitelist = {
            consts.CP_ENABLED: 'single',
            consts.CP_POLICY_NAME: 'single',
            consts.CP_POLICY_TYPE: 'single',
            consts.PARAM_SORT: 'single',
        }
        for key in req.params.keys():
            if (key not in param_whitelist.keys()):
                raise exc.HTTPBadRequest(_('Invalid parameter %s') % key)

        params = util.get_allowed_params(req.params, param_whitelist)
        key = consts.CP_ENABLED
        if key in params:
            params[key] = util.parse_bool_param(key, params[key])
        params['identity'] = cluster_id

        obj = util.parse_request('ClusterPolicyListRequest', req, params)
        policies = self.rpc_client.call2(req.context, 'cluster_policy_list2',
                                         obj)

        return {'cluster_policies': policies}
Ejemplo n.º 13
0
    def index(self, req):
        whitelist = {
            consts.PROFILE_NAME: 'mixed',
            consts.PROFILE_TYPE: 'mixed',
            consts.PARAM_LIMIT: 'single',
            consts.PARAM_MARKER: 'single',
            consts.PARAM_SORT: 'single',
            consts.PARAM_GLOBAL_PROJECT: 'single',
        }
        for key in req.params.keys():
            if key not in whitelist.keys():
                raise exc.HTTPBadRequest(_('Invalid parameter %s') % key)

        params = util.get_allowed_params(req.params, whitelist)

        project_safe = not util.parse_bool_param(
            consts.PARAM_GLOBAL_PROJECT,
            params.pop(consts.PARAM_GLOBAL_PROJECT, False))
        params['project_safe'] = project_safe

        obj = util.parse_request('ProfileListRequest', req, params)
        profiles = self.rpc_client.call(req.context, 'profile_list', obj)
        return {'profiles': profiles}