Package yakumo :: Package neutron :: Package v2 :: Module quota
[hide private]
[frames] | no frames]

Source Code for Module yakumo.neutron.v2.quota

  1  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>. 
  2  # All Rights Reserved. 
  3  # 
  4  #    Licensed under the Apache License, Version 2.0 (the "License"); you may 
  5  #    not use this file except in compliance with the License. You may obtain 
  6  #    a copy of the License at 
  7  # 
  8  #         http://www.apache.org/licenses/LICENSE-2.0 
  9  # 
 10  #    Unless required by applicable law or agreed to in writing, software 
 11  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 12  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 13  #    License for the specific language governing permissions and limitations 
 14  #    under the License. 
 15   
 16  """ 
 17  Resource class and its manager for quotas in Networking V2 API 
 18  """ 
 19   
 20  from yakumo import base 
 21  from yakumo.constant import UNDEF 
 22  from yakumo import mapper 
 23  from yakumo import utils 
 24   
 25   
 26  ATTRIBUTE_MAPPING = [ 
 27      ('project', 'tenant_id', mapper.Resource('project')), 
 28      ('subnet', 'subnet', mapper.Noop), 
 29      ('ikepolicy', 'ikepolicy', mapper.Noop), 
 30      ('subnetpool', 'subnetpool', mapper.Noop), 
 31      ('network', 'network', mapper.Noop), 
 32      ('ipsec_site_connection', 'ipsec_site_connection', mapper.Noop), 
 33      ('floatingip', 'floatingip', mapper.Noop), 
 34      ('ipsecpolicy', 'ipsecpolicy', mapper.Noop), 
 35      ('security_group_rule', 'security_group_rule', mapper.Noop), 
 36      ('vpnservice', 'vpnservice', mapper.Noop), 
 37      ('security_group', 'security_group', mapper.Noop), 
 38      ('router', 'router', mapper.Noop), 
 39      ('port', 'po', mapper.Noop), 
 40  ] 
 41   
 42   
43 -class Resource(base.Resource):
44 """Resource class for quotas in Networking V2 API""" 45
46 - def update(self, subnet=UNDEF, ikepolicy=UNDEF, subnetpool=UNDEF, 47 network=UNDEF, ipsec_site_connection=UNDEF, floatingip=UNDEF, 48 ipsecpolicy=UNDEF, security_group_rule=UNDEF, vpnservice=UNDEF, 49 security_group=UNDEF, router=UNDEF, port=UNDEF):
50 """ 51 Update properties of a quota 52 53 @keyword subnet: Maximum number of subnets 54 @type subnet: int 55 @keyword ikepolicy: Maximum number of IKE policies 56 @type ikepolicy: int 57 @keyword subnetpool: Maximum number of subnet pools 58 @type subnetpool: int 59 @keyword network: Maximum number of networks 60 @type network: int 61 @keyword ipsec_site_connection: Maximum number of IPSec site 62 connections 63 @type ipsec_site_connection: int 64 @keyword floatingip: Maximum number of floating IPs 65 @type floatingip: int 66 @keyword ipsecpolicy: Maximum number of IPSec policies 67 @type ipsecpolicy: int 68 @keyword security_group_rule: Maximum number of security group rules 69 @type security_group_rule: int 70 @keyword vpnservice: Maximum number of VPN services 71 @type vpnservice: int 72 @keyword security_group: Maximum number of security groups 73 @type security_group: int 74 @keyword router: Maximum number of routers 75 @type router: int 76 @keyword port: Maximum number of ports 77 @type port: int 78 """ 79 super(Resource, self).update( 80 subnet=subnet, 81 ikepolicy=ikepolicy, 82 subnetpool=subnetpool, 83 network=network, 84 ipsec_site_connection=ipsec_site_connection, 85 floatingip=floatingip, 86 ipsecpolicy=ipsecpolicy, 87 security_group_rule=security_group_rule, 88 vpnservice=vpnservice, 89 security_group=security_group, 90 router=router, 91 port=port)
92
93 - def delete(self):
94 try: 95 self._http.delete(self._url_resource_path, self.project) 96 except: 97 return None
98 99
100 -class Manager(base.Manager):
101 """Manager class for quotas in Networking V2 API""" 102 103 resource_class = Resource 104 service_type = 'network' 105 _attr_mapping = ATTRIBUTE_MAPPING 106 _hidden_methods = ["create"] 107 _id_attr = 'project' 108 _json_resource_key = 'quota' 109 _json_resources_key = 'quotas' 110 _url_resource_path = '/v2.0/quotas' 111
112 - def get(self, project):
113 try: 114 id = project._id 115 ret = self._http.get(self._url_resource_path, id) 116 json_params = ret.get(self._json_resource_key) 117 json_params['tenant_id'] = id 118 attrs = self._json2attr(json_params) 119 return self.resource_class(self, **attrs) 120 except: 121 return None
122