Correctly display multiple jails snapshots

This commit is contained in:
yo
2022-04-04 20:10:42 +02:00
parent a12c268be2
commit 966a3d57c1
3 changed files with 22 additions and 14 deletions

View File

@ -11,6 +11,7 @@ import (
*******************************************************************************/
func ListJailsSnapshots(args []string) {
var jailNames []string
var snapshots []Snapshot
if len(args) > 0 {
for _, a := range args {
@ -20,24 +21,25 @@ func ListJailsSnapshots(args []string) {
if len(jailNames) == 0 || len(args) == 0 {
for _, j := range gJails {
listJailSnapshots(j)
snapshots = append(snapshots, listJailSnapshots(j)...)
}
} else {
for _, cj := range gJails {
for _, jn := range jailNames {
if strings.EqualFold(cj.Name, jn) {
listJailSnapshots(cj)
snapshots = append(snapshots, listJailSnapshots(cj)...)
}
}
}
}
displaySnapshotsFields(snapshots, []string{"Jailname","Name","Creation","Referenced","Used"})
}
/********************************************************************************
* List all snapshots a jail have
*******************************************************************************/
func listJailSnapshots(jail Jail) {
func listJailSnapshots(jail Jail) []Snapshot {
var snapshots []Snapshot
// 1. List all datasets
@ -48,7 +50,7 @@ func listJailSnapshots(jail Jail) {
out, err := executeCommand(cmd)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
return snapshots
}
dateLayout := "Mon Jan _2 15:04 2006"
@ -61,7 +63,7 @@ func listJailSnapshots(jail Jail) {
creationts, err := time.ParseInLocation(dateLayout, ls[4], loc)
if err != nil {
fmt.Println("Error while parsing date %s:", ls[4], err)
return
return snapshots
}
// Get subdir to append to snapshot name
subdir := strings.Replace(strings.Split(ls[0], "@")[0],
@ -69,6 +71,7 @@ func listJailSnapshots(jail Jail) {
snapshots = append(snapshots, Snapshot{Dsname: ls[0],
Name: fmt.Sprintf("%s%s", strings.Split(ls[0], "@")[1], subdir),
Jailname: jail.Name,
Mountpoint: ls[1],
Used: ls[2],
Referenced: ls[3],
@ -80,9 +83,5 @@ func listJailSnapshots(jail Jail) {
ss := initSnapshotSortStruct()
SnapshotsOrderedBy(ss.CreationInc).Sort(snapshots)
// TODO : Pretty display. Make an interface of displayStructFields?
displaySnapshotsFields(snapshots, []string{"Name","Creation","Referenced","Used"})
/*for _, s := range snapshots {
fmt.Printf("| %s | %s | %s | %s |\n", s.Name, s.Creation.String(), s.Referenced, s.Used)
}*/
return snapshots
}