Add datastore list, filter and sort, add snapshot sorting
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -17,6 +18,9 @@ func ListJailsSnapshots(args []string) {
|
||||
var jailNames []string
|
||||
var snapshots []Snapshot
|
||||
|
||||
/***************************************************************
|
||||
/ Filter snapshots by jailname
|
||||
/**************************************************************/
|
||||
if len(args) > 0 {
|
||||
for _, a := range args {
|
||||
jailNames = append(jailNames, a)
|
||||
@ -36,7 +40,55 @@ func ListJailsSnapshots(args []string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
displaySnapshotsFields(snapshots, []string{"Jailname", "Name", "Creation", "Referenced", "Used"})
|
||||
|
||||
fields := strings.Split(gDisplaySColumns, ",")
|
||||
|
||||
/***************************************************************
|
||||
/ Sort snapshots
|
||||
/ We support 3 sort criteria max
|
||||
/**************************************************************/
|
||||
if len(gSortSnapFields) > 0 && gSortSnapFields != "none" {
|
||||
ss := initSnapshotSortStruct()
|
||||
|
||||
// The way we manage criteria quantity is not very elegant...
|
||||
var fct1, fct2, fct3 *reflect.Value
|
||||
for i, c := range strings.Split(gSortSnapFields, ",") {
|
||||
var fctName string
|
||||
if strings.HasPrefix(c, "-") {
|
||||
fctName = fmt.Sprintf("%sDec", strings.Replace(c, "-", "", 1))
|
||||
} else { // Par defaut (pas de prefix +/-) on considere un tri incremental
|
||||
fctName = fmt.Sprintf("%sInc", strings.Replace(c, "+", "", 1))
|
||||
}
|
||||
|
||||
// Get function by its name
|
||||
fct, _, err := getStructFieldValue(ss, fctName)
|
||||
|
||||
if err != nil {
|
||||
fieldName := strings.Replace(strings.Replace(c, "-", "", 1), "+", "", 1)
|
||||
fmt.Printf("ERROR getting SnapshotSort struct field %s. Please check the field name: %s\n", fctName, fieldName)
|
||||
return
|
||||
}
|
||||
switch i + 1 {
|
||||
case 1:
|
||||
fct1 = fct
|
||||
case 2:
|
||||
fct2 = fct
|
||||
case 3:
|
||||
fct3 = fct
|
||||
}
|
||||
}
|
||||
|
||||
switch len(strings.Split(gSortSnapFields, ",")) {
|
||||
case 1:
|
||||
SnapshotsOrderedBy(fct1.Interface().(snapshotLessFunc)).Sort(snapshots)
|
||||
case 2:
|
||||
SnapshotsOrderedBy(fct1.Interface().(snapshotLessFunc), fct2.Interface().(snapshotLessFunc)).Sort(snapshots)
|
||||
case 3:
|
||||
SnapshotsOrderedBy(fct1.Interface().(snapshotLessFunc), fct2.Interface().(snapshotLessFunc), fct3.Interface().(snapshotLessFunc)).Sort(snapshots)
|
||||
}
|
||||
}
|
||||
|
||||
displaySnapshotsFields(snapshots, fields)
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
|
Reference in New Issue
Block a user