Add -p flag to create command to specify jail configuration items in k=v format

This commit is contained in:
yo 2024-09-22 17:34:56 +02:00
parent c19e40b139
commit 2df22b10b1
2 changed files with 18 additions and 5 deletions

View File

@ -44,7 +44,7 @@ func CreateJail(args []string) {
var ds *Datastore
if len(gCreateArgs.Datastore) > 0 {
fmt.Printf("DEBUG: Use %s datastore\n", gCreateArgs.Datastore)
log.Debugf("Use %s datastore\n", gCreateArgs.Datastore)
ds, err = getDatastoreFromArray(gCreateArgs.Datastore, gDatastores)
if err != nil {
fmt.Printf("ERROR Getting datastore: %s\n", gCreateArgs.Datastore, err.Error())
@ -272,7 +272,6 @@ func CreateJail(args []string) {
j.Config.Host_hostname = jname
j.Config.Host_hostuuid = jname
j.Config.Jailtype = "jail"
j.WriteConfigToDisk(false)
///////////////////////////////////////////////////////////////////////
@ -285,5 +284,17 @@ func CreateJail(args []string) {
defer fstabHandle.Close()
fmt.Printf(" > Jail created!\n")
}
var cmdline []string
for _, props := range strings.Split(gCreateArgs.Properties, ",") {
cmdline = append(cmdline, props)
}
// Reload jail list so SetJailProperties will see it
ListJails(nil, false)
cmdline = append(cmdline, jname)
log.Debugf("cmdline: \"%v\"", cmdline)
SetJailProperties(cmdline)
}
}

View File

@ -25,6 +25,7 @@ type createArgs struct {
BaseJail bool
Datastore string
JailType string
Properties string
}
var (
@ -379,6 +380,7 @@ func init() {
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.MarkFlagRequired("bridge")
initCmd.MarkFlagsRequiredTogether("bridge", "interface")
// We reuse these flags in "gocage snapshot list myjail" and 'gocage datastore list" commands
@ -412,8 +414,8 @@ func init() {
migrateCmd.MarkFlagRequired("datastore")
fetchCmd.Flags().StringVarP(&gFetchRelease, "release", "r", "", "Release to fetch (e.g.: \"13.1-RELEASE\"")
fetchCmd.Flags().StringVarP(&gFetchIntoDS, "datastore", "o", "", "Datastore release will be saved to")
fetchCmd.Flags().StringVarP(&gFetchFrom, "from", "d", "", "Repository to download from. Should contain XY.Z-RELEASE. File protocol supported")
fetchCmd.Flags().StringVarP(&gFetchIntoDS, "datastore", "d", "", "Datastore release will be saved to")
fetchCmd.Flags().StringVarP(&gFetchFrom, "from", "f", "", "Repository to download from. Should contain XY.Z-RELEASE. File protocol supported")
fetchCmd.MarkFlagRequired("release")
fetchCmd.MarkFlagRequired("datastore")
@ -423,6 +425,7 @@ func init() {
createCmd.Flags().StringVarP(&gCreateArgs.Release, "release", "r", "", "Release for the jail (e.g.: \"13.1-RELEASE\"")
createCmd.Flags().BoolVarP(&gCreateArgs.BaseJail, "basejail", "b", false, "Basejail. This will create a jail mounted read only from a release, so every up(date|grade) made to this release will immediately propagate to new jail.\n")
createCmd.Flags().StringVarP(&gCreateArgs.Datastore, "datastore", "d", "", "Datastore to create the jail on. Defaults to first declared in config.")
createCmd.Flags().StringVarP(&gCreateArgs.Properties, "configuration", "p", "", "Configuration properties with format k1=v1,k2=v2 (Ex: \"Config.Ip4_addr='vnet0|192.168.1.2',Config.Ip6=none\")")
// Now declare commands
rootCmd.AddCommand(initCmd)
@ -443,7 +446,6 @@ func init() {
rootCmd.AddCommand(updateCmd)
rootCmd.AddCommand(upgradeCmd)
rootCmd.AddCommand(createCmd)
rootCmd.AddCommand(apiCmd)
rootCmd.AddCommand(testCmd)
snapshotCmd.AddCommand(snapshotListCmd)