Skip to content

Commit 3205dad

Browse files
Rodolfo Alonso HernandezDean Troyer
authored andcommitted
Add network support for Network QoS policies
Added following commands: - network qos policy create - network qos policy delete - network qos policy set - network qos policy show - network qos policy list Closes-Bug: 1609037 Depends-On: I33bafeca979410d329ae10a82772ccdb48c10daa Change-Id: I63a8f63702514ff5814481bb021e2aa9d5f3d4b1
1 parent 762f2f2 commit 3205dad

8 files changed

Lines changed: 953 additions & 0 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
==================
2+
network qos policy
3+
==================
4+
5+
A **Network QoS policy** groups a number of Network QoS rules, applied to a
6+
network or a port.
7+
8+
Network v2
9+
10+
network qos policy create
11+
-------------------------
12+
13+
Create new Network QoS policy
14+
15+
.. program:: network qos policy create
16+
.. code:: bash
17+
18+
os network qos policy create
19+
[--description <description>]
20+
[--share | --no-share]
21+
[--project <project>]
22+
[--project-domain <project-domain>]
23+
<name>
24+
25+
.. option:: --description <description>
26+
27+
Description of the QoS policy
28+
29+
.. option:: --share
30+
31+
Make the QoS policy accessible by other projects
32+
33+
.. option:: --no-share
34+
35+
Make the QoS policy not accessible by other projects (default)
36+
37+
.. option:: --project <project>
38+
39+
Owner's project (name or ID)
40+
41+
.. option:: --project-domain <project-domain>]
42+
43+
Domain the project belongs to (name or ID).
44+
This can be used in case collisions between project names exist.
45+
46+
.. describe:: <name>
47+
48+
New QoS policy specification name
49+
50+
network qos policy delete
51+
-------------------------
52+
53+
Delete Network QoS policy
54+
55+
.. program:: network qos policy delete
56+
.. code:: bash
57+
58+
os network qos policy delete
59+
<qos-policy> [<qos-policy> ...]
60+
61+
.. describe:: <qos-policy>
62+
63+
Network QoS policy(s) to delete (name or ID)
64+
65+
network qos policy list
66+
-----------------------
67+
68+
List Network QoS policies
69+
70+
.. program:: network qos policy list
71+
.. code:: bash
72+
73+
os network qos policy list
74+
75+
network qos policy set
76+
----------------------
77+
78+
Set Network QoS policy properties
79+
80+
.. program:: network qos policy set
81+
.. code:: bash
82+
83+
os network qos policy set
84+
[--name <name>]
85+
[--description <description>]
86+
[--share | --no-share]
87+
<qos-policy>
88+
89+
.. option:: --name <name>
90+
91+
Name of the QoS policy
92+
93+
.. option:: --description <description>
94+
95+
Description of the QoS policy
96+
97+
.. option:: --share
98+
99+
Make the QoS policy accessible by other projects
100+
101+
.. option:: --no-share
102+
103+
Make the QoS policy not accessible by other projects
104+
105+
.. describe:: <qos-policy>
106+
107+
Network QoS policy(s) to delete (name or ID)
108+
109+
network qos policy show
110+
-----------------------
111+
112+
Display Network QoS policy details
113+
114+
.. program:: network qos policy show
115+
.. code:: bash
116+
117+
os network qos policy show
118+
<qos-policy>
119+
120+
.. describe:: <qos-policy>
121+
122+
Network QoS policy(s) to show (name or ID)

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ referring to both Compute and Volume quotas.
112112
* ``network``: (**Compute**, **Network**) - a virtual network for connecting servers and other resources
113113
* ``network agent``: (**Network**) - A network agent is an agent that handles various tasks used to implement virtual networks
114114
* ``network rbac``: (**Network**) - an RBAC policy for network resources
115+
* ``network qos policy``: (**Network**) - a QoS policy for network resources
115116
* ``network segment``: (**Network**) - a segment of a virtual network
116117
* ``object``: (**Object Storage**) a single file in the Object Storage
117118
* ``object store account``: (**Object Storage**) owns a group of Object Storage resources
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# Copyright (c) 2016, Intel Corporation.
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+
import logging
17+
18+
from osc_lib.command import command
19+
from osc_lib import exceptions
20+
from osc_lib import utils
21+
22+
from openstackclient.i18n import _
23+
from openstackclient.identity import common as identity_common
24+
25+
26+
LOG = logging.getLogger(__name__)
27+
28+
29+
def _get_columns(item):
30+
columns = list(item.keys())
31+
if 'tenant_id' in columns:
32+
columns.remove('tenant_id')
33+
columns.append('project_id')
34+
return tuple(sorted(columns))
35+
36+
37+
def _get_attrs(client_manager, parsed_args):
38+
attrs = {}
39+
if parsed_args.name is not None:
40+
attrs['name'] = str(parsed_args.name)
41+
if parsed_args.description is not None:
42+
attrs['description'] = parsed_args.description
43+
if parsed_args.share:
44+
attrs['shared'] = True
45+
if parsed_args.no_share:
46+
attrs['shared'] = False
47+
if parsed_args.project is not None:
48+
identity_client = client_manager.identity
49+
project_id = identity_common.find_project(
50+
identity_client,
51+
parsed_args.project,
52+
parsed_args.project_domain,
53+
).id
54+
attrs['tenant_id'] = project_id
55+
56+
return attrs
57+
58+
59+
class CreateNetworkQosPolicy(command.ShowOne):
60+
"""Create a QoS policy"""
61+
62+
def get_parser(self, prog_name):
63+
parser = super(CreateNetworkQosPolicy, self).get_parser(prog_name)
64+
parser.add_argument(
65+
'name',
66+
metavar='<name>',
67+
help=_("Name of QoS policy to create")
68+
)
69+
parser.add_argument(
70+
'--description',
71+
metavar='<description>',
72+
help=_("Description of the QoS policy")
73+
)
74+
share_group = parser.add_mutually_exclusive_group()
75+
share_group.add_argument(
76+
'--share',
77+
action='store_true',
78+
default=None,
79+
help=_("Make the QoS policy accessible by other projects")
80+
)
81+
share_group.add_argument(
82+
'--no-share',
83+
action='store_true',
84+
help=_("Make the QoS policy not accessible by other projects "
85+
"(default)")
86+
)
87+
parser.add_argument(
88+
'--project',
89+
metavar='<project>',
90+
help=_("Owner's project (name or ID)")
91+
)
92+
identity_common.add_project_domain_option_to_parser(parser)
93+
return parser
94+
95+
def take_action(self, parsed_args):
96+
client = self.app.client_manager.network
97+
attrs = _get_attrs(self.app.client_manager, parsed_args)
98+
obj = client.create_qos_policy(**attrs)
99+
columns = _get_columns(obj)
100+
data = utils.get_item_properties(obj, columns, formatters={})
101+
return columns, data
102+
103+
104+
class DeleteNetworkQosPolicy(command.Command):
105+
"""Delete Qos Policy(s)"""
106+
107+
def get_parser(self, prog_name):
108+
parser = super(DeleteNetworkQosPolicy, self).get_parser(prog_name)
109+
parser.add_argument(
110+
'policy',
111+
metavar="<qos-policy>",
112+
nargs="+",
113+
help=_("QoS policy(s) to delete (name or ID)")
114+
)
115+
return parser
116+
117+
def take_action(self, parsed_args):
118+
client = self.app.client_manager.network
119+
result = 0
120+
121+
for policy in parsed_args.policy:
122+
try:
123+
obj = client.find_qos_policy(policy, ignore_missing=False)
124+
client.delete_qos_policy(obj)
125+
except Exception as e:
126+
result += 1
127+
LOG.error(_("Failed to delete QoS policy "
128+
"name or ID '%(qos_policy)s': %(e)s"),
129+
{'qos_policy': policy, 'e': e})
130+
131+
if result > 0:
132+
total = len(parsed_args.policy)
133+
msg = (_("%(result)s of %(total)s QoS policies failed "
134+
"to delete.") % {'result': result, 'total': total})
135+
raise exceptions.CommandError(msg)
136+
137+
138+
class ListNetworkQosPolicy(command.Lister):
139+
"""List QoS policies"""
140+
141+
def take_action(self, parsed_args):
142+
client = self.app.client_manager.network
143+
columns = (
144+
'id',
145+
'name',
146+
'shared',
147+
'tenant_id',
148+
)
149+
column_headers = (
150+
'ID',
151+
'Name',
152+
'Shared',
153+
'Project',
154+
)
155+
data = client.qos_policies()
156+
157+
return (column_headers,
158+
(utils.get_item_properties(
159+
s, columns, formatters={},
160+
) for s in data))
161+
162+
163+
class SetNetworkQosPolicy(command.Command):
164+
"""Set QoS policy properties"""
165+
166+
def get_parser(self, prog_name):
167+
parser = super(SetNetworkQosPolicy, self).get_parser(prog_name)
168+
parser.add_argument(
169+
'policy',
170+
metavar="<qos-policy>",
171+
help=_("QoS policy to modify (name or ID)")
172+
)
173+
parser.add_argument(
174+
'--name',
175+
metavar="<name>",
176+
help=_('Set QoS policy name')
177+
)
178+
parser.add_argument(
179+
'--description',
180+
metavar='<description>',
181+
help=_("Description of the QoS policy")
182+
)
183+
enable_group = parser.add_mutually_exclusive_group()
184+
enable_group.add_argument(
185+
'--share',
186+
action='store_true',
187+
help=_('Make the QoS policy accessible by other projects'),
188+
)
189+
enable_group.add_argument(
190+
'--no-share',
191+
action='store_true',
192+
help=_('Make the QoS policy not accessible by other projects'),
193+
)
194+
return parser
195+
196+
def take_action(self, parsed_args):
197+
client = self.app.client_manager.network
198+
obj = client.find_qos_policy(
199+
parsed_args.policy,
200+
ignore_missing=False)
201+
attrs = {}
202+
if parsed_args.name is not None:
203+
attrs['name'] = parsed_args.name
204+
if parsed_args.share:
205+
attrs['shared'] = True
206+
if parsed_args.no_share:
207+
attrs['shared'] = False
208+
if parsed_args.description is not None:
209+
attrs['description'] = parsed_args.description
210+
client.update_qos_policy(obj, **attrs)
211+
212+
213+
class ShowNetworkQosPolicy(command.ShowOne):
214+
"""Display QoS policy details"""
215+
216+
def get_parser(self, prog_name):
217+
parser = super(ShowNetworkQosPolicy, self).get_parser(prog_name)
218+
parser.add_argument(
219+
'policy',
220+
metavar="<qos-policy>",
221+
help=_("QoS policy to display (name or ID)")
222+
)
223+
return parser
224+
225+
def take_action(self, parsed_args):
226+
client = self.app.client_manager.network
227+
obj = client.find_qos_policy(parsed_args.policy,
228+
ignore_missing=False)
229+
columns = _get_columns(obj)
230+
data = utils.get_item_properties(obj, columns)
231+
return columns, data

0 commit comments

Comments
 (0)