1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5#      http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from openstack import resource
14
15
16class Quota(resource.Resource):
17    resource_key = 'quota'
18    resources_key = 'quotas'
19    base_path = '/quotas'
20
21    _allow_unknown_attrs_in_body = True
22
23    # capabilities
24    allow_fetch = True
25    allow_commit = True
26    allow_delete = True
27    allow_list = True
28
29    # Properties
30    #: The maximum amount of floating IPs you can have. *Type: int*
31    floating_ips = resource.Body('floatingip', type=int)
32    #: The maximum amount of health monitors you can create. *Type: int*
33    health_monitors = resource.Body('healthmonitor', type=int)
34    #: The maximum amount of listeners you can create. *Type: int*
35    listeners = resource.Body('listener', type=int)
36    #: The maximum amount of load balancers you can create. *Type: int*
37    load_balancers = resource.Body('loadbalancer', type=int)
38    #: The maximum amount of L7 policies you can create. *Type: int*
39    l7_policies = resource.Body('l7policy', type=int)
40    #: The maximum amount of networks you can create. *Type: int*
41    networks = resource.Body('network', type=int)
42    #: The maximum amount of pools you can create. *Type: int*
43    pools = resource.Body('pool', type=int)
44    #: The maximum amount of ports you can create. *Type: int*
45    ports = resource.Body('port', type=int)
46    #: The ID of the project these quota values are for.
47    project_id = resource.Body('tenant_id', alternate_id=True)
48    #: The maximum amount of RBAC policies you can create. *Type: int*
49    rbac_policies = resource.Body('rbac_policy', type=int)
50    #: The maximum amount of routers you can create. *Type: int*
51    routers = resource.Body('router', type=int)
52    #: The maximum amount of subnets you can create. *Type: int*
53    subnets = resource.Body('subnet', type=int)
54    #: The maximum amount of subnet pools you can create. *Type: int*
55    subnet_pools = resource.Body('subnetpool', type=int)
56    #: The maximum amount of security group rules you can create. *Type: int*
57    security_group_rules = resource.Body('security_group_rule', type=int)
58    #: The maximum amount of security groups you can create. *Type: int*
59    security_groups = resource.Body('security_group', type=int)
60
61    def _prepare_request(self, requires_id=True, prepend_key=False,
62                         base_path=None, **kwargs):
63        _request = super(Quota, self)._prepare_request(requires_id,
64                                                       prepend_key)
65        if self.resource_key in _request.body:
66            _body = _request.body[self.resource_key]
67        else:
68            _body = _request.body
69        if 'id' in _body:
70            del _body['id']
71        return _request
72
73
74class QuotaDefault(Quota):
75    base_path = '/quotas/%(project)s/default'
76
77    # capabilities
78    allow_retrieve = True
79    allow_commit = False
80    allow_delete = False
81    allow_list = False
82
83    # Properties
84    #: The ID of the project.
85    project = resource.URI('project')
86
87
88class QuotaDetails(Quota):
89    base_path = '/quotas/%(project)s/details'
90
91    # capabilities
92    allow_retrieve = True
93    allow_commit = False
94    allow_delete = False
95    allow_list = False
96
97    # Properties
98    #: The ID of the project.
99    project = resource.URI('project')
100    #: The maximum amount of floating IPs you can have. *Type: dict*
101    floating_ips = resource.Body('floatingip', type=dict)
102    #: The maximum amount of health monitors you can create. *Type: dict*
103    health_monitors = resource.Body('healthmonitor', type=dict)
104    #: The maximum amount of listeners you can create. *Type: dict*
105    listeners = resource.Body('listener', type=dict)
106    #: The maximum amount of load balancers you can create. *Type: dict*
107    load_balancers = resource.Body('loadbalancer', type=dict)
108    #: The maximum amount of L7 policies you can create. *Type: dict*
109    l7_policies = resource.Body('l7policy', type=dict)
110    #: The maximum amount of networks you can create. *Type: dict*
111    networks = resource.Body('network', type=dict)
112    #: The maximum amount of pools you can create. *Type: dict*
113    pools = resource.Body('pool', type=dict)
114    #: The maximum amount of ports you can create. *Type: dict*
115    ports = resource.Body('port', type=dict)
116    #: The ID of the project these quota values are for.
117    project_id = resource.Body('tenant_id', alternate_id=True)
118    #: The maximum amount of RBAC policies you can create. *Type: dict*
119    rbac_policies = resource.Body('rbac_policy', type=dict)
120    #: The maximum amount of routers you can create. *Type: int*
121    routers = resource.Body('router', type=dict)
122    #: The maximum amount of subnets you can create. *Type: dict*
123    subnets = resource.Body('subnet', type=dict)
124    #: The maximum amount of subnet pools you can create. *Type: dict*
125    subnet_pools = resource.Body('subnetpool', type=dict)
126    #: The maximum amount of security group rules you can create. *Type: dict*
127    security_group_rules = resource.Body('security_group_rule', type=dict)
128    #: The maximum amount of security groups you can create. *Type: dict*
129    security_groups = resource.Body('security_group', type=dict)
130