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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flg_masters
TM
Secure solution for nexus infrastructure
Commits
13443081
Commit
13443081
authored
2 years ago
by
Florent Gluck
Browse files
Options
Downloads
Patches
Plain Diff
new stuff
parent
42790da0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/exec/VirtCopyIn.go
+47
-0
47 additions, 0 deletions
src/exec/VirtCopyIn.go
with
47 additions
and
0 deletions
src/exec/VirtCopyIn.go
0 → 100644
+
47
−
0
View file @
13443081
package
exec
import
(
"fmt"
"os/exec"
"strings"
"errors"
)
const
(
virtcopyinBinary
=
"virt-copy-in"
)
// Check virt-copy-in is available.
func
CheckVirtCopyIn
()
error
{
output
,
err
:=
exec
.
Command
(
virtcopyinBinary
,
"--version"
)
.
Output
()
if
err
!=
nil
{
return
errors
.
New
(
virtcopyinBinary
+
" is required but not found. On Ubuntu/Debian, it can be installed with
\"
sudo apt-get install guestfish
\"
."
)
}
out
:=
string
(
output
)
lines
:=
strings
.
Split
(
out
,
"
\n
"
)
fields
:=
strings
.
Split
(
lines
[
0
],
" "
)
if
len
(
fields
)
<
2
{
return
errors
.
New
(
"Failed extracting "
+
virtcopyinBinary
+
" version number!"
)
}
cmd
:=
fields
[
0
]
if
cmd
!=
virtcopyinBinary
{
return
errors
.
New
(
virtcopyinBinary
+
" is required, but not found."
)
}
return
nil
}
// Creates a virt-copy-in command that recursively copy a directory on the host (localDir)
// into a directory on the VM's filesystem (vmDir).
// Note: both directories must exist, otherwise the command will fail.
func
CopyToVM
(
vmDiskFile
,
localDir
,
vmDir
string
)
error
{
log
.
Info
(
"localDir = "
,
localDir
)
cmd
:=
exec
.
Command
(
virtcopyinBinary
,
"-a"
,
vmDiskFile
,
localDir
,
vmDir
)
stdoutStderr
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
output
:=
fmt
.
Sprintf
(
"[%s]"
,
stdoutStderr
)
msg
:=
"Failed writing to
\"
"
+
vmDir
+
"
\"
in qcow ("
+
vmDiskFile
+
"): "
+
output
log
.
Error
(
msg
)
return
errors
.
New
(
msg
)
}
return
nil
}
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