Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Secure solution for nexus infrastructure
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flg_masters
TM
Secure solution for nexus infrastructure
Commits
1ae0b65c
Commit
1ae0b65c
authored
4 months ago
by
Florent Gluck
Browse files
Options
Downloads
Patches
Plain Diff
server: minor changes to ExportVMDir
parent
29d773ed
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/server/router/routerVMs.go
+10
-4
10 additions, 4 deletions
src/server/router/routerVMs.go
with
10 additions
and
4 deletions
src/server/router/routerVMs.go
+
10
−
4
View file @
1ae0b65c
...
...
@@ -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
i
t
s
disk busy
if
err
=
r
.
vms
.
ImportFilesToVM
(
vm
,
uploadedtarGzFile
,
vmDir
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
err
.
Error
())
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment