@@ -97,6 +97,7 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
9797 var enableSSH bool
9898 var addGPU bool
9999 var profiles []string
100+ var validBridges []string
100101
101102 proceed , err := launchForm (app , application .Description , accessible )
102103 if err != nil {
@@ -106,6 +107,16 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
106107 log .Error ("Instance creation cancelled" )
107108 return nil
108109 }
110+ networks , err := c .global .client .Networks (context .Background ())
111+ if err != nil {
112+ return err
113+ }
114+ for _ , net := range networks {
115+ if net .Type == "bridge" {
116+ validBridges = append (validBridges , net .Name )
117+ }
118+
119+ }
109120
110121 // if it isn't a vm specific application, ask if they want to use the advanced form
111122 if ! launchSettings .VM {
@@ -288,6 +299,40 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
288299 launchSettings .SSHAuthorizedKey = string (bb )
289300 }
290301
302+ var chooseBridge bool
303+ // choose advanced network options
304+ form = huh .NewForm (
305+ huh .NewGroup (
306+ huh .NewConfirm ().
307+ Title ("Choose a bridge?" ).
308+ Value (& chooseBridge ).
309+ Affirmative ("Yes" ).
310+ Negative ("No" ),
311+ ),
312+ ).WithAccessible (accessible )
313+
314+ err = form .Run ()
315+ if err != nil {
316+ fmt .Println ("form error:" , err )
317+ os .Exit (1 )
318+ }
319+
320+ if chooseBridge {
321+ form = huh .NewForm (
322+ huh .NewGroup (
323+ huh .NewSelect [string ]().
324+ Value (& launchSettings .Network ).
325+ Title ("Choose Network Bridge" ).
326+ Options (huh .NewOptions [string ](validBridges ... )... ).
327+ Description ("Select an existing network bridge for the instance." ),
328+ ),
329+ ).WithAccessible (accessible )
330+ err = form .Run ()
331+ if err != nil {
332+ fmt .Println ("form error:" , err )
333+ os .Exit (1 )
334+ }
335+ }
291336 // select profiles
292337 profileList , err := c .global .client .ProfileNames (context .Background ())
293338 if err != nil {
@@ -303,13 +348,16 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
303348 // add "default" profile back at the beginning
304349 profileList = append ([]string {"default" }, profileList ... )
305350
351+ var chooseProfiles bool
352+ // choose advanced network options
306353 form = huh .NewForm (
307354 huh .NewGroup (
308- huh .NewMultiSelect [string ]().
309- Options (huh .NewOptions (profileList ... )... ).
310- Title ("Select Additional Incus Profiles" ).
311- Value (& profiles ).
312- Description ("*default* profile should usually be included." ),
355+ huh .NewConfirm ().
356+ Title ("Choose incus profiles?" ).
357+ Value (& chooseProfiles ).
358+ Affirmative ("Yes" ).
359+ Negative ("No" ).
360+ Description ("Select NO to use only the default profile." ),
313361 ),
314362 ).WithAccessible (accessible )
315363
@@ -318,6 +366,23 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
318366 fmt .Println ("form error:" , err )
319367 os .Exit (1 )
320368 }
369+ if chooseProfiles {
370+ form = huh .NewForm (
371+ huh .NewGroup (
372+ huh .NewMultiSelect [string ]().
373+ Options (huh .NewOptions (profileList ... )... ).
374+ Title ("Select Additional Incus Profiles" ).
375+ Value (& profiles ).
376+ Description ("*default* profile should usually be included." ),
377+ ),
378+ ).WithAccessible (accessible )
379+
380+ err = form .Run ()
381+ if err != nil {
382+ fmt .Println ("form error:" , err )
383+ os .Exit (1 )
384+ }
385+ }
321386 launchSettings .Profiles = profiles
322387
323388 }
@@ -416,7 +481,7 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
416481
417482 createInstance := func () {
418483 // create the instance
419- err := c .global .client .Launch (launchSettings .Image , launchSettings .Name , launchSettings .Profiles , extraConfigs , deviceOverrides , launchSettings .VM , false )
484+ err := c .global .client .Launch (launchSettings .Image , launchSettings .Name , launchSettings .Profiles , extraConfigs , deviceOverrides , launchSettings .Network , launchSettings . VM , false )
420485 if err != nil {
421486 fmt .Println ("Error creating instance:" , err )
422487 os .Exit (1 )
0 commit comments