Add datastore to snapshots, force Datastore display when jail exist on multi datastores
This commit is contained in:
36
cmd/list.go
36
cmd/list.go
@@ -3,7 +3,6 @@ package cmd
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"gocage/jail"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -40,12 +39,12 @@ func ListJailsProps(args []string) {
|
||||
* into gJails global var
|
||||
*******************************************************************************/
|
||||
func ListJails(args []string, display bool) {
|
||||
fields := strings.Split(gDisplayJColumns, ",")
|
||||
|
||||
for _, d := range viper.GetStringSlice("datastore") {
|
||||
listJailsFromDatastore(d)
|
||||
for _, ds := range gDatastores {
|
||||
listJailsFromDatastore(ds)
|
||||
}
|
||||
|
||||
|
||||
fields := strings.Split(gDisplayJColumns, ",")
|
||||
|
||||
// This is the structure we will filter, then display
|
||||
var jails []Jail
|
||||
|
||||
@@ -91,7 +90,6 @@ func ListJails(args []string, display bool) {
|
||||
for _, j := range jails {
|
||||
if j.Name == a {
|
||||
js = append(js, j)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,17 +148,17 @@ func ListJails(args []string, display bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func listJailsFromDatastore(datastore string) {
|
||||
fileInfo, err := os.Stat(datastore)
|
||||
func listJailsFromDatastore(ds Datastore) {
|
||||
fileInfo, err := os.Stat(ds.Mountpoint)
|
||||
if err != nil {
|
||||
log.Fatalln(fmt.Sprintf("Unable to access %s, check path and/or rights", datastore))
|
||||
log.Fatalln(fmt.Sprintf("Unable to access %s, check path and/or rights", ds.Mountpoint))
|
||||
}
|
||||
if fileInfo.IsDir() == false {
|
||||
log.Fatalln(fmt.Sprintf("%s is not a directory", datastore))
|
||||
log.Fatalln(fmt.Sprintf("%s is not a directory", ds.Mountpoint))
|
||||
}
|
||||
|
||||
// A datastore have to contain a "jails" directory
|
||||
jailsDir := fmt.Sprintf("%s/jails", datastore)
|
||||
jailsDir := fmt.Sprintf("%s/jails", ds.Mountpoint)
|
||||
fileInfo, err = os.Stat(jailsDir)
|
||||
if err != nil {
|
||||
log.Fatalln(fmt.Sprintf("Unable to access %s, check path and/or rights", jailsDir))
|
||||
@@ -169,10 +167,10 @@ func listJailsFromDatastore(datastore string) {
|
||||
log.Fatalln(fmt.Sprintf("%s is not a directory", jailsDir))
|
||||
}
|
||||
|
||||
listJailsFromDirectory(jailsDir)
|
||||
listJailsFromDirectory(jailsDir, ds.Name)
|
||||
}
|
||||
|
||||
func listJailsFromDirectory(dir string) []Jail {
|
||||
func listJailsFromDirectory(dir string, dsname string) []Jail {
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Fatalln(fmt.Sprintf("Unable to browse %s, check path and/or rights", dir))
|
||||
@@ -194,6 +192,7 @@ func listJailsFromDirectory(dir string) []Jail {
|
||||
Name: jailConf.Host_hostname,
|
||||
Config: jailConf,
|
||||
ConfigPath: jailConfPath,
|
||||
Datastore: dsname,
|
||||
RootPath: jailRootPath,
|
||||
Running: false,
|
||||
}
|
||||
@@ -223,9 +222,12 @@ func listJailsFromDirectory(dir string) []Jail {
|
||||
// Check if jail with the same name already exist on another DS
|
||||
for _, jj := range gJails {
|
||||
if strings.EqualFold(jj.Name, j.Name) {
|
||||
fmt.Printf("ERROR: A jail with name %s already exist on datastore %s!\n", j.Name, jj.Zpool)
|
||||
fmt.Printf("Jail %s on datastore %s wont be handled\n", j.Name, j.Zpool)
|
||||
return gJails
|
||||
fmt.Printf(" ---------------------------------------------- \n")
|
||||
fmt.Printf("Warning: A jail with name %s already exist on datastore %s!\n", j.Name, jj.Datastore)
|
||||
fmt.Printf(" ---------------------------------------------- \n")
|
||||
// Add Datastore to avoid confusion
|
||||
gDisplayJColumns += ",Datastore"
|
||||
gDisplaySColumns += ",Datastore"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user