Skip to content

Commit 4132392

Browse files
author
Rodolfo Alonso Hernandez
committed
Add QoS support to Network object.
Added "qos_policy" parameter to Network class. Change-Id: Idc00f2792eef5b1f0910084d95cf9a8e83fe818c Closes-Bug: 1627069
1 parent f4536e7 commit 4132392

5 files changed

Lines changed: 69 additions & 0 deletions

File tree

doc/source/command-objects/network.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Create new network
3030
[--provider-network-type <provider-network-type>]
3131
[--provider-physical-network <provider-physical-network>]
3232
[--provider-segment <provider-segment>]
33+
[--qos-policy <qos-policy>]
3334
[--transparent-vlan | --no-transparent-vlan]
3435
<name>
3536
@@ -144,6 +145,12 @@ Create new network
144145
145146
*Network version 2 only*
146147
148+
.. option:: --qos-policy <qos-policy>
149+
150+
QoS policy to attach to this network (name or ID)
151+
152+
*Network version 2 only*
153+
147154
.. option:: --transparent-vlan
148155
149156
Make the network VLAN transparent
@@ -303,6 +310,7 @@ Set network properties
303310
[--provider-network-type <provider-network-type>]
304311
[--provider-physical-network <provider-physical-network>]
305312
[--provider-segment <provider-segment>]
313+
[--qos-policy <qos-policy> | --no-qos-policy]
306314
[--transparent-vlan | --no-transparent-vlan]
307315
<network>
308316
@@ -370,6 +378,14 @@ Set network properties
370378
371379
VLAN ID for VLAN networks or Tunnel ID for GRE/VXLAN networks
372380
381+
.. option:: --qos-policy <qos-policy>
382+
383+
QoS policy to attach to this network (name or ID)
384+
385+
.. option:: --no-qos-policy
386+
387+
Remove the QoS policy attached to this network
388+
373389
.. option:: --transparent-vlan
374390
375391
Make the network VLAN transparent

openstackclient/network/v2/network.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ def _get_attrs(client_manager, parsed_args):
9999
attrs['provider:physical_network'] = parsed_args.physical_network
100100
if parsed_args.segmentation_id:
101101
attrs['provider:segmentation_id'] = parsed_args.segmentation_id
102+
if parsed_args.qos_policy is not None:
103+
network_client = client_manager.network
104+
_qos_policy = network_client.find_qos_policy(parsed_args.qos_policy,
105+
ignore_missing=False)
106+
attrs['qos_policy_id'] = _qos_policy.id
107+
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
108+
attrs['qos_policy_id'] = None
102109
# Update VLAN Transparency for networks
103110
if parsed_args.transparent_vlan:
104111
attrs['vlan_transparent'] = True
@@ -249,6 +256,11 @@ def update_parser_network(self, parser):
249256
help=_("Do not use the network as the default external network "
250257
"(default)")
251258
)
259+
parser.add_argument(
260+
'--qos-policy',
261+
metavar='<qos-policy>',
262+
help=_("QoS policy to attach to this network (name or ID)")
263+
)
252264
_add_additional_network_options(parser)
253265
return parser
254266

@@ -572,6 +584,17 @@ def get_parser(self, prog_name):
572584
action='store_true',
573585
help=_("Do not use the network as the default external network")
574586
)
587+
qos_group = parser.add_mutually_exclusive_group()
588+
qos_group.add_argument(
589+
'--qos-policy',
590+
metavar='<qos-policy>',
591+
help=_("QoS policy to attach to this network (name or ID)")
592+
)
593+
qos_group.add_argument(
594+
'--no-qos-policy',
595+
action='store_true',
596+
help=_("Remove the QoS policy attached to this network")
597+
)
575598
_add_additional_network_options(parser)
576599
return parser
577600

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def create_one_network(attrs=None):
299299
'availability_zone_hints': [],
300300
'is_default': False,
301301
'port_security_enabled': True,
302+
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
302303
}
303304

304305
# Overwrite default attributes.

openstackclient/tests/unit/network/v2/test_network.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class TestCreateNetworkIdentityV3(TestNetwork):
5353
'availability_zone_hints': ["nova"],
5454
}
5555
)
56+
qos_policy = (network_fakes.FakeNetworkQosPolicy.
57+
create_one_qos_policy(attrs={'id': _network.qos_policy_id}))
5658

