mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
init machined cli
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package install
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"uncloud/internal/machine"
|
||||
"uncloud/internal/machine/daemon"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
uncloudID string
|
||||
uncloudSecret string
|
||||
network string
|
||||
}
|
||||
|
||||
func NewCommand(dataDir *string) *cobra.Command {
|
||||
opts := Options{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "install",
|
||||
Short: "Install OS dependencies and configure Uncloud machine.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return install(*dataDir, opts)
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVar(&opts.uncloudID, "id", "", "Globally unique identifier for the uncloud this machine belongs to")
|
||||
_ = cmd.MarkFlagRequired("id")
|
||||
// TODO: read secret from file for security reasons (bash history).
|
||||
cmd.Flags().StringVar(&opts.uncloudSecret, "secret", "", "Shared secret for the uncloud this machine belongs to")
|
||||
_ = cmd.MarkFlagRequired("secret")
|
||||
cmd.Flags().StringVar(&opts.network, "network", "", "IPv4 network in CIDR format to use for the machine network")
|
||||
_ = cmd.MarkFlagRequired("network")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func install(dataDir string, opts Options) error {
|
||||
cfg := daemon.Config{
|
||||
UncloudID: opts.uncloudID,
|
||||
UncloudSecret: opts.uncloudSecret,
|
||||
Network: opts.network,
|
||||
}
|
||||
return machine.Install(dataDir, cfg)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"uncloud/cmd/machined/install"
|
||||
"uncloud/internal/machine/daemon"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var dataDir string
|
||||
cmd := &cobra.Command{
|
||||
Use: "machined",
|
||||
Short: "Uncloud machine daemon.",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return daemon.Run(dataDir)
|
||||
},
|
||||
}
|
||||
cmd.PersistentFlags().StringVarP(&dataDir, "data-dir", "d", daemon.DefaultDataDir, "Directory to store machine state")
|
||||
_ = cmd.MarkFlagDirname("data-dir")
|
||||
cmd.AddCommand(
|
||||
install.NewCommand(&dataDir),
|
||||
)
|
||||
cobra.CheckErr(cmd.Execute())
|
||||
}
|
||||
Reference in New Issue
Block a user