@@ -110,6 +110,16 @@ def _get_ip_address(addresses, address_type, ip_address_family):
110110 )
111111
112112
113+ def _prefix_checked_value (prefix ):
114+ def func (value ):
115+ if ',' in value or '=' in value :
116+ msg = _ ("Invalid argument %s, "
117+ "characters ',' and '=' are not allowed" ) % value
118+ raise argparse .ArgumentTypeError (msg )
119+ return prefix + value
120+ return func
121+
122+
113123def _prep_server_detail (compute_client , image_client , server ):
114124 """Prepare the detailed server dict for printing
115125
@@ -447,7 +457,6 @@ def get_parser(self, prog_name):
447457 metavar = "<net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,"
448458 "port-id=port-uuid,auto,none>" ,
449459 action = 'append' ,
450- default = [],
451460 help = _ ("Create a NIC on the server. "
452461 "Specify option multiple times to create multiple NICs. "
453462 "Either net-id or port-id must be provided, but not both. "
@@ -460,6 +469,28 @@ def get_parser(self, prog_name):
460469 "allocate a network. Specifying a --nic of auto or none "
461470 "cannot be used with any other --nic value." ),
462471 )
472+ parser .add_argument (
473+ '--network' ,
474+ metavar = "<network>" ,
475+ action = 'append' ,
476+ dest = 'nic' ,
477+ type = _prefix_checked_value ('net-id=' ),
478+ help = _ ("Create a NIC on the server and connect it to network. "
479+ "Specify option multiple times to create multiple NICs. "
480+ "For more options on NICs see --nic parameter. "
481+ "network: attach NIC to this network " ),
482+ )
483+ parser .add_argument (
484+ '--port' ,
485+ metavar = "<port>" ,
486+ action = 'append' ,
487+ dest = 'nic' ,
488+ type = _prefix_checked_value ('port-id=' ),
489+ help = _ ("Create a NIC on the server and connect it to port. "
490+ "Specify option multiple times to create multiple NICs. "
491+ "For more options on NICs see --nic parameter. "
492+ "port: attach NIC this port " ),
493+ )
463494 parser .add_argument (
464495 '--hint' ,
465496 metavar = '<key=value>' ,
@@ -592,6 +623,8 @@ def take_action(self, parsed_args):
592623
593624 nics = []
594625 auto_or_none = False
626+ if parsed_args .nic is None :
627+ parsed_args .nic = []
595628 for nic_str in parsed_args .nic :
596629 # Handle the special auto/none cases
597630 if nic_str in ('auto' , 'none' ):
@@ -607,7 +640,7 @@ def take_action(self, parsed_args):
607640 msg = _ ('Invalid --nic argument %s.' ) % nic_str
608641 raise exceptions .CommandError (msg )
609642 if bool (nic_info ["net-id" ]) == bool (nic_info ["port-id" ]):
610- msg = _ ("either net-id or port-id should be specified "
643+ msg = _ ("either network or port should be specified "
611644 "but not both" )
612645 raise exceptions .CommandError (msg )
613646 if self .app .client_manager .is_network_endpoint_enabled ():
@@ -636,7 +669,8 @@ def take_action(self, parsed_args):
636669 if auto_or_none :
637670 if len (nics ) > 1 :
638671 msg = _ ('Specifying a --nic of auto or none cannot '
639- 'be used with any other --nic value.' )
672+ 'be used with any other --nic, --network '
673+ 'or --port value.' )
640674 raise exceptions .CommandError (msg )
641675 nics = nics [0 ]
642676 else :
0 commit comments