Skip to content

Commit 74a7c1d

Browse files
committed
Add description field to portforwarding NAT rules
Add the `description` field to Floating IP Port Forwardings Depends-On: https://review.opendev.org/#/c/705038/ Change-Id: I6477368e32570c96cacddba4f86455262e533277 Implements: blueprint portforwarding-description Closes-Bug: #1850818
1 parent 70f1ff3 commit 74a7c1d

6 files changed

Lines changed: 44 additions & 4 deletions

File tree

lower-constraints.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fixtures==3.0.0
2424
flake8-import-order==0.13
2525
flake8==2.6.2
2626
future==0.16.0
27-
futurist==1.2.0
27+
futurist==2.1.0
2828
gitdb==0.6.4
2929
GitPython==1.0.1
3030
gnocchiclient==3.3.1
@@ -50,7 +50,7 @@ msgpack-python==0.4.0
5050
munch==2.1.0
5151
netaddr==0.7.18
5252
netifaces==0.10.4
53-
openstacksdk==0.38.0
53+
openstacksdk==0.44.0
5454
os-client-config==1.28.0
5555
os-service-types==1.7.0
5656
os-testr==1.0.0

openstackclient/network/v2/floating_ip_port_forwarding.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ def get_parser(self, prog_name):
7575
required=True,
7676
help=_("The protocol used in the floating IP "
7777
"port forwarding, for instance: TCP, UDP")
78+
),
79+
parser.add_argument(
80+
'--description',
81+
metavar='<description>',
82+
help=_("A text to describe/contextualize the use of the "
83+
"port forwarding configuration")
7884
)
7985
parser.add_argument(
8086
'floating_ip',
@@ -113,6 +119,9 @@ def take_action(self, parsed_args):
113119
attrs['internal_ip_address'] = parsed_args.internal_ip_address
114120
attrs['protocol'] = parsed_args.protocol
115121

122+
if parsed_args.description is not None:
123+
attrs['description'] = parsed_args.description
124+
116125
obj = client.create_floating_ip_port_forwarding(
117126
floating_ip.id,
118127
**attrs
@@ -212,6 +221,7 @@ def take_action(self, parsed_args):
212221
'internal_port',
213222
'external_port',
214223
'protocol',
224+
'description',
215225
)
216226
headers = (
217227
'ID',
@@ -220,6 +230,7 @@ def take_action(self, parsed_args):
220230
'Internal Port',
221231
'External Port',
222232
'Protocol',
233+
'Description',
223234
)
224235

225236
query = {}
@@ -296,6 +307,12 @@ def get_parser(self, prog_name):
296307
metavar='<protocol>',
297308
choices=['tcp', 'udp'],
298309
help=_("The IP protocol used in the floating IP port forwarding")
310+
),
311+
parser.add_argument(
312+
'--description',
313+
metavar='<description>',
314+
help=_("A text to describe/contextualize the use of "
315+
"the port forwarding configuration")
299316
)
300317

301318
return parser
@@ -332,6 +349,9 @@ def take_action(self, parsed_args):
332349
if parsed_args.protocol:
333350
attrs['protocol'] = parsed_args.protocol
334351

352+
if parsed_args.description is not None:
353+
attrs['description'] = parsed_args.description
354+
335355
client.update_floating_ip_port_forwarding(
336356
floating_ip.id, parsed_args.port_forwarding_id, **attrs)
337357

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,7 @@ def create_one_port_forwarding(attrs=None):
18431843
'internal_port': randint(1, 65535),
18441844
'external_port': randint(1, 65535),
18451845
'protocol': 'tcp',
1846+
'description': 'some description',
18461847
}
18471848

18481849
# Overwrite default attributes.

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def setUp(self):
6262
self.app, self.namespace)
6363

6464
self.columns = (
65+
'description',
6566
'external_port',
6667
'floatingip_id',
6768
'id',
@@ -73,6 +74,7 @@ def setUp(self):
7374
)
7475

7576
self.data = (
77+
self.new_port_forwarding.description,
7678
self.new_port_forwarding.external_port,
7779
self.new_port_forwarding.floatingip_id,
7880
self.new_port_forwarding.id,
@@ -102,6 +104,8 @@ def test_create_all_options(self):
102104
self.new_port_forwarding.floatingip_id,
103105
'--internal-ip-address',
104106
self.new_port_forwarding.internal_ip_address,
107+
'--description',
108+
self.new_port_forwarding.description,
105109
]
106110
verifylist = [
107111
('port', self.new_port_forwarding.internal_port_id),
@@ -111,6 +115,7 @@ def test_create_all_options(self):
111115
('floating_ip', self.new_port_forwarding.floatingip_id),
112116
('internal_ip_address', self.new_port_forwarding.
113117
internal_ip_address),
118+
('description', self.new_port_forwarding.description),
114119
]
115120
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
116121
columns, data = self.cmd.take_action(parsed_args)
@@ -126,6 +131,7 @@ def test_create_all_options(self):
126131
'internal_port_id': self.new_port_forwarding.
127132
internal_port_id,
128133
'protocol': self.new_port_forwarding.protocol,
134+
'description': self.new_port_forwarding.description,
129135
})
130136
self.assertEqual(self.columns, columns)
131137
self.assertEqual(self.data, data)
@@ -251,7 +257,8 @@ class TestListFloatingIPPortForwarding(TestFloatingIPPortForwarding):
251257
'Internal IP Address',
252258
'Internal Port',
253259
'External Port',
254-
'Protocol'
260+
'Protocol',
261+
'Description',
255262
)
256263

257264
def setUp(self):
@@ -273,6 +280,7 @@ def setUp(self):
273280
port_forwarding.internal_port,
274281
port_forwarding.external_port,
275282
port_forwarding.protocol,
283+
port_forwarding.description,
276284
))
277285
self.network.floating_ip_port_forwardings = mock.Mock(
278286
return_value=self.port_forwardings
@@ -393,6 +401,7 @@ def test_set_all_thing(self):
393401
'--internal-protocol-port', '100',
394402
'--external-protocol-port', '200',
395403
'--protocol', 'tcp',
404+
'--description', 'some description',
396405
self._port_forwarding.floatingip_id,
397406
self._port_forwarding.id,
398407
]
@@ -402,6 +411,7 @@ def test_set_all_thing(self):
402411
('internal_protocol_port', 100),
403412
('external_protocol_port', 200),
404413
('protocol', 'tcp'),
414+
('description', 'some description'),
405415
('floating_ip', self._port_forwarding.floatingip_id),
406416
('port_forwarding_id', self._port_forwarding.id),
407417
]
@@ -415,6 +425,7 @@ def test_set_all_thing(self):
415425
'internal_port': 100,
416426
'external_port': 200,
417427
'protocol': 'tcp',
428+
'description': 'some description',
418429
}
419430
self.network.update_floating_ip_port_forwarding.assert_called_with(
420431
self._port_forwarding.floatingip_id,
@@ -428,6 +439,7 @@ class TestShowFloatingIPPortForwarding(TestFloatingIPPortForwarding):
428439

429440
# The port forwarding to show.
430441
columns = (
442+
'description',
431443
'external_port',
432444
'floatingip_id',
433445
'id',
@@ -450,6 +462,7 @@ def setUp(self):
450462
)
451463
)
452464
self.data = (
465+
self._port_forwarding.description,
453466
self._port_forwarding.external_port,
454467
self._port_forwarding.floatingip_id,
455468
self._port_forwarding.id,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Add a new option `--description` to
5+
``floating ip port forwarding create`` and
6+
``floating ip port forwarding set`` commands.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ six>=1.10.0 # MIT
66

77
Babel!=2.4.0,>=2.3.4 # BSD
88
cliff!=2.9.0,>=2.8.0 # Apache-2.0
9-
openstacksdk>=0.38.0 # Apache-2.0
9+
openstacksdk>=0.44.0 # Apache-2.0
1010
osc-lib>=2.0.0 # Apache-2.0
1111
oslo.i18n>=3.15.3 # Apache-2.0
1212
oslo.utils>=3.33.0 # Apache-2.0

0 commit comments

Comments
 (0)