@@ -393,7 +393,10 @@ def get_parser(self, prog_name):
393393 "net-id: attach NIC to network with this UUID, "
394394 "port-id: attach NIC to port with this UUID, "
395395 "v4-fixed-ip: IPv4 fixed address for NIC (optional), "
396- "v6-fixed-ip: IPv6 fixed address for NIC (optional)." ),
396+ "v6-fixed-ip: IPv6 fixed address for NIC (optional), "
397+ "none: (v2.37+) no network is attached, "
398+ "auto: (v2.37+) the compute service will automatically "
399+ "allocate a network." ),
397400 )
398401 parser .add_argument (
399402 '--hint' ,
@@ -513,36 +516,39 @@ def take_action(self, parsed_args):
513516 block_device_mapping .update ({dev_key : block_volume })
514517
515518 nics = []
516- for nic_str in parsed_args .nic :
517- nic_info = {"net-id" : "" , "v4-fixed-ip" : "" ,
518- "v6-fixed-ip" : "" , "port-id" : "" }
519- nic_info .update (dict (kv_str .split ("=" , 1 )
520- for kv_str in nic_str .split ("," )))
521- if bool (nic_info ["net-id" ]) == bool (nic_info ["port-id" ]):
522- msg = _ ("either net-id or port-id should be specified "
523- "but not both" )
524- raise exceptions .CommandError (msg )
525- if self .app .client_manager .is_network_endpoint_enabled ():
526- network_client = self .app .client_manager .network
527- if nic_info ["net-id" ]:
528- net = network_client .find_network (
529- nic_info ["net-id" ], ignore_missing = False )
530- nic_info ["net-id" ] = net .id
531- if nic_info ["port-id" ]:
532- port = network_client .find_port (
533- nic_info ["port-id" ], ignore_missing = False )
534- nic_info ["port-id" ] = port .id
535- else :
536- if nic_info ["net-id" ]:
537- nic_info ["net-id" ] = utils .find_resource (
538- compute_client .networks ,
539- nic_info ["net-id" ]
540- ).id
541- if nic_info ["port-id" ]:
542- msg = _ ("can't create server with port specified "
543- "since network endpoint not enabled" )
519+ if parsed_args .nic in ('auto' , 'none' ):
520+ nics = [parsed_args .nic ]
521+ else :
522+ for nic_str in parsed_args .nic :
523+ nic_info = {"net-id" : "" , "v4-fixed-ip" : "" ,
524+ "v6-fixed-ip" : "" , "port-id" : "" }
525+ nic_info .update (dict (kv_str .split ("=" , 1 )
526+ for kv_str in nic_str .split ("," )))
527+ if bool (nic_info ["net-id" ]) == bool (nic_info ["port-id" ]):
528+ msg = _ ("either net-id or port-id should be specified "
529+ "but not both" )
544530 raise exceptions .CommandError (msg )
545- nics .append (nic_info )
531+ if self .app .client_manager .is_network_endpoint_enabled ():
532+ network_client = self .app .client_manager .network
533+ if nic_info ["net-id" ]:
534+ net = network_client .find_network (
535+ nic_info ["net-id" ], ignore_missing = False )
536+ nic_info ["net-id" ] = net .id
537+ if nic_info ["port-id" ]:
538+ port = network_client .find_port (
539+ nic_info ["port-id" ], ignore_missing = False )
540+ nic_info ["port-id" ] = port .id
541+ else :
542+ if nic_info ["net-id" ]:
543+ nic_info ["net-id" ] = utils .find_resource (
544+ compute_client .networks ,
545+ nic_info ["net-id" ]
546+ ).id
547+ if nic_info ["port-id" ]:
548+ msg = _ ("can't create server with port specified "
549+ "since network endpoint not enabled" )
550+ raise exceptions .CommandError (msg )
551+ nics .append (nic_info )
546552
547553 hints = {}
548554 for hint in parsed_args .hint :
0 commit comments