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 ...@@ -2,7 +2,6 @@ package cmdVM
import ( import (
u "nexus-client/utils" u "nexus-client/utils"
g "nexus-libclient/globals"
libclient "nexus-libclient/vm" libclient "nexus-libclient/vm"
"os" "os"
...@@ -38,9 +37,6 @@ IMPORTANT: to avoid disk corruption, files can only be imported into non-running ...@@ -38,9 +37,6 @@ IMPORTANT: to avoid disk corruption, files can only be imported into non-running
} }
func (cmd *ImportDir) Run(args []string) int { func (cmd *ImportDir) Run(args []string) int {
client := g.GetInstance().Client
host := g.GetInstance().Host
argc := len(args) argc := len(args)
if argc < 3 { if argc < 3 {
cmd.PrintUsage() cmd.PrintUsage()
...@@ -76,21 +72,12 @@ func (cmd *ImportDir) Run(args []string) int { ...@@ -76,21 +72,12 @@ func (cmd *ImportDir) Run(args []string) int {
} }
for _, vm := range vms { for _, vm := range vms {
uuid := vm.ID.String() err := libclient.VMImportArchive(vm.ID.String(), vmDir, tmpTarGzFile)
resp, err := client.R().SetFile("file", tmpTarGzFile).
SetFormData(map[string]string{
"vmDir": vmDir,
}).Post(host + "/vms/" + uuid + "/importfiles")
if err != nil { if err != nil {
u.PrintlnErr("Failed copying \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\": " + err.Error()) u.PrintlnErr("Failed copying \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\": " + err.Error())
statusCode = 1 statusCode = 1
} else { } else {
if resp.IsSuccess() { u.Println("Copied \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\"")
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
}
} }
} }
......
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