MCPcopy
hub / github.com/lxc/incus / runInteractive

Method runInteractive

cmd/incus/admin_init_interactive.go:29–95  ·  view source on GitHub ↗
(_ *cobra.Command, d incus.InstanceServer, server *api.Server)

Source from the content-addressed store, hash-verified

27)
28
29func (c *cmdAdminInit) runInteractive(_ *cobra.Command, d incus.InstanceServer, server *api.Server) (*api.InitPreseed, error) {
30 // Initialize config
31 config := newInitPressed()
32
33 // Clustering
34 clustering, err := c.global.asker.AskBool(i18n.G("Would you like to use clustering?")+" (yes/no) [default=no]: ", "no")
35 if err != nil {
36 return nil, err
37 }
38
39 if clustering {
40 err := askClustering(c.global.asker, config, nil, d, false)
41 if err != nil {
42 return nil, err
43 }
44 }
45
46 // Ask all the other questions
47 if config.Cluster == nil || config.Cluster.ClusterAddress == "" {
48 // Storage
49 err = c.askStorage(config, d, server)
50 if err != nil {
51 return nil, err
52 }
53
54 // Networking
55 err = c.askNetworking(config, d)
56 if err != nil {
57 return nil, err
58 }
59
60 // Daemon config
61 err = c.askDaemon(config, server)
62 if err != nil {
63 return nil, err
64 }
65 }
66
67 // Print the YAML
68 preSeedPrint, err := c.global.asker.AskBool(i18n.G("Would you like a YAML \"init\" preseed to be printed?")+" (yes/no) [default=no]: ", "no")
69 if err != nil {
70 return nil, err
71 }
72
73 if preSeedPrint {
74 var object api.InitPreseed
75
76 // If the user has chosen to join an existing cluster, print
77 // only YAML for the cluster section, which is the only
78 // relevant one. Otherwise print the regular config.
79 if config.Cluster != nil && config.Cluster.ClusterAddress != "" {
80 object = api.InitPreseed{}
81 object.Cluster = config.Cluster
82 } else {
83 object = *config
84 }
85
86 out, err := yaml.Dump(object, yaml.WithV2Defaults())

Callers 1

runMethod · 0.95

Calls 9

askStorageMethod · 0.95
askNetworkingMethod · 0.95
askDaemonMethod · 0.95
GFunction · 0.92
newInitPressedFunction · 0.85
askClusteringFunction · 0.85
AskBoolMethod · 0.80
ErrorfMethod · 0.80
DumpMethod · 0.45

Tested by

no test coverage detected