Skip to content
Snippets Groups Projects
Commit 06c8c527 authored by Florent Gluck's avatar Florent Gluck
Browse files

libclient: completed vmImportDir

parent 06381645
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@ package cmdVM
import (
u "nexus-client/utils"
g "nexus-libclient/globals"
libclient "nexus-libclient/vm"
"os"
......@@ -38,9 +37,6 @@ IMPORTANT: to avoid disk corruption, files can only be imported into non-running
}
func (cmd *ImportDir) Run(args []string) int {
client := g.GetInstance().Client
host := g.GetInstance().Host
argc := len(args)
if argc < 3 {
cmd.PrintUsage()
......@@ -76,21 +72,12 @@ func (cmd *ImportDir) Run(args []string) int {
}
for _, vm := range vms {
uuid := vm.ID.String()
resp, err := client.R().SetFile("file", tmpTarGzFile).
SetFormData(map[string]string{
"vmDir": vmDir,
}).Post(host + "/vms/" + uuid + "/importfiles")
err := libclient.VMImportArchive(vm.ID.String(), vmDir, tmpTarGzFile)
if err != nil {
u.PrintlnErr("Failed copying \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\": " + err.Error())
statusCode = 1
} else {
if resp.IsSuccess() {
u.Println("Copied \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\"")
} else {
u.PrintlnErr("Failed copying \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\": " + resp.Status() + ": " + resp.String())
statusCode = 1
}
u.Println("Copied \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\"")
}
}
......
package vm
import (
g "nexus-libclient/globals"
"nexus-libclient/response"
)
func VMImportArchive(vmID, vmDir, archiveFile string) error {
client := g.GetInstance().Client
host := g.GetInstance().Host
resp, err := client.R().SetFile("file", archiveFile).
SetFormData(map[string]string{
"vmDir": vmDir,
}).Post(host + "/vms/" + vmID + "/importfiles")
if err != nil {
return err
}
if resp.IsSuccess() {
return nil
} else {
return response.ErrorToMsg(resp)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment