Ejemplo n.º 1
0
    def index(self, req):
        """List summary information for all policies"""
        filter_whitelist = {
            'name': 'mixed',
            'metadata': 'mixed',
        }
        param_whitelist = {
            'limit': 'single',
            'marker': 'single',
            'sort_dir': 'single',
            'sort_keys': 'multi',
            'show_deleted': 'single',
        }
        params = util.get_allowed_params(req.params, param_whitelist)
        filters = util.get_allowed_params(req.params, filter_whitelist)

        key = consts.PARAM_LIMIT
        if key in params:
            params[key] = utils.parse_int_param(key, params[key])

        key = consts.PARAM_SHOW_DELETED
        if key in params:
            params[key] = utils.parse_bool_param(key, params[key])

        if not filters:
            filters = None

        policies = self.rpc_client.policy_list(req.context,
                                               filters=filters,
                                               **params)

        return {'policies': policies}
Ejemplo n.º 2
0
    def index(self, req):
        filter_whitelist = {
            'status': 'mixed',
        }
        param_whitelist = {
            'limit': 'single',
            'marker': 'single',
            'sort_dir': 'single',
            'sort_keys': 'multi',
            'show_deleted': 'single',
        }
        params = util.get_allowed_params(req.params, param_whitelist)
        filters = util.get_allowed_params(req.params, filter_whitelist)

        key = consts.PARAM_LIMIT
        if key in params:
            params[key] = utils.parse_int_param(key, params[key])

        key = consts.PARAM_SHOW_DELETED
        if key in params:
            params[key] = utils.parse_bool_param(key, params[key])

        if not filters:
            filters = None

        users = self.rpc_client.user_list(req.context,
                                          filters=filters,
                                          **params)

        return {'users': users}
Ejemplo n.º 3
0
    def policy_update(self, cnxt, policy_id, name=None, metadata=None,
                      is_default=None):
        LOG.info(_LI("Updating policy: '%(id)s'"), {'id': policy_id})

        policy = policy_mod.Policy.load(cnxt, policy_id=policy_id)
        changed = False
        if name is not None and name != policy.name:
            policies = policy_mod.Policy.load_all(cnxt, filters={'name': name})
            if len(policies) > 0:
                msg = _("The policy (%(name)s) already exists."
                        ) % {"name": name}
                raise exception.BileanBadRequest(msg=msg)
            policy.name = name
            changed = True
        if metadata is not None and metadata != policy.metadata:
            policy.metadata = metadata
            changed = True
        if is_default is not None and is_default != policy.is_default:
            is_default = utils.parse_bool_param('is_default', is_default)
            if is_default:
                # Set policy to default should unset old default policy.
                policies = policy_mod.load_all(cnxt,
                                               filters={'is_default': True})
                if len(policies) == 1:
                    default_policy = policies[0]
                    default_policy.is_default = False
                    default_policy.store(cnxt)
            policy.is_default = is_default
            changed = True

        if changed:
            policy.store(cnxt)

        LOG.info(_LI("Policy '%(id)s' is updated."), {'id': policy_id})
        return policy.to_dict()
Ejemplo n.º 4
0
    def index(self, req):
        """Lists summary information for all resources"""
        filter_whitelist = {
            'resource_type': 'mixed',
            'rule_id': 'mixed',
        }
        param_whitelist = {
            'user_id': 'single',
            'limit': 'single',
            'marker': 'single',
            'sort_dir': 'single',
            'sort_keys': 'multi',
            'show_deleted': 'single',
        }
        params = util.get_allowed_params(req.params, param_whitelist)
        filters = util.get_allowed_params(req.params, filter_whitelist)

        key = consts.PARAM_LIMIT
        if key in params:
            params[key] = utils.parse_int_param(key, params[key])

        key = consts.PARAM_SHOW_DELETED
        if key in params:
            params[key] = utils.parse_bool_param(key, params[key])

        if not filters:
            filters = None
        resources = self.rpc_client.resource_list(req.context, filters=filters,
                                                  **params)

        return {'resources': resources}
Ejemplo n.º 5
0
    def index(self, req, tenant_id):
        """Lists summary information for all events"""
        filter_whitelist = {
            'resource_type': 'mixed',
            'action': 'single',
        }
        param_whitelist = {
            'user_id': 'single',
            'start_time': 'single',
            'end_time': 'single',
            'limit': 'single',
            'marker': 'single',
            'sort_dir': 'single',
            'sort_keys': 'multi',
            'show_deleted': 'single',
        }
        params = util.get_allowed_params(req.params, param_whitelist)
        filters = util.get_allowed_params(req.params, filter_whitelist)

        key = consts.PARAM_LIMIT
        if key in params:
            params[key] = utils.parse_int_param(key, params[key])

        key = consts.PARAM_SHOW_DELETED
        if key in params:
            params[key] = utils.parse_bool_param(key, params[key])

        if not filters:
            filters = None

        events = self.rpc_client.event_list(req.context,
                                            filters=filters,
                                            **params)
        return {'events': events}
