-
Notifications
You must be signed in to change notification settings - Fork 19
/
snapshot_create.go
50 lines (39 loc) · 1004 Bytes
/
snapshot_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cmd
import (
"fmt"
"log"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// createCmd represents the create command
var snapshotCreateCmd = &cobra.Command{
Use: "create <vm name | vm id>",
Short: "Create a snapshot of an instance volume",
Aliases: gCreateAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
vm, err := getVMWithNameOrID(args[0])
if err != nil {
return err
}
volume := &egoscale.Volume{
VirtualMachineID: vm.ID,
Type: "ROOT",
}
if err := cs.GetWithContext(gContext, volume); err != nil {
return err
}
res, err := asyncRequest(&egoscale.CreateSnapshot{VolumeID: volume.ID}, fmt.Sprintf("Creating snapshot of %q", vm.Name))
if err != nil {
return err
}
result := res.(*egoscale.Snapshot)
log.Printf("Snapshot %q of %q successfully created", result.Name, vm.Name)
return nil
},
}
func init() {
snapshotCmd.AddCommand(snapshotCreateCmd)
}