This repository has been archived by the owner on Mar 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #533 from rafikc30/snapshot1
Snapshot: patches for basic functionality
- Loading branch information
Showing
38 changed files
with
2,421 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gluster/glusterd2/pkg/api" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
snapshotActivateHelpShort = "Activate a Gluster Snapshot" | ||
snapshotActivateHelpLong = "Activate a Gluster snapshot. Force flag can be used to activate a snapshot forcefully. It will override some checks." | ||
) | ||
|
||
var ( | ||
flagSnapshotActivateCmdForce bool | ||
|
||
snapshotActivateCmd = &cobra.Command{ | ||
Use: "activate <snapname>", | ||
Short: snapshotActivateHelpShort, | ||
Long: snapshotActivateHelpLong, | ||
Args: cobra.ExactArgs(1), | ||
Run: snapshotActivateCmdRun, | ||
} | ||
) | ||
|
||
func init() { | ||
snapshotActivateCmd.Flags().BoolVarP(&flagSnapshotActivateCmdForce, "force", "f", false, "Force") | ||
snapshotCmd.AddCommand(snapshotActivateCmd) | ||
} | ||
|
||
func snapshotActivateCmdRun(cmd *cobra.Command, args []string) { | ||
snapname := cmd.Flags().Args()[0] | ||
req := api.SnapActivateReq{ | ||
Force: flagSnapshotActivateCmdForce, | ||
} | ||
err := client.SnapshotActivate(req, snapname) | ||
if err != nil { | ||
if verbose { | ||
log.WithFields(log.Fields{ | ||
"snapshot": snapname, | ||
"error": err.Error(), | ||
}).Error("snapshot activation failed") | ||
} | ||
failure("snapshot activation failed", err, 1) | ||
} | ||
fmt.Printf("Snapshot %s activated successfully\n", snapname) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gluster/glusterd2/pkg/api" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
snapshotCreateHelpShort = "Create a Gluster Snapshot" | ||
snapshotCreateHelpLong = "Create a Gluster snapshot of the requested volume. By default it creates the snapshot with out timestamp." | ||
) | ||
|
||
var ( | ||
flagSnapshotCreateForce bool | ||
flagSnapshotCreateTimestamp bool | ||
flagSnapshotCreateDescription string | ||
|
||
snapshotCreateCmd = &cobra.Command{ | ||
Use: "create <snapname> <volname>", | ||
Short: snapshotCreateHelpShort, | ||
Long: snapshotCreateHelpLong, | ||
Args: cobra.MinimumNArgs(2), | ||
Run: snapshotCreateCmdRun, | ||
} | ||
) | ||
|
||
func init() { | ||
snapshotCreateCmd.Flags().StringVar(&flagSnapshotCreateDescription, "desctription", "", "Description of snapshot") | ||
snapshotCreateCmd.Flags().BoolVar(&flagSnapshotCreateForce, "force", false, "Force") | ||
snapshotCreateCmd.Flags().BoolVar(&flagSnapshotCreateTimestamp, "timestamp", false, "Append timestamp with snap name") | ||
|
||
snapshotCmd.AddCommand(snapshotCreateCmd) | ||
} | ||
|
||
func snapshotCreateCmdRun(cmd *cobra.Command, args []string) { | ||
snapname := args[0] | ||
volname := args[1] | ||
|
||
req := api.SnapCreateReq{ | ||
VolName: volname, | ||
SnapName: snapname, | ||
Force: flagSnapshotCreateForce, | ||
TimeStamp: flagSnapshotCreateTimestamp, | ||
Description: flagSnapshotCreateDescription, | ||
} | ||
|
||
snap, err := client.SnapshotCreate(req) | ||
if err != nil { | ||
if verbose { | ||
log.WithFields(log.Fields{ | ||
"volume": volname, | ||
"snapshot": snapname, | ||
"error": err.Error(), | ||
}).Error("snapshot creation failed") | ||
} | ||
failure("Snapshot creation failed", err, 1) | ||
} | ||
vol := snap.VolInfo | ||
fmt.Printf("%s Snapshot created successfully\n", vol.Name) | ||
fmt.Println("Snapshot Volume ID: ", vol.ID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
snapshotDeactivateHelpShort = "Deactivate a Gluster Snapshot" | ||
) | ||
|
||
var ( | ||
snapshotDeactivateCmd = &cobra.Command{ | ||
Use: "deactivate <snapname>", | ||
Short: snapshotDeactivateHelpShort, | ||
Args: cobra.ExactArgs(1), | ||
Run: snapshotDeactivateCmdRun, | ||
} | ||
) | ||
|
||
func init() { | ||
snapshotCmd.AddCommand(snapshotDeactivateCmd) | ||
} | ||
|
||
func snapshotDeactivateCmdRun(cmd *cobra.Command, args []string) { | ||
snapname := cmd.Flags().Args()[0] | ||
err := client.SnapshotDeactivate(snapname) | ||
if err != nil { | ||
if verbose { | ||
log.WithFields(log.Fields{ | ||
"snapshot": snapname, | ||
"error": err.Error(), | ||
}).Error("snapshot deactivation failed") | ||
} | ||
failure("snapshot deactivation failed", err, 1) | ||
} | ||
fmt.Printf("Snapshot %s deactivated successfully\n", snapname) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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:", "To Be Added") | ||
fmt.Println("Labels:", "To Be Added") | ||
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) { | ||
err := snapshotInfoHandler(cmd) | ||
if err != nil { | ||
if verbose { | ||
log.WithFields(log.Fields{ | ||
"error": err.Error(), | ||
}).Error("error getting snapshot info") | ||
} | ||
failure("Error getting Snapshot info", err, 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/gluster/glusterd2/pkg/api" | ||
"github.com/olekukonko/tablewriter" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
helpSnapshotListCmd = "List all Gluster Snapshots" | ||
) | ||
|
||
func init() { | ||
|
||
snapshotCmd.AddCommand(snapshotListCmd) | ||
|
||
} | ||
|
||
func snapshotListHandler(cmd *cobra.Command) error { | ||
var snaps api.SnapListResp | ||
var req api.SnapListReq | ||
var err error | ||
if len(cmd.Flags().Args()) > 0 { | ||
req.Volname = cmd.Flags().Args()[0] | ||
} | ||
|
||
snaps, err = client.SnapshotList(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetAutoMergeCells(true) | ||
table.SetRowLine(true) | ||
if req.Volname == "" { | ||
table.SetHeader([]string{"Name", "Origin Volume"}) | ||
for _, snap := range snaps { | ||
for _, entry := range snap.SnapName { | ||
table.Append([]string{entry, snap.ParentName}) | ||
} | ||
} | ||
} else { | ||
table.SetHeader([]string{"Name"}) | ||
for _, entry := range snaps[0].SnapName { | ||
table.Append([]string{entry}) | ||
} | ||
|
||
} | ||
table.Render() | ||
return err | ||
} | ||
|
||
var snapshotListCmd = &cobra.Command{ | ||
Use: "list [volname]", | ||
Short: helpSnapshotListCmd, | ||
Args: cobra.RangeArgs(0, 1), | ||
Run: snapshotListCmdRun, | ||
} | ||
|
||
func snapshotListCmdRun(cmd *cobra.Command, args []string) { | ||
err := snapshotListHandler(cmd) | ||
if err != nil { | ||
if verbose { | ||
log.WithFields(log.Fields{ | ||
"error": err.Error(), | ||
}).Error("error getting snapshot list") | ||
} | ||
failure("Error getting Snapshot list", err, 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
helpSnapshotCmd = "Gluster Snapshot Management" | ||
) | ||
|
||
func init() { | ||
RootCmd.AddCommand(snapshotCmd) | ||
} | ||
|
||
var snapshotCmd = &cobra.Command{ | ||
Use: "snapshot", | ||
Short: helpSnapshotCmd, | ||
} |
Oops, something went wrong.