Skip to content

Commit cf91d7a

Browse files
gotostackDean Troyer
authored andcommitted
Add floating IP qos_policy actions
Now we can associate a qos policy to the floating IP, and dissociate it. The commands are: $ openstack floating ip create --qos-policy ... $ openstack floating ip set --qos-policy ... $ openstack floating ip set --no-qos-policy ... $ openstack floating ip unset --qos-policy These commands are based on the neutron change: I4efe9e49d268dffeb3df4de4ea1780152218633b Partially-Implements blueprint: floating-ip-rate-limit Change-Id: I932b32f78cc5a2b53926feaec1a0b392cf7e8b57
1 parent b13a323 commit cf91d7a

5 files changed

Lines changed: 201 additions & 3 deletions

File tree

doc/source/cli/command-objects/floating-ip.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Create floating IP
1818
[--floating-ip-address <ip-address>]
1919
[--fixed-ip-address <ip-address>]
2020
[--description <description>]
21+
[--qos-policy <qos-policy>]
2122
[--project <project> [--project-domain <project-domain>]]
2223
<network>
2324
@@ -46,6 +47,12 @@ Create floating IP
4647
Set floating IP description
4748
*Network version 2 only*
4849
50+
.. option:: --qos-policy <qos-policy>
51+
52+
QoS policy to attach to the floating IP (name or ID)
53+
54+
*Network version 2 only*
55+
4956
.. option:: --project <project>
5057
5158
Owner's project (name or ID)
@@ -154,6 +161,7 @@ Set floating IP properties
154161
openstack floating ip set
155162
--port <port>
156163
[--fixed-ip-address <ip-address>]
164+
[--qos-policy <qos-policy> | --no-qos-policy]
157165
<floating-ip>
158166
159167
.. option:: --port <port>
@@ -164,6 +172,14 @@ Set floating IP properties
164172
165173
Fixed IP of the port (required only if port has multiple IPs)
166174
175+
.. option:: --qos-policy <qos-policy>
176+
177+
Attach QoS policy to the floating IP (name or ID)
178+
179+
.. option:: --no-qos-policy
180+
181+
Remove the QoS policy attached to the floating IP
182+
167183
.. _floating_ip_set-floating-ip:
168184
.. describe:: <floating-ip>
169185
@@ -193,12 +209,17 @@ Unset floating IP Properties
193209
194210
openstack floating ip unset
195211
--port
212+
--qos-policy
196213
<floating-ip>
197214
198215
.. option:: --port
199216
200217
Disassociate any port associated with the floating IP
201218
219+
.. option:: --qos-policy
220+
221+
Remove the QoS policy attached to the floating IP
222+
202223
.. _floating_ip_unset-floating-ip:
203224
.. describe:: <floating-ip>
204225

openstackclient/network/v2/floating_ip.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def _get_attrs(client_manager, parsed_args):
6767
if parsed_args.fixed_ip_address:
6868
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
6969

70+
if parsed_args.qos_policy:
71+
attrs['qos_policy_id'] = network_client.find_qos_policy(
72+
parsed_args.qos_policy, ignore_missing=False).id
73+
7074
if parsed_args.description is not None:
7175
attrs['description'] = parsed_args.description
7276

@@ -169,6 +173,11 @@ def update_parser_network(self, parser):
169173
dest='fixed_ip_address',
170174
help=_("Fixed IP address mapped to the floating IP")
171175
)
176+
parser.add_argument(
177+
'--qos-policy',
178+
metavar='<qos-policy>',
179+
help=_("Attach QoS policy to the floating IP (name or ID)")
180+
)
172181
parser.add_argument(
173182
'--description',
174183
metavar='<description>',
@@ -462,6 +471,17 @@ def get_parser(self, prog_name):
462471
help=_("Fixed IP of the port "
463472
"(required only if port has multiple IPs)")
464473
)
474+
qos_policy_group = parser.add_mutually_exclusive_group()
475+
qos_policy_group.add_argument(
476+
'--qos-policy',
477+
metavar='<qos-policy>',
478+
help=_("Attach QoS policy to the floating IP (name or ID)")
479+
)
480+
qos_policy_group.add_argument(
481+
'--no-qos-policy',
482+
action='store_true',
483+
help=_("Remove the QoS policy attached to the floating IP")
484+
)
465485
return parser
466486

