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

new stuff

parent 42790da0
No related branches found
No related tags found
No related merge requests found
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment