@@ -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+
253264class 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