Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit b6b6248

Browse files
committed
feat: launch on specific network
1 parent 20c2fe2 commit b6b6248

4 files changed

Lines changed: 75 additions & 9 deletions

File tree

cli/cmd/launch.go

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

cli/cmd/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type ExecuteContext struct {
7777
type LaunchSettings struct {
7878
Name string `json:"name,omitempty"`
7979
Image string `json:"image,omitempty"`
80+
Network string `json:"network,omitempty"`
8081
Profiles []string `json:"profiles,omitempty"`
8182
CPU int `json:"cpu,omitempty"`
8283
RAM string `json:"ram,omitempty"`

cli/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/bketelsen/IncusScripts/cli
33
go 1.23.6
44

55
require (
6-
github.com/bketelsen/inclient v0.0.4
6+
github.com/bketelsen/inclient v0.0.5
77
github.com/charmbracelet/glamour v0.8.0
88
github.com/charmbracelet/huh v0.6.0
99
github.com/charmbracelet/huh/spinner v0.0.0-20250207133237-2eba4f31bf81

cli/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
1414
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
1515
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
1616
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
17-
github.com/bketelsen/inclient v0.0.4 h1:YobfEHQHh56u9jzQG0fNFZ8oAyOedMi1W6OSHFf/4KY=
18-
github.com/bketelsen/inclient v0.0.4/go.mod h1:0FTjkxQa3bWiplU90NBTEjGMoKdsfZBWLPtPoE+GaxI=
17+
github.com/bketelsen/inclient v0.0.5 h1:k5H/debfGznd7i2VSCzqpWjd5z5Igm0DQCDtowDXXOM=
18+
github.com/bketelsen/inclient v0.0.5/go.mod h1:0FTjkxQa3bWiplU90NBTEjGMoKdsfZBWLPtPoE+GaxI=
1919
github.com/bmatcuk/doublestar/v4 v4.8.0 h1:DSXtrypQddoug1459viM9X9D3dp1Z7993fw36I2kNcQ=
2020
github.com/bmatcuk/doublestar/v4 v4.8.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
2121
github.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY=

0 commit comments

Comments
 (0)