5759
columns = (
5860
'admin_state_up',
@@ -67,6 +69,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
6769
'provider_network_type',
6870
'provider_physical_network',
6971
'provider_segmentation_id',
72+
'qos_policy_id',
7073
'router:external',
7174
'shared',
7275
'status',
@@ -86,6 +89,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
8689
_network.provider_network_type,
8790
_network.provider_physical_network,
8891
_network.provider_segmentation_id,
92+
_network.qos_policy_id,
8993
network._format_router_external(_network.is_router_external),
9094
_network.shared,
9195
_network.status,
@@ -102,6 +106,7 @@ def setUp(self):
102106

103107
self.projects_mock.get.return_value = self.project
104108
self.domains_mock.get.return_value = self.domain
109+
self.network.find_qos_policy = mock.Mock(return_value=self.qos_policy)
105110

106111
def test_create_no_options(self):
107112
arglist = []
@@ -144,6 +149,7 @@ def test_create_all_options(self):
144149
"--provider-network-type", "vlan",
145150
"--provider-physical-network", "physnet1",
146151
"--provider-segment", "400",
152+
"--qos-policy", self.qos_policy.id,
147153
"--transparent-vlan",
148154
"--enable-port-security",
149155
self._network.name,
@@ -160,6 +166,7 @@ def test_create_all_options(self):
160166
('provider_network_type', 'vlan'),
161167
('physical_network', 'physnet1'),
162168
('segmentation_id', '400'),
169+
('qos_policy', self.qos_policy.id),
163170
('transparent_vlan', True),
164171
('enable_port_security', True),
165172
('name', self._network.name),
@@ -180,6 +187,7 @@ def test_create_all_options(self):
180187
'provider:network_type': 'vlan',
181188
'provider:physical_network': 'physnet1',
182189
'provider:segmentation_id': '400',
190+
'qos_policy_id': self.qos_policy.id,
183191
'vlan_transparent': True,
184192
'port_security_enabled': True,
185193
})
@@ -235,6 +243,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
235243
'provider_network_type',
236244
'provider_physical_network',
237245
'provider_segmentation_id',
246+
'qos_policy_id',
238247
'router:external',
239248
'shared',
240249
'status',
@@ -254,6 +263,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
254263
_network.provider_network_type,
255264
_network.provider_physical_network,
256265
_network.provider_segmentation_id,
266+
_network.qos_policy_id,
257267
network._format_router_external(_network.is_router_external),
258268
_network.shared,
259269
_network.status,
@@ -745,13 +755,16 @@ class TestSetNetwork(TestNetwork):
745755

746756
# The network to set.
747757
_network = network_fakes.FakeNetwork.create_one_network()
758+
qos_policy = (network_fakes.FakeNetworkQosPolicy.
759+
create_one_qos_policy(attrs={'id': _network.qos_policy_id}))
748760

749761
def setUp(self):
750762
super(TestSetNetwork, self).setUp()
751763

752764
self.network.update_network = mock.Mock(return_value=None)
753765

754766
self.network.find_network = mock.Mock(return_value=self._network)
767+
self.network.find_qos_policy = mock.Mock(return_value=self.qos_policy)
755768

756769
# Get the command object to test
757770
self.cmd = network.SetNetwork(self.app, self.namespace)
@@ -770,6 +783,7 @@ def test_set_this(self):
770783
'--provider-segment', '400',
771784
'--no-transparent-vlan',
772785
'--enable-port-security',
786+
'--qos-policy', self.qos_policy.name,
773787
]
774788
verifylist = [
775789
('network', self._network.name),
@@ -784,6 +798,7 @@ def test_set_this(self):
784798
('segmentation_id', '400'),
785799
('no_transparent_vlan', True),
786800
('enable_port_security', True),
801+
('qos_policy', self.qos_policy.name),
787802
]
788803

789804
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -801,6 +816,7 @@ def test_set_this(self):
801816
'provider:segmentation_id': '400',
802817
'vlan_transparent': False,
803818
'port_security_enabled': True,
819+
'qos_policy_id': self.qos_policy.id,
804820
}
805821
self.network.update_network.assert_called_once_with(
806822
self._network, **attrs)
@@ -813,13 +829,15 @@ def test_set_that(self):
813829
'--no-share',
814830
'--internal',
815831
'--disable-port-security',
832+
'--no-qos-policy',
816833
]
817834
verifylist = [
818835
('network', self._network.name),
819836
('disable', True),
820837
('no_share', True),
821838
('internal', True),
822839
('disable_port_security', True),
840+
('no_qos_policy', True),
823841
]
824842

825843
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -830,6 +848,7 @@ def test_set_that(self):
830848
'shared': False,
831849
'router:external': False,
832850
'port_security_enabled': False,
851+
'qos_policy_id': None,
833852
}
834853
self.network.update_network.assert_called_once_with(
835854
self._network, **attrs)
@@ -866,6 +885,7 @@ class TestShowNetwork(TestNetwork):
866885
'provider_network_type',
867886
'provider_physical_network',
868887
'provider_segmentation_id',
888+
'qos_policy_id',
869889
'router:external',
870890
'shared',
871891
'status',
@@ -885,6 +905,7 @@ class TestShowNetwork(TestNetwork):
885905
_network.provider_network_type,
886906
_network.provider_physical_network,
887907
_network.provider_segmentation_id,
908+
_network.qos_policy_id,
888909
network._format_router_external(_network.is_router_external),
889910
_network.shared,
890911
_network.status,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
Add QoS support for Network commands.
5+
The new parameter ``qos-policy`` is added to ``network create`` and
6+
``network set`` commands. This parameter is the name or the ID of the
7+
network QoS policy to attach to this network.
8+
[Bug `1627069 <https://bugs.launchpad.net/python-openstackclient/+bug/1627069>`_]

0 commit comments

Comments
 (0)