467487
def take_action(self, parsed_args):
@@ -479,6 +499,13 @@ def take_action(self, parsed_args):
479499
if parsed_args.fixed_ip_address:
480500
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
481501

502+
if parsed_args.qos_policy:
503+
attrs['qos_policy_id'] = client.find_qos_policy(
504+
parsed_args.qos_policy, ignore_missing=False).id
505+
506+
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
507+
attrs['qos_policy_id'] = None
508+
482509
client.update_ip(obj, **attrs)
483510

484511

@@ -549,6 +576,12 @@ def get_parser(self, prog_name):
549576
default=False,
550577
help=_("Disassociate any port associated with the floating IP")
551578
)
579+
parser.add_argument(
580+
'--qos-policy',
581+
action='store_true',
582+
default=False,
583+
help=_("Remove the QoS policy attached to the floating IP")
584+
)
552585
return parser
553586

554587
def take_action(self, parsed_args):
@@ -559,8 +592,11 @@ def take_action(self, parsed_args):
559592
parsed_args.floating_ip,
560593
ignore_missing=False,
561594
)
595+
attrs = {}
562596
if parsed_args.port:
563-
attrs = {
564-
'port_id': None,
565-
}
597+
attrs['port_id'] = None
598+
if parsed_args.qos_policy:
599+
attrs['qos_policy_id'] = None
600+
601+
if attrs:
566602
client.update_ip(obj, **attrs)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ def create_one_floating_ip(attrs=None):
13781378
'port_id': 'port-id-' + uuid.uuid4().hex,
13791379
'tenant_id': 'project-id-' + uuid.uuid4().hex,
13801380
'description': 'floating-ip-description-' + uuid.uuid4().hex,
1381+
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
13811382
}
13821383

13831384
# Overwrite default attributes.

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

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class TestCreateFloatingIPNetwork(TestFloatingIPNetwork):
6262
'id',
6363
'port_id',
6464
'project_id',
65+
'qos_policy_id',
6566
'router_id',
6667
'status',
6768
)
@@ -76,6 +77,7 @@ class TestCreateFloatingIPNetwork(TestFloatingIPNetwork):
7677
floating_ip.id,
7778
floating_ip.port_id,
7879
floating_ip.project_id,
80+
floating_ip.qos_policy_id,
7981
floating_ip.router_id,
8082
floating_ip.status,
8183
)
@@ -197,6 +199,28 @@ def test_floating_ip_create_project_domain(self):
197199
self.assertEqual(self.columns, columns)
198200
self.assertEqual(self.data, data)
199201

202+
def test_create_floating_ip_with_qos(self):
203+
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
204+
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
205+
arglist = [
206+
'--qos-policy', qos_policy.id,
207+
self.floating_ip.floating_network_id,
208+
]
209+
verifylist = [
210+
('network', self.floating_ip.floating_network_id),
211+
('qos_policy', qos_policy.id),
212+
]
213+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
214+
215+
columns, data = self.cmd.take_action(parsed_args)
216+
217+
self.network.create_ip.assert_called_once_with(**{
218+
'floating_network_id': self.floating_ip.floating_network_id,
219+
'qos_policy_id': qos_policy.id,
220+
})
221+
self.assertEqual(self.columns, columns)
222+
self.assertEqual(self.data, data)
223+
200224

201225
class TestDeleteFloatingIPNetwork(TestFloatingIPNetwork):
202226

@@ -538,6 +562,7 @@ class TestShowFloatingIPNetwork(TestFloatingIPNetwork):
538562
'id',
539563
'port_id',
540564
'project_id',
565+
'qos_policy_id',
541566
'router_id',
542567
'status',
543568
)
@@ -552,6 +577,7 @@ class TestShowFloatingIPNetwork(TestFloatingIPNetwork):
552577
floating_ip.id,
553578
floating_ip.port_id,
554579
floating_ip.project_id,
580+
floating_ip.qos_policy_id,
555581
floating_ip.router_id,
556582
floating_ip.status,
557583
)
@@ -677,6 +703,76 @@ def test_fixed_ip_option(self, find_floating_ip_mock):
677703
self.network.update_ip.assert_called_once_with(
678704
self.floating_ip, **attrs)
679705

706+
@mock.patch(
707+
"openstackclient.tests.unit.network.v2.test_floating_ip_network." +
708+
"fip._find_floating_ip"
709+
)
710+
def test_port_and_qos_policy_option(self, find_floating_ip_mock):
711+
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
712+
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
713+
find_floating_ip_mock.side_effect = [
714+
self.floating_ip,
715+
]
716+
arglist = [
717+
"--qos-policy", qos_policy.id,
718+
'--port', self.floating_ip.port_id,
719+
self.floating_ip.id,
720+
]
721+
verifylist = [
722+
('qos_policy', qos_policy.id),
723+
('port', self.floating_ip.port_id),
724+
('floating_ip', self.floating_ip.id),
725+
]
726+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
727+
728+
self.cmd.take_action(parsed_args)
729+
730+
attrs = {
731+
'qos_policy_id': qos_policy.id,
732+
'port_id': self.floating_ip.port_id,
733+
}
734+
find_floating_ip_mock.assert_called_once_with(
735+
mock.ANY,
736+
self.floating_ip.id,
737+
ignore_missing=False,
738+
)
739+
self.network.update_ip.assert_called_once_with(
740+
self.floating_ip, **attrs)
741+
742+
@mock.patch(
743+
"openstackclient.tests.unit.network.v2.test_floating_ip_network." +
744+
"fip._find_floating_ip"
745+
)
746+
def test_port_and_no_qos_policy_option(self, find_floating_ip_mock):
747+
find_floating_ip_mock.side_effect = [
748+
self.floating_ip,
749+
]
750+
arglist = [
751+
"--no-qos-policy",
752+
'--port', self.floating_ip.port_id,
753+
self.floating_ip.id,
754+
]
755+
verifylist = [
756+
('no_qos_policy', True),
757+
('port', self.floating_ip.port_id),
758+
('floating_ip', self.floating_ip.id),
759+
]
760+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
761+
762+
self.cmd.take_action(parsed_args)
763+
764+
attrs = {
765+
'qos_policy_id': None,
766+
'port_id': self.floating_ip.port_id,
767+
}
768+
find_floating_ip_mock.assert_called_once_with(
769+
mock.ANY,
770+
self.floating_ip.id,
771+
ignore_missing=False,
772+
)
773+
self.network.update_ip.assert_called_once_with(
774+
self.floating_ip, **attrs)
775+
680776

681777
class TestUnsetFloatingIP(TestFloatingIPNetwork):
682778

@@ -732,3 +828,36 @@ def test_floating_ip_unset_port(self, find_floating_ip_mock):
732828
self.floating_ip, **attrs)
733829

734830
self.assertIsNone(result)
831+
832+
@mock.patch(
833+
"openstackclient.tests.unit.network.v2.test_floating_ip_network." +
834+
"fip._find_floating_ip"
835+
)
836+
def test_floating_ip_unset_qos_policy(self, find_floating_ip_mock):
837+
find_floating_ip_mock.side_effect = [
838+
self.floating_ip,
839+
]
840+
arglist = [
841+
self.floating_ip.id,
842+
"--qos-policy",
843+
]
844+
verifylist = [
845+
('floating_ip', self.floating_ip.id),
846+
('qos_policy', True),
847+
]
848+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
849+
850+
result = self.cmd.take_action(parsed_args)
851+
852+
attrs = {
853+
'qos_policy_id': None,
854+
}
855+
find_floating_ip_mock.assert_called_once_with(
856+
mock.ANY,
857+
self.floating_ip.id,
858+
ignore_missing=False,
859+
)
860+
self.network.update_ip.assert_called_once_with(
861+
self.floating_ip, **attrs)
862+
863+
self.assertIsNone(result)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
features:
3+
- |
4+
Add support for attaching and removing qos policy to floating IPs.
5+
6+
Add option ``--qos-policy`` to the ``floating ip create`` and
7+
``floating ip set`` commands to add qos policy to a floating IP.
8+
9+
Add option ``--no-qos-policy`` to the ``floating ip set`` and option
10+
``--qos-policy`` to the ``floating ip unset`` command to remove the
11+
qos policy from a floating IP.

0 commit comments

Comments
 (0)