Add init subcommand
This commit is contained in:
parent
43a958cdec
commit
900e1939f3
52
cmd/root.go
52
cmd/root.go
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gVersion = "0.42a"
|
gVersion = "0.42b"
|
||||||
|
|
||||||
// TODO : Get from $jail_zpool/defaults.json
|
// TODO : Get from $jail_zpool/defaults.json
|
||||||
MIN_DYN_DEVFS_RULESET = 1000
|
MIN_DYN_DEVFS_RULESET = 1000
|
||||||
@ -59,6 +59,9 @@ var (
|
|||||||
|
|
||||||
gTimeZone string
|
gTimeZone string
|
||||||
gSnapshotName string
|
gSnapshotName string
|
||||||
|
gZPool string
|
||||||
|
gBridge string
|
||||||
|
gInterface string
|
||||||
|
|
||||||
gMigrateDestDatastore string
|
gMigrateDestDatastore string
|
||||||
gYesToAll bool
|
gYesToAll bool
|
||||||
@ -99,20 +102,14 @@ It support iocage jails and can coexist with iocage.`,
|
|||||||
fmt.Printf("GoCage v.%s on FreeBSD %d.%d-%s\n", gVersion, fv.major, fv.minor, fv.flavor)
|
fmt.Printf("GoCage v.%s on FreeBSD %d.%d-%s\n", gVersion, fv.major, fv.minor, fv.flavor)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
|
||||||
Initialize datastore(s) /iocage, /iocage/jails
|
|
||||||
Put defaults.json, update it with hostid,interfaces, and maybe other necessary fields
|
|
||||||
Initialize bridge
|
|
||||||
initCmd = &cobra.Command{
|
initCmd = &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "Initialize GoCage",
|
Short: "Initialize GoCage",
|
||||||
//Long: `Let this show you how much fail I had to get this *cough* perfect`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fv, _ := getFreeBSDVersion()
|
InitGoCage(args)
|
||||||
fmt.Printf("GoCage v.%s on FreeBSD %d.%d-%s\n", gVersion, fv.major, fv.minor, fv.flavor)
|
|
||||||
},
|
},
|
||||||
}*/
|
}
|
||||||
|
|
||||||
listCmd = &cobra.Command{
|
listCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
@ -395,6 +392,10 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().BoolVar(&gDebug, "debug", false, "Debug mode")
|
rootCmd.PersistentFlags().BoolVar(&gDebug, "debug", false, "Debug mode")
|
||||||
|
|
||||||
// Command dependant switches
|
// Command dependant switches
|
||||||
|
initCmd.Flags().StringVarP(&gZPool, "pool", "p", "", "ZFS pool to create datastore on")
|
||||||
|
initCmd.Flags().StringVarP(&gBridge, "bridge", "b", "", "bridge to create for jails networking")
|
||||||
|
initCmd.Flags().StringVarP(&gInterface, "interface", "i", "", "interface to add as bridge member. This should be your main interface")
|
||||||
|
initCmd.MarkFlagsRequiredTogether("bridge", "interface")
|
||||||
|
|
||||||
// We reuse these flags in "gocage snapshot list myjail" and 'gocage datastore list" commands
|
// We reuse these flags in "gocage snapshot list myjail" and 'gocage datastore list" commands
|
||||||
listCmd.Flags().StringVarP(&gDisplayJColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output")
|
listCmd.Flags().StringVarP(&gDisplayJColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output")
|
||||||
@ -443,6 +444,7 @@ func init() {
|
|||||||
apiCmd.Flags().IntVarP(&gApiPort, "listen-port", "p", 1234, "API listening port")
|
apiCmd.Flags().IntVarP(&gApiPort, "listen-port", "p", 1234, "API listening port")
|
||||||
|
|
||||||
// Now declare commands
|
// Now declare commands
|
||||||
|
rootCmd.AddCommand(initCmd)
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
rootCmd.AddCommand(listCmd)
|
rootCmd.AddCommand(listCmd)
|
||||||
listCmd.AddCommand(listPropsCmd)
|
listCmd.AddCommand(listPropsCmd)
|
||||||
@ -461,7 +463,6 @@ func init() {
|
|||||||
rootCmd.AddCommand(upgradeCmd)
|
rootCmd.AddCommand(upgradeCmd)
|
||||||
rootCmd.AddCommand(createCmd)
|
rootCmd.AddCommand(createCmd)
|
||||||
rootCmd.AddCommand(apiCmd)
|
rootCmd.AddCommand(apiCmd)
|
||||||
|
|
||||||
rootCmd.AddCommand(testCmd)
|
rootCmd.AddCommand(testCmd)
|
||||||
|
|
||||||
snapshotCmd.AddCommand(snapshotListCmd)
|
snapshotCmd.AddCommand(snapshotListCmd)
|
||||||
@ -491,17 +492,6 @@ func initConfig() {
|
|||||||
fmt.Printf("ERROR reading config file %s : %s\n", gConfigFile, err.Error())
|
fmt.Printf("ERROR reading config file %s : %s\n", gConfigFile, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load default configs from datastores
|
|
||||||
err := ListDatastores(viper.GetStringSlice("datastore"), false)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: error checking datastores: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Println("Using config file:", viper.ConfigFileUsed())
|
|
||||||
// fmt.Printf("datastore in config : %s\n", viper.GetStringSlice("datastore"))
|
|
||||||
// fmt.Printf("datastore.0 in config : %s\n", viper.GetStringSlice("datastore.0"))
|
|
||||||
|
|
||||||
// Command line flags have priority on config file
|
// Command line flags have priority on config file
|
||||||
if rootCmd.Flags().Lookup("sudo") != nil && false == rootCmd.Flags().Lookup("sudo").Changed {
|
if rootCmd.Flags().Lookup("sudo") != nil && false == rootCmd.Flags().Lookup("sudo").Changed {
|
||||||
@ -535,12 +525,26 @@ func initConfig() {
|
|||||||
fmt.Printf("More than 3 sort criteria is not supported!\n")
|
fmt.Printf("More than 3 sort criteria is not supported!\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if gDebug {
|
if gDebug {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
log.Debugf("Debug mode enabled\n")
|
log.Debugf("Debug mode enabled\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// no need to check prerequesites if we are initializing gocage
|
||||||
|
for _, rc := range rootCmd.Commands() {
|
||||||
|
//fmt.Printf("DEBUG: rootCmd subcommand: %v. Was it called? %s\n", rc.Use, rootCmd.Commands()[i].CalledAs())
|
||||||
|
if len(rc.CalledAs()) > 0 && strings.EqualFold("init", rc.CalledAs()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load default configs from datastores
|
||||||
|
err := ListDatastores(viper.GetStringSlice("datastore"), false)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: error checking datastores: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user