-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (74 loc) · 2.34 KB
/
main.go
File metadata and controls
82 lines (74 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"context"
"fmt"
"log"
"os"
"path/filepath"
"github.com/harvester/harvester-installer/pkg/config"
"github.com/harvester/harvester-installer/pkg/console"
"github.com/harvester/harvester-installer/pkg/version"
"github.com/urfave/cli/v3"
)
func main() {
cmd := &cli.Command{
Name: "harvester-installer",
Version: version.FriendlyVersion(),
Usage: "Console application to install Harvester",
UsageText: `harvester-installer [global options] [command [command options]]
Executes the Harvester installer if no command is specified.`,
Action: func(context.Context, *cli.Command) error {
return console.RunConsole()
},
Commands: []*cli.Command{
{
Name: "generate-network-config",
Usage: "Generate NetworkManager connection profiles",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Value: "/oem/harvester.config",
Usage: "Harvester config file",
},
&cli.StringFlag{
Name: "connection-path",
Value: config.NMConnectionPath,
Usage: "Directory to save connection profiles in",
},
&cli.BoolFlag{
Name: "force",
Usage: "Overwrite existing connection profiles",
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
data, err := os.ReadFile(cmd.String("config"))
if err != nil {
return err
}
harvesterCfg, err := config.LoadHarvesterConfig(data)
if err != nil {
return err
}
paths, err := filepath.Glob(fmt.Sprintf("%s/%s", cmd.String("connection-path"), config.NMConnectionGlobPattern))
if err != nil {
return err
}
if len(paths) == 0 || cmd.Bool("force") {
err = config.UpdateManagementInterfaceConfig(harvesterCfg.ManagementInterface, harvesterCfg.OS.DNSNameservers, cmd.String("connection-path"), false)
if err != nil {
return err
}
log.Printf("Generated NetworkManager connection profiles in %s from %s\n", cmd.String("connection-path"), cmd.String("config"))
return nil
} else {
log.Printf("Skipped generation of NetworkManager connection profiles (%s/%s already exists, specify --force to overwrite)", cmd.String("connection-path"), config.NMConnectionGlobPattern)
return nil
}
},
},
},
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatalf("Error: %v", err)
}
}