Skip to content

Commit ade841f

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add 'allowed address pairs' option to 'port create/set/unset'"
2 parents 43f9370 + 8bcfb82 commit ade841f

4 files changed

Lines changed: 310 additions & 4 deletions

File tree

doc/source/command-objects/port.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Create new port
2929
[--mac-address <mac-address>]
3030
[--security-group <security-group> | --no-security-group]
3131
[--dns-name <dns-name>]
32+
[--allowed-address ip-address=<ip-address>[,mac-address=<mac-address>]]
3233
[--project <project> [--project-domain <project-domain>]]
3334
[--enable-port-security | --disable-port-security]
3435
<name>
@@ -97,6 +98,12 @@ Create new port
9798
Set DNS name to this port
9899
(requires DNS integration extension)
99100
101+
.. option:: --allowed-address ip-address=<ip-address>[,mac-address=<mac-address>]
102+
103+
Add allowed-address pair associated with this port:
104+
ip-address=<ip-address>[,mac-address=<mac-address>]
105+
(repeat option to set multiple allowed-address pairs)
106+
100107
.. option:: --project <project>
101108
102109
Owner's project (name or ID)
@@ -199,6 +206,8 @@ Set port properties
199206
[--no-security-group]
200207
[--enable-port-security | --disable-port-security]
201208
[--dns-name <dns-name>]
209+
[--allowed-address ip-address=<ip-address>[,mac-address=<mac-address>]]
210+
[--no-allowed-address]
202211
<port>
203212
204213
.. option:: --description <description>
@@ -281,6 +290,19 @@ Set port properties
281290
Set DNS name to this port
282291
(requires DNS integration extension)
283292
293+
.. option:: --allowed-address ip-address=<ip-address>[,mac-address=<mac-address>]
294+
295+
Add allowed-address pair associated with this port:
296+
ip-address=<ip-address>[,mac-address=<mac-address>]
297+
(repeat option to set multiple allowed-address pairs)
298+
299+
.. option:: --no-allowed-address
300+
301+
Clear existing allowed-address pairs associated
302+
with this port.
303+
(Specify both --allowed-address and --no-allowed-address
304+
to overwrite the current allowed-address pairs)
305+
284306
.. _port_set-port:
285307
.. describe:: <port>
286308
@@ -314,6 +336,7 @@ Unset port properties
314336
[--fixed-ip subnet=<subnet>,ip-address=<ip-address> [...]]
315337
[--binding-profile <binding-profile-key> [...]]
316338
[--security-group <security-group> [...]]
339+
[--allowed-address ip-address=<ip-address>[,mac-address=<mac-address>] [...]]
317340
<port>
318341
319342
.. option:: --fixed-ip subnet=<subnet>,ip-address=<ip-address>
@@ -332,6 +355,12 @@ Unset port properties
332355
Security group which should be removed from this port (name or ID)
333356
(repeat option to unset multiple security groups)
334357
358+
.. option:: --allowed-address ip-address=<ip-address>[,mac-address=<mac-address>]
359+
360+
Desired allowed-address pair which should be removed from this port:
361+
ip-address=<ip-address>[,mac-address=<mac-address>]
362+
(repeat option to unset multiple allowed-address pairs)
363+
335364
.. _port_unset-port:
336365
.. describe:: <port>
337366

openstackclient/network/v2/port.py

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ def _add_updatable_args(parser):
250250

251251
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
252252
# OSC minimum requirements include SDK 1.0.
253+
def _convert_address_pairs(parsed_args):
254+
ops = []
255+
for opt in parsed_args.allowed_address_pairs:
256+
addr = {}
257+
addr['ip_address'] = opt['ip-address']
258+
if 'mac-address' in opt:
259+
addr['mac_address'] = opt['mac-address']
260+
ops.append(addr)
261+
return ops
262+
263+
253264
class CreatePort(command.ShowOne):
254265
_description = _("Create a new port")
255266

@@ -309,7 +320,7 @@ def get_parser(self, prog_name):
309320
help=_("Name of this port")
310321
)
311322
# TODO(singhj): Add support for extended options:
312-
# qos,dhcp, address pairs
323+
# qos,dhcp
313324
secgroups = parser.add_mutually_exclusive_group()
314325
secgroups.add_argument(
315326
'--security-group',
@@ -336,7 +347,17 @@ def get_parser(self, prog_name):
336347
action='store_true',
337348
help=_("Disable port security for this port")
338349
)
339-
350+
parser.add_argument(
351+
'--allowed-address',
352+
metavar='ip-address=<ip-address>[,mac-address=<mac-address>]',
353+
action=parseractions.MultiKeyValueAction,
354+
dest='allowed_address_pairs',
355+
required_keys=['ip-address'],
356+
optional_keys=['mac-address'],
357+
help=_("Add allowed-address pair associated with this port: "
358+
"ip-address=<ip-address>[,mac-address=<mac-address>] "
359+
"(repeat option to set multiple allowed-address pairs)")
360+
)
340361
return parser
341362

342363
def take_action(self, parsed_args):
@@ -353,6 +374,9 @@ def take_action(self, parsed_args):
353374
for sg in parsed_args.security_groups]
354375
if parsed_args.no_security_group:
355376
attrs['security_groups'] = []
377+
if parsed_args.allowed_address_pairs:
378+
attrs['allowed_address_pairs'] = (
379+
_convert_address_pairs(parsed_args))
356380

357381
obj = client.create_port(**attrs)
358382
display_columns, columns = _get_columns(obj)
@@ -573,7 +597,26 @@ def get_parser(self, prog_name):
573597
action='store_true',
574598
help=_("Disable port security for this port")
575599
)
576-
600+
parser.add_argument(
601+
'--allowed-address',
602+
metavar='ip-address=<ip-address>[,mac-address=<mac-address>]',
603+
action=parseractions.MultiKeyValueAction,
604+
dest='allowed_address_pairs',
605+
required_keys=['ip-address'],
606+
optional_keys=['mac-address'],
607+
help=_("Add allowed-address pair associated with this port: "
608+
"ip-address=<ip-address>[,mac-address=<mac-address>] "
609+
"(repeat option to set multiple allowed-address pairs)")
610+
)
611+
parser.add_argument(
612+
'--no-allowed-address',
613+
dest='no_allowed_address_pair',
614+
action='store_true',
615+
help=_("Clear existing allowed-address pairs associated"
616+
"with this port."
617+
"(Specify both --allowed-address and --no-allowed-address"
618+
"to overwrite the current allowed-address pairs)")
619+
)
577620
return parser
578621

579622
def take_action(self, parsed_args):
@@ -613,6 +656,19 @@ def take_action(self, parsed_args):
613656
elif parsed_args.no_security_group:
614657
attrs['security_groups'] = []
615658

659+
if (parsed_args.allowed_address_pairs and
660+
parsed_args.no_allowed_address_pair):
661+
attrs['allowed_address_pairs'] = (
662+
_convert_address_pairs(parsed_args))
663+
664+
elif parsed_args.allowed_address_pairs:
665+
attrs['allowed_address_pairs'] = (
666+
[addr for addr in obj.allowed_address_pairs if addr] +
667+
_convert_address_pairs(parsed_args))
668+
669+
elif parsed_args.no_allowed_address_pair:
670+
attrs['allowed_address_pairs'] = []
671+
616672
client.update_port(obj, **attrs)
617673

618674

@@ -673,6 +729,19 @@ def get_parser(self, prog_name):
673729
metavar="<port>",
674730
help=_("Port to modify (name or ID)")
675731
)
732+
parser.add_argument(
733+
'--allowed-address',
734+
metavar='ip-address=<ip-address>[,mac-address=<mac-address>]',
735+
action=parseractions.MultiKeyValueAction,
736+
dest='allowed_address_pairs',
737+
required_keys=['ip-address'],
738+
optional_keys=['mac-address'],
739+
help=_("Desired allowed-address pair which should be removed "
740+
"from this port: ip-address=<ip-address> "
741+
"[,mac-address=<mac-address>] (repeat option to set "
742+
"multiple allowed-address pairs)")
743+
)
744+
676745
return parser
677746

678747
def take_action(self, parsed_args):
@@ -684,6 +753,7 @@ def take_action(self, parsed_args):
684753
tmp_fixed_ips = copy.deepcopy(obj.fixed_ips)
685754
tmp_binding_profile = copy.deepcopy(obj.binding_profile)
686755
tmp_secgroups = copy.deepcopy(obj.security_groups)
756+
tmp_addr_pairs = copy.deepcopy(obj.allowed_address_pairs)
687757
_prepare_fixed_ips(self.app.client_manager, parsed_args)
688758
attrs = {}
689759
if parsed_args.fixed_ip:
@@ -712,6 +782,14 @@ def take_action(self, parsed_args):
712782
msg = _("Port does not contain security group %s") % sg
713783
raise exceptions.CommandError(msg)
714784
attrs['security_groups'] = tmp_secgroups
785+
if parsed_args.allowed_address_pairs:
786+
try:
787+
for addr in _convert_address_pairs(parsed_args):
788+
tmp_addr_pairs.remove(addr)
789+
except ValueError:
790+
msg = _("Port does not contain allowed-address-pair %s") % addr
791+
raise exceptions.CommandError(msg)
792+
attrs['allowed_address_pairs'] = tmp_addr_pairs
715793

716794
if attrs:
717795
client.update_port(obj, **attrs)

0 commit comments

Comments
 (0)