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

server: minor changes to ExportVMDir

parent 29d773ed
No related branches found
No related tags found
No related merge requests found
......@@ -581,10 +581,14 @@ func (r *RouterVMs) DeleteVMAccessForUser(c echo.Context) error {
// curl --cacert ca.pem -X GET https://localhost:1077/vms/e41f3556-ca24-4658-bd79-8c85bd6bff59/exportdir -H 'Content-Type: application/json' -d '{"dir":"absolute_path_to_dir"}' -H "Authorization: Bearer <AccessToken>" --output dir.tar
func (r *RouterVMs) ExportVMDir(c echo.Context) error {
return r.applyOnFilteredVMs(c, caps.CAP_VM_READFS_ANY, caps.CAP_VM_READFS, func(c echo.Context, vm *vms.VM) error {
vmID := vm.GetID().String()
// Deserializes and validates the client's parameter.
p := new(params.VMExportDir)
if err := decodeJson(c, &p); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
msg := "Failed extracting VM " + vmID + "'s dir: " + err.Error()
log.Error(msg)
return echo.NewHTTPError(http.StatusBadRequest, msg)
}
// Creates a unique tar filename.
......@@ -592,13 +596,15 @@ func (r *RouterVMs) ExportVMDir(c echo.Context) error {
// Extracts VM's p.Dir directory into tarGzFile on the host.
if err := r.vms.ExportVMFiles(vm, p.Dir, tarGzFile); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Failed extracting VM's dir")
msg := "Failed extracting VM " + vmID + "'s dir: " + err.Error()
log.Error(msg)
return echo.NewHTTPError(http.StatusBadRequest, msg)
}
// Sends the archive back to the client and once completed, deletes it.
defer func(file string) {
if err := os.Remove(file); err != nil {
log.Error("Failed removing archive of extracted VM dir: " + err.Error())
log.Error("Failed removing archive of extracted VM " + vmID + "'s dir: " + err.Error())
}
}(tarGzFile)
return c.File(tarGzFile)
......@@ -645,7 +651,7 @@ func (r *RouterVMs) ImportFilesToVM(c echo.Context) error {
}
// Copy the archive's files into the VM
// IMPORTANT: check the VM is NOT running!
// IMPORTANT: the VM cannot have its disk busy
if err = r.vms.ImportFilesToVM(vm, uploadedtarGzFile, vmDir); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment