@@ -409,8 +409,8 @@ def get_parser(self, prog_name):
409409 '--tag' ,
410410 metavar = '<tag>' ,
411411 help = _ (
412- " Tag for the attached interface. "
413- "(Supported by API versions ' 2.49' - '2.latest')"
412+ ' Tag for the attached interface '
413+ '(supported by --os-compute-api-version 2.49 or later)'
414414 )
415415 )
416416 return parser
@@ -652,29 +652,68 @@ def take_action(self, parsed_args):
652652 )
653653
654654
655- # TODO(stephenfin): Replace with 'MultiKeyValueAction' when we no longer
656- # support '--nic=auto' and '--nic=none'
655+ class NoneNICAction (argparse .Action ):
656+
657+ def __init__ (self , option_strings , dest , help = None ):
658+ super ().__init__ (
659+ option_strings = option_strings ,
660+ dest = dest ,
661+ nargs = 0 ,
662+ default = [],
663+ required = False ,
664+ help = help ,
665+ )
666+
667+ def __call__ (self , parser , namespace , values , option_string = None ):
668+ # Make sure we have an empty dict rather than None
669+ if getattr (namespace , self .dest , None ) is None :
670+ setattr (namespace , self .dest , [])
671+
672+ getattr (namespace , self .dest ).append ('none' )
673+
674+
675+ class AutoNICAction (argparse .Action ):
676+
677+ def __init__ (self , option_strings , dest , help = None ):
678+ super ().__init__ (
679+ option_strings = option_strings ,
680+ dest = dest ,
681+ nargs = 0 ,
682+ default = [],
683+ required = False ,
684+ help = help ,
685+ )
686+
687+ def __call__ (self , parser , namespace , values , option_string = None ):
688+ # Make sure we have an empty dict rather than None
689+ if getattr (namespace , self .dest , None ) is None :
690+ setattr (namespace , self .dest , [])
691+
692+ getattr (namespace , self .dest ).append ('auto' )
693+
694+
657695class NICAction (argparse .Action ):
658696
659697 def __init__ (
660698 self ,
661699 option_strings ,
662700 dest ,
663- nargs = None ,
664- const = None ,
665- default = None ,
666- type = None ,
667- choices = None ,
668- required = False ,
669701 help = None ,
670702 metavar = None ,
671703 key = None ,
672704 ):
673705 self .key = key
674706 super ().__init__ (
675- option_strings = option_strings , dest = dest , nargs = nargs , const = const ,
676- default = default , type = type , choices = choices , required = required ,
677- help = help , metavar = metavar ,
707+ option_strings = option_strings ,
708+ dest = dest ,
709+ nargs = None ,
710+ const = None ,
711+ default = [],
712+ type = None ,
713+ choices = None ,
714+ required = False ,
715+ help = help ,
716+ metavar = metavar ,
678717 )
679718
680719 def __call__ (self , parser , namespace , values , option_string = None ):
@@ -707,7 +746,7 @@ def __call__(self, parser, namespace, values, option_string=None):
707746 }
708747
709748 for kv_str in values .split (',' ):
710- k , sep , v = kv_str .partition ("=" )
749+ k , sep , v = kv_str .partition ('=' )
711750
712751 if k not in list (info ) + ['tag' ] or not v :
713752 msg = _ (
@@ -998,28 +1037,23 @@ def get_parser(self, prog_name):
9981037 )
9991038 parser .add_argument (
10001039 '--network' ,
1001- metavar = " <network>" ,
1040+ metavar = ' <network>' ,
10021041 dest = 'nics' ,
1003- default = [],
10041042 action = NICAction ,
10051043 key = 'net-id' ,
1006- # NOTE(RuiChen): Add '\n' to the end of line to improve formatting;
1007- # see cliff's _SmartHelpFormatter for more details.
10081044 help = _ (
10091045 "Create a NIC on the server and connect it to network. "
10101046 "Specify option multiple times to create multiple NICs. "
10111047 "This is a wrapper for the '--nic net-id=<network>' "
10121048 "parameter that provides simple syntax for the standard "
10131049 "use case of connecting a new server to a given network. "
1014- "For more advanced use cases, refer to the '--nic' "
1015- "parameter."
1050+ "For more advanced use cases, refer to the '--nic' parameter."
10161051 ),
10171052 )
10181053 parser .add_argument (
10191054 '--port' ,
1020- metavar = " <port>" ,
1055+ metavar = ' <port>' ,
10211056 dest = 'nics' ,
1022- default = [],
10231057 action = NICAction ,
10241058 key = 'port-id' ,
10251059 help = _ (
@@ -1031,13 +1065,41 @@ def get_parser(self, prog_name):
10311065 "more advanced use cases, refer to the '--nic' parameter."
10321066 ),
10331067 )
1068+ parser .add_argument (
1069+ '--no-network' ,
1070+ dest = 'nics' ,
1071+ action = NoneNICAction ,
1072+ help = _ (
1073+ "Do not attach a network to the server. "
1074+ "This is a wrapper for the '--nic none' option that provides "
1075+ "a simple syntax for disabling network connectivity for a new "
1076+ "server. "
1077+ "For more advanced use cases, refer to the '--nic' parameter. "
1078+ "(supported by --os-compute-api-version 2.37 or above)"
1079+ ),
1080+ )
1081+ parser .add_argument (
1082+ '--auto-network' ,
1083+ dest = 'nics' ,
1084+ action = AutoNICAction ,
1085+ help = _ (
1086+ "Automatically allocate a network to the server. "
1087+ "This is the default network allocation policy. "
1088+ "This is a wrapper for the '--nic auto' option that provides "
1089+ "a simple syntax for enabling automatic configuration of "
1090+ "network connectivity for a new server. "
1091+ "For more advanced use cases, refer to the '--nic' parameter. "
1092+ "(supported by --os-compute-api-version 2.37 or above)"
1093+ ),
1094+ )
10341095 parser .add_argument (
10351096 '--nic' ,
10361097 metavar = "<net-id=net-uuid,port-id=port-uuid,v4-fixed-ip=ip-addr,"
10371098 "v6-fixed-ip=ip-addr,tag=tag,auto,none>" ,
1038- action = NICAction ,
10391099 dest = 'nics' ,
1040- default = [],
1100+ action = NICAction ,
1101+ # NOTE(RuiChen): Add '\n' to the end of line to improve formatting;
1102+ # see cliff's _SmartHelpFormatter for more details.
10411103 help = _ (
10421104 "Create a NIC on the server.\n "
10431105 "NIC in the format:\n "
0 commit comments