-
Notifications
You must be signed in to change notification settings - Fork 20
/
snapshot_create.go
57 lines (44 loc) · 1.08 KB
/
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
51
52
53
54
55
56
57
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 := getVirtualMachineByNameOrID(args[0])
if err != nil {
return err
}
query := &egoscale.Volume{
VirtualMachineID: vm.ID,
Type: "ROOT",
}
resp, err := cs.GetWithContext(gContext, query)
if err != nil {
return err
}
createSnapshot := &egoscale.CreateSnapshot{
VolumeID: resp.(*egoscale.Volume).ID,
}
message := fmt.Sprintf("Creating snapshot of %q", vm.Name)
res, err := asyncRequest(createSnapshot, message)
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)
}