Ejemplo n.º 1
0
    def index(self, req, tenant_id):
        """
        Return all absolute and rate limit information.
        """
        quotas = QUOTAS.get_all_quotas_by_tenant(tenant_id)
        abs_limits = dict((k, v['hard_limit']) for k, v in quotas.items())
        rate_limits = req.environ.get("reddwarf.limits", [])

        return wsgi.Result(views.LimitViews(abs_limits,
                                            rate_limits).data(), 200)
Ejemplo n.º 2
0
    def test_empty_data(self):
        rate_limits = []
        abs_view = dict()

        view_data = views.LimitViews(abs_view, rate_limits)
        self.assertIsNotNone(view_data)

        data = view_data.data()
        expected = {'limits': [{'verb': 'ABSOLUTE'}]}

        self.assertEqual(expected, data)
Ejemplo n.º 3
0
    def test_data(self):
        rate_limits = [{
            "URI": "*",
            "regex": ".*",
            "value": 10,
            "verb": "POST",
            "remaining": 2,
            "unit": "MINUTE",
            "resetTime": 1311272226
        }, {
            "URI": "*",
            "regex": ".*",
            "value": 10,
            "verb": "PUT",
            "remaining": 2,
            "unit": "MINUTE",
            "resetTime": 1311272226
        }, {
            "URI": "*",
            "regex": ".*",
            "value": 10,
            "verb": "DELETE",
            "remaining": 2,
            "unit": "MINUTE",
            "resetTime": 1311272226
        }, {
            "URI": "*",
            "regex": ".*",
            "value": 10,
            "verb": "GET",
            "remaining": 2,
            "unit": "MINUTE",
            "resetTime": 1311272226
        }]
        abs_view = {"instances": 55, "volumes": 100, "backups": 40}

        view_data = views.LimitViews(abs_view, rate_limits)
        self.assertIsNotNone(view_data)

        data = view_data.data()
        expected = {
            'limits': [{
                'max_instances': 55,
                'max_backups': 40,
                'verb': 'ABSOLUTE',
                'max_volumes': 100
            }, {
                'regex': '.*',
                'nextAvailable': '2011-07-21T18:17:06Z',
                'uri': '*',
                'value': 10,
                'verb': 'POST',
                'remaining': 2,
                'unit': 'MINUTE'
            }, {
                'regex': '.*',
                'nextAvailable': '2011-07-21T18:17:06Z',
                'uri': '*',
                'value': 10,
                'verb': 'PUT',
                'remaining': 2,
                'unit': 'MINUTE'
            }, {
                'regex': '.*',
                'nextAvailable': '2011-07-21T18:17:06Z',
                'uri': '*',
                'value': 10,
                'verb': 'DELETE',
                'remaining': 2,
                'unit': 'MINUTE'
            }, {
                'regex': '.*',
                'nextAvailable': '2011-07-21T18:17:06Z',
                'uri': '*',
                'value': 10,
                'verb': 'GET',
                'remaining': 2,
                'unit': 'MINUTE'
            }]
        }

        self.assertEqual(expected, data)