Debian Codegraph @

neutronclient/neutron/v2_0/qos/bandwidth_limit_rule.py

raw
1 # Copyright 2015 Huawei Technologies India Pvt Ltd, Inc.
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
18 from neutronclient._i18n import _
19 from neutronclient.common import exceptions
20 from neutronclient.neutron import v2_0 as neutronv20
21 from neutronclient.neutron.v2_0.qos import rule as qos_rule
22
23
24 BANDWIDTH_LIMIT_RULE_RESOURCE = 'bandwidth_limit_rule'
25
26
27 def add_bandwidth_limit_arguments(parser):
28 parser.add_argument(
29 '--max-kbps',
30 help=_('Maximum bandwidth in kbps.'))
31 parser.add_argument(
32 '--max-burst-kbps',
33 help=_('Maximum burst bandwidth in kbps.'))
34
35
36 def update_bandwidth_limit_args2body(parsed_args, body):
37 max_kbps = parsed_args.max_kbps
38 max_burst_kbps = parsed_args.max_burst_kbps
39 if not (max_kbps or max_burst_kbps):
40 raise exceptions.CommandError(_("Must provide max-kbps"
41 " or max-burst-kbps option."))
42 neutronv20.update_dict(parsed_args, body,
43 ['max_kbps', 'max_burst_kbps', 'tenant_id'])
44
45
46 class CreateQoSBandwidthLimitRule(qos_rule.QosRuleMixin,
47 neutronv20.CreateCommand):
48 """Create a qos bandwidth limit rule."""
49
50 resource = BANDWIDTH_LIMIT_RULE_RESOURCE
51
52 def add_known_arguments(self, parser):
53 super(CreateQoSBandwidthLimitRule, self).add_known_arguments(parser)
54 add_bandwidth_limit_arguments(parser)
55
56 def args2body(self, parsed_args):
57 body = {}
58 update_bandwidth_limit_args2body(parsed_args, body)
59 return {self.resource: body}
60
61
62 class ListQoSBandwidthLimitRules(qos_rule.QosRuleMixin,
63 neutronv20.ListCommand):
64 """List all qos bandwidth limit rules belonging to the specified policy."""
65
66 resource = BANDWIDTH_LIMIT_RULE_RESOURCE
67 _formatters = {}
68 pagination_support = True
69 sorting_support = True
70
71
72 class ShowQoSBandwidthLimitRule(qos_rule.QosRuleMixin, neutronv20.ShowCommand):
73 """Show information about the given qos bandwidth limit rule."""
74
75 resource = BANDWIDTH_LIMIT_RULE_RESOURCE
76 allow_names = False
77
78
79 class UpdateQoSBandwidthLimitRule(qos_rule.QosRuleMixin,
80 neutronv20.UpdateCommand):
81 """Update the given qos bandwidth limit rule."""
82
83 resource = BANDWIDTH_LIMIT_RULE_RESOURCE
84 allow_names = False
85
86 def add_known_arguments(self, parser):
87 super(UpdateQoSBandwidthLimitRule, self).add_known_arguments(parser)
88 add_bandwidth_limit_arguments(parser)
89
90 def args2body(self, parsed_args):
91 body = {}
92 update_bandwidth_limit_args2body(parsed_args, body)
93 return {self.resource: body}
94
95
96 class DeleteQoSBandwidthLimitRule(qos_rule.QosRuleMixin,
97 neutronv20.DeleteCommand):
98 """Delete a given qos bandwidth limit rule."""
99
100 resource = BANDWIDTH_LIMIT_RULE_RESOURCE
101 allow_names = False