Ejemplo n.º 6
0
    def statistics(self, req):
        '''Consumptions statistics.'''
        filter_whitelist = {
            'resource_type': 'mixed',
        }
        param_whitelist = {
            'user_id': 'single',
            'start_time': 'single',
            'end_time': 'single',
            'summary': 'single',
        }
        params = util.get_allowed_params(req.params, param_whitelist)
        filters = util.get_allowed_params(req.params, filter_whitelist)

        key = consts.PARAM_SUMMARY
        if key in params:
            params[key] = utils.parse_bool_param(key, params[key])

        if not filters:
            filters = None
        statistics = self.rpc_client.consumption_statistics(req.context,
                                                            filters=filters,
                                                            **params)

        return {'statistics': statistics}
Ejemplo n.º 7
0
    def policy_update(self, cnxt, policy_id, name=None, metadata=None,
                      is_default=None):
        LOG.info(_LI("Updating policy: '%(id)s'"), {'id': policy_id})

        policy = policy_mod.Policy.load(cnxt, policy_id=policy_id)
        changed = False
        if name is not None and name != policy.name:
            policies = policy_mod.Policy.load_all(cnxt, filters={'name': name})
            if len(policies) > 0:
                msg = _("The policy (%(name)s) already exists."
                        ) % {"name": name}
                raise exception.BileanBadRequest(msg=msg)
            policy.name = name
            changed = True
        if metadata is not None and metadata != policy.metadata:
            policy.metadata = metadata
            changed = True
        if is_default is not None and is_default != policy.is_default:
            is_default = utils.parse_bool_param('is_default', is_default)
            if is_default:
                # Set policy to default should unset old default policy.
                policies = policy_mod.load_all(cnxt,
                                               filters={'is_default': True})
                if len(policies) == 1:
                    default_policy = policies[0]
                    default_policy.is_default = False
                    default_policy.store(cnxt)
            policy.is_default = is_default
            changed = True

        if changed:
            policy.store(cnxt)

        LOG.info(_LI("Policy '%(id)s' is updated."), {'id': policy_id})
        return policy.to_dict()
Ejemplo n.º 8
0
    def index(self, req):
        filter_whitelist = {
            'status': 'mixed',
        }
        param_whitelist = {
            'limit': 'single',
            'marker': 'single',
            'sort_dir': 'single',
            'sort_keys': 'multi',
            'show_deleted': 'single',
        }
        params = util.get_allowed_params(req.params, param_whitelist)
        filters = util.get_allowed_params(req.params, filter_whitelist)

        key = consts.PARAM_LIMIT
        if key in params:
            params[key] = utils.parse_int_param(key, params[key])

        key = consts.PARAM_SHOW_DELETED
        if key in params:
            params[key] = utils.parse_bool_param(key, params[key])

        if not filters:
            filters = None

        users = self.rpc_client.user_list(req.context, filters=filters,
                                          **params)

        return {'users': users}
Ejemplo n.º 9
0
    def user_list(self, cnxt, show_deleted=False, limit=None,
                  marker=None, sort_keys=None, sort_dir=None,
                  filters=None):
        limit = utils.parse_int_param('limit', limit)
        show_deleted = utils.parse_bool_param('show_deleted', show_deleted)

        users = user_mod.User.load_all(cnxt, show_deleted=show_deleted,
                                       limit=limit, marker=marker,
                                       sort_keys=sort_keys, sort_dir=sort_dir,
                                       filters=filters)

        return [user.to_dict() for user in users]
Ejemplo n.º 10
0
    def user_list(self, cnxt, show_deleted=False, limit=None,
                  marker=None, sort_keys=None, sort_dir=None,
                  filters=None):
        limit = utils.parse_int_param('limit', limit)
        show_deleted = utils.parse_bool_param('show_deleted', show_deleted)

        users = user_mod.User.load_all(cnxt, show_deleted=show_deleted,
                                       limit=limit, marker=marker,
                                       sort_keys=sort_keys, sort_dir=sort_dir,
                                       filters=filters)

        return [user.to_dict() for user in users]
Ejemplo n.º 11
0
    def policy_list(self, cnxt, limit=None, marker=None, sort_keys=None,
                    sort_dir=None, filters=None, show_deleted=False):
        if limit is not None:
            limit = utils.parse_int_param('limit', limit)
        if show_deleted is not None:
            show_deleted = utils.parse_bool_param('show_deleted',
                                                  show_deleted)
        policies = policy_mod.Policy.load_all(cnxt, limit=limit,
                                              marker=marker,
                                              sort_keys=sort_keys,
                                              sort_dir=sort_dir,
                                              filters=filters,
                                              show_deleted=show_deleted)

        return [policy.to_dict() for policy in policies]
