mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-05 12:45:38 +01:00
Added capacity field to volume GET AP response. This is currently returned only for volumes provisioned dynamically and their volume snapshots. The CLI prints the volume capacity in a human friendly format. Signed-off-by: Hari Gowtham <hgowtham@redhat.com>
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gluster/glusterd2/pkg/api"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const (
|
|
snapshotInfoHelpShort = "Get Gluster Snapshot Info"
|
|
)
|
|
|
|
var (
|
|
snapshotInfoCmd = &cobra.Command{
|
|
Use: "info <snapname>",
|
|
Short: snapshotInfoHelpShort,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: snapshotInfoCmdRun,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
snapshotCmd.AddCommand(snapshotInfoCmd)
|
|
}
|
|
|
|
func snapshotInfoDisplay(snap api.SnapGetResp) {
|
|
vol := &snap.VolInfo
|
|
/*
|
|
data := [][]string{
|
|
{vol.Name, vol.Name},
|
|
{"Snapshot Volume ID:", fmt.Sprintln(vol.ID)},
|
|
{"State:", fmt.Sprintln(vol.State)},
|
|
{"Origin Volume name:", snap.ParentVolName},
|
|
{"Snap Creation Time:", "To Be Added"},
|
|
{"Labels:", "To Be Added"},
|
|
}
|
|
table := tablewriter.NewWriter(os.Stdout)
|
|
table.SetAutoMergeCells(true)
|
|
table.AppendBulk(data)
|
|
table.Render()
|
|
// table.Append([]string{"Snapshot Volume ID:", string(vol.ID)})
|
|
*/
|
|
fmt.Println()
|
|
fmt.Println("Snapshot Name:", vol.Name)
|
|
fmt.Println("Snapshot Volume ID:", vol.ID)
|
|
fmt.Println("State:", vol.State)
|
|
fmt.Println("Origin Volume name:", snap.ParentVolName)
|
|
fmt.Println("Snap Creation Time:", snap.CreatedAt.Format("Mon Jan _2 2006 15:04:05 GMT"))
|
|
if vol.Capacity != 0 {
|
|
fmt.Println("Snapshot Volume Capactiy: ", humanReadable(vol.Capacity))
|
|
}
|
|
fmt.Println("Labels:", "To Be Added")
|
|
fmt.Println("Snapshot Description:", snap.Description)
|
|
fmt.Println()
|
|
|
|
return
|
|
}
|
|
|
|
func snapshotInfoHandler(cmd *cobra.Command) error {
|
|
var snap api.SnapGetResp
|
|
var err error
|
|
|
|
snapname := cmd.Flags().Args()[0]
|
|
snap, err = client.SnapshotInfo(snapname)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
snapshotInfoDisplay(snap)
|
|
return err
|
|
}
|
|
|
|
func snapshotInfoCmdRun(cmd *cobra.Command, args []string) {
|
|
if err := snapshotInfoHandler(cmd); err != nil {
|
|
if GlobalFlag.Verbose {
|
|
log.WithError(err).Error("error getting snapshot info")
|
|
}
|
|
failure("Error getting Snapshot info", err, 1)
|
|
}
|
|
}
|