2929COMPUTE_QUOTAS = {
3030 'cores' : 'cores' ,
3131 'fixed_ips' : 'fixed-ips' ,
32- 'floating_ips' : 'floating-ips' ,
3332 'injected_file_content_bytes' : 'injected-file-size' ,
3433 'injected_file_path_bytes' : 'injected-path-size' ,
3534 'injected_files' : 'injected-files' ,
3635 'instances' : 'instances' ,
3736 'key_pairs' : 'key-pairs' ,
3837 'metadata_items' : 'properties' ,
3938 'ram' : 'ram' ,
40- 'security_group_rules' : 'secgroup-rules' ,
41- 'security_groups' : 'secgroups' ,
4239}
4340
4441VOLUME_QUOTAS = {
4744 'volumes' : 'volumes' ,
4845}
4946
47+ NOVA_NETWORK_QUOTAS = {
48+ 'floating_ips' : 'floating-ips' ,
49+ 'security_group_rules' : 'secgroup-rules' ,
50+ 'security_groups' : 'secgroups' ,
51+ }
52+
5053NETWORK_QUOTAS = {
5154 'floatingip' : 'floating-ips' ,
5255 'security_group_rule' : 'secgroup-rules' ,
5356 'security_group' : 'secgroups' ,
57+ 'network' : 'networks' ,
58+ 'subnet' : 'subnets' ,
59+ 'port' : 'ports' ,
60+ 'router' : 'routers' ,
61+ 'rbac_policy' : 'rbac-policies' ,
62+ 'vip' : 'vips' ,
63+ 'subnetpool' : 'subnetpools' ,
64+ 'member' : 'members' ,
65+ 'health_monitor' : 'health-monitors' ,
5466}
5567
5668
5769class SetQuota (command .Command ):
5870 """Set quotas for project or class"""
5971
72+ def _build_options_list (self ):
73+ if self .app .client_manager .is_network_endpoint_enabled ():
74+ return itertools .chain (COMPUTE_QUOTAS .items (),
75+ VOLUME_QUOTAS .items (),
76+ NETWORK_QUOTAS .items ())
77+ else :
78+ return itertools .chain (COMPUTE_QUOTAS .items (),
79+ VOLUME_QUOTAS .items (),
80+ NOVA_NETWORK_QUOTAS .items ())
81+
6082 def get_parser (self , prog_name ):
6183 parser = super (SetQuota , self ).get_parser (prog_name )
6284 parser .add_argument (
@@ -71,8 +93,7 @@ def get_parser(self, prog_name):
7193 default = False ,
7294 help = 'Set quotas for <class>' ,
7395 )
74- for k , v in itertools .chain (
75- COMPUTE_QUOTAS .items (), VOLUME_QUOTAS .items ()):
96+ for k , v in self ._build_options_list ():
7697 parser .add_argument (
7798 '--%s' % v ,
7899 metavar = '<%s>' % v ,
@@ -92,7 +113,7 @@ def take_action(self, parsed_args):
92113 identity_client = self .app .client_manager .identity
93114 compute_client = self .app .client_manager .compute
94115 volume_client = self .app .client_manager .volume
95-
116+ network_client = self . app . client_manager . network
96117 compute_kwargs = {}
97118 for k , v in COMPUTE_QUOTAS .items ():
98119 value = getattr (parsed_args , k , None )
@@ -107,7 +128,20 @@ def take_action(self, parsed_args):
107128 k = k + '_%s' % parsed_args .volume_type
108129 volume_kwargs [k ] = value
109130
110- if compute_kwargs == {} and volume_kwargs == {}:
131+ network_kwargs = {}
132+ if self .app .client_manager .is_network_endpoint_enabled ():
133+ for k , v in NETWORK_QUOTAS .items ():
134+ value = getattr (parsed_args , k , None )
135+ if value is not None :
136+ network_kwargs [k ] = value
137+ else :
138+ for k , v in NOVA_NETWORK_QUOTAS .items ():
139+ value = getattr (parsed_args , k , None )
140+ if value is not None :
141+ compute_kwargs [k ] = value
142+
143+ if (compute_kwargs == {} and volume_kwargs == {}
144+ and network_kwargs == {}):
111145 sys .stderr .write ("No quotas updated" )
112146 return
113147
@@ -126,6 +160,9 @@ def take_action(self, parsed_args):
126160 volume_client .quota_classes .update (
127161 project .id ,
128162 ** volume_kwargs )
163+ if network_kwargs :
164+ sys .stderr .write ("Network quotas are ignored since quota class"
165+ "is not supported." )
129166 else :
130167 if compute_kwargs :
131168 compute_client .quotas .update (
@@ -135,6 +172,10 @@ def take_action(self, parsed_args):
135172 volume_client .quotas .update (
136173 project .id ,
137174 ** volume_kwargs )
175+ if network_kwargs :
176+ network_client .update_quota (
177+ project .id ,
178+ ** network_kwargs )
138179
139180
140181class ShowQuota (command .ShowOne ):
@@ -232,8 +273,8 @@ def take_action(self, parsed_args):
232273 # neutron is enabled, quotas of these three resources
233274 # in nova will be replaced by neutron's.
234275 for k , v in itertools .chain (
235- COMPUTE_QUOTAS .items (), VOLUME_QUOTAS .items (),
236- NETWORK_QUOTAS .items ()):
276+ COMPUTE_QUOTAS .items (), NOVA_NETWORK_QUOTAS .items (),
277+ VOLUME_QUOTAS . items (), NETWORK_QUOTAS .items ()):
237278 if not k == v and info .get (k ):
238279 info [v ] = info [k ]
239280 info .pop (k )
0 commit comments