Ejemplo n.º 12
0
    def rule_list(self, cnxt, limit=None, marker=None, sort_keys=None,
                  sort_dir=None, filters=None, show_deleted=False):
        if limit is not None:
            limit = utils.parse_int_param('limit', limit)
        if show_deleted is not None:
            show_deleted = utils.parse_bool_param('show_deleted',
                                                  show_deleted)
        rules = plugin_base.Rule.load_all(cnxt, limit=limit,
                                          marker=marker,
                                          sort_keys=sort_keys,
                                          sort_dir=sort_dir,
                                          filters=filters,
                                          show_deleted=show_deleted)

        return [rule.to_dict() for rule in rules]
Ejemplo n.º 13
0
    def policy_list(self, cnxt, limit=None, marker=None, sort_keys=None,
                    sort_dir=None, filters=None, show_deleted=False):
        if limit is not None:
            limit = utils.parse_int_param('limit', limit)
        if show_deleted is not None:
            show_deleted = utils.parse_bool_param('show_deleted',
                                                  show_deleted)
        policies = policy_mod.Policy.load_all(cnxt, limit=limit,
                                              marker=marker,
                                              sort_keys=sort_keys,
                                              sort_dir=sort_dir,
                                              filters=filters,
                                              show_deleted=show_deleted)

        return [policy.to_dict() for policy in policies]
Ejemplo n.º 14
0
    def rule_list(self, cnxt, limit=None, marker=None, sort_keys=None,
                  sort_dir=None, filters=None, show_deleted=False):
        if limit is not None:
            limit = utils.parse_int_param('limit', limit)
        if show_deleted is not None:
            show_deleted = utils.parse_bool_param('show_deleted',
                                                  show_deleted)
        rules = rule_base.Rule.load_all(cnxt, limit=limit,
                                        marker=marker,
                                        sort_keys=sort_keys,
                                        sort_dir=sort_dir,
                                        filters=filters,
                                        show_deleted=show_deleted)

        return [rule.to_dict() for rule in rules]
Ejemplo n.º 15
0
 def resource_list(self, cnxt, user_id=None, limit=None, marker=None,
                   sort_keys=None, sort_dir=None, filters=None,
                   project_safe=True, show_deleted=False):
     if limit is not None:
         limit = utils.parse_int_param('limit', limit)
     if show_deleted is not None:
         show_deleted = utils.parse_bool_param('show_deleted',
                                               show_deleted)
     resources = plugin_base.Resource.load_all(cnxt, user_id=user_id,
                                               limit=limit, marker=marker,
                                               sort_keys=sort_keys,
                                               sort_dir=sort_dir,
                                               filters=filters,
                                               project_safe=project_safe,
                                               show_deleted=show_deleted)
     return [r.to_dict() for r in resources]
Ejemplo n.º 16
0
 def resource_list(self, cnxt, user_id=None, limit=None, marker=None,
                   sort_keys=None, sort_dir=None, filters=None,
                   tenant_safe=True, show_deleted=False):
     if limit is not None:
         limit = utils.parse_int_param('limit', limit)
     if show_deleted is not None:
         show_deleted = utils.parse_bool_param('show_deleted',
                                               show_deleted)
     resources = resource_mod.Resource.load_all(cnxt, user_id=user_id,
                                                limit=limit, marker=marker,
                                                sort_keys=sort_keys,
                                                sort_dir=sort_dir,
                                                filters=filters,
                                                tenant_safe=tenant_safe,
                                                show_deleted=show_deleted)
     return [r.to_dict() for r in resources]
Ejemplo n.º 17
0
    def event_list(self, cnxt, user_id=None, limit=None, marker=None,
                   sort_keys=None, sort_dir=None, filters=None,
                   start_time=None, end_time=None, project_safe=True,
                   show_deleted=False):
        if limit is not None:
            limit = utils.parse_int_param('limit', limit)
        if show_deleted is not None:
            show_deleted = utils.parse_bool_param('show_deleted',
                                                  show_deleted)

        events = event_mod.Event.load_all(cnxt, user_id=user_id,
                                          limit=limit, marker=marker,
                                          sort_keys=sort_keys,
                                          sort_dir=sort_dir,
                                          filters=filters,
                                          start_time=start_time,
                                          end_time=end_time,
                                          project_safe=project_safe,
                                          show_deleted=show_deleted)
        return [e.to_dict() for e in events]
Ejemplo n.º 18
0
    def event_list(self, cnxt, user_id=None, limit=None, marker=None,
                   sort_keys=None, sort_dir=None, filters=None,
                   start_time=None, end_time=None, tenant_safe=True,
                   show_deleted=False):
        if limit is not None:
            limit = utils.parse_int_param('limit', limit)
        if show_deleted is not None:
            show_deleted = utils.parse_bool_param('show_deleted',
                                                  show_deleted)

        events = event_mod.Event.load_all(cnxt, user_id=user_id,
                                          limit=limit, marker=marker,
                                          sort_keys=sort_keys,
                                          sort_dir=sort_dir,
                                          filters=filters,
                                          start_time=start_time,
                                          end_time=end_time,
                                          tenant_safe=tenant_safe,
                                          show_deleted=show_deleted)
        return [e.to_dict() for e in events]