Select Git revision
vmExportDir.go
vmExportDir.go 2.28 KiB
package cmdVM
import (
u "nexus-client/utils"
g "nexus-client/globals"
)
type ExportDir struct {
Name string
}
type vmExportDirParams struct {
Dir string
}
func (cmd *ExportDir)GetName() string {
return cmd.Name
}
func (cmd *ExportDir)GetDesc() []string {
return []string{
"Exports one or more VMs' directory into one or more tar archives.",
"Creates one archive per VM (regex).",
"Requires VM_READFS VM access capability or VM_READFS_ANY user capability."}
}
func (cmd *ExportDir)PrintUsage() {
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
u.PrintlnErr("USAGE: ",cmd.GetName()," [ID ...] [regex ...] dir")
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
u.PrintlnErr("\"dir\" is the directory in the VM to export into a tar archive named after the VM ID.")
printRegexUsageDetails()
}
func (cmd *ExportDir)Run(args []string) int {
client := g.GetInstance().Client
host := g.GetInstance().Host
argc := len(args)
if argc < 2 {
cmd.PrintUsage()
return 1
}
dir := args[argc-1]
vms, err := getFilteredVMs("/vms/exportdir", args[:argc-1])
if err != nil {
u.PrintlnErr("Error: "+err.Error())
return 1
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
return 1
}
params := &vmExportDirParams { Dir: dir }
statusCode := 0
client.SetAllowGetMethodPayload(true)
for _, vm := range(vms) {
uuid := vm.ID.String()
outputFile := "exportdir_"+uuid+".tar"
resp, err := client.R().SetOutput(outputFile).SetBody(params).Get(host+"/vms/"+uuid+"/exportdir")