Skip to content

Commit

Permalink
Fix virt-v2v monitor consumer for go wrapper + minor changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed Feb 18, 2024
1 parent 0358a32 commit 5fcaf2b
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"io"
"net/http"
"os"
"os/exec"
Expand All @@ -28,6 +29,11 @@ func main() {
virtV2vArgs := []string{"virt-v2v", "-v", "-x"}
source := os.Getenv("V2V_source")

if isValidSource(source) {
fmt.Printf("virt-v2v supports the following providers: {OVA, vSphere}. Provided: %s\n", source)
os.Exit(1)
}

requiredEnvVars := map[string][]string{
vSphere: {"V2V_libvirtURL", "V2V_secretKey", "V2V_vmName"},
OVA: {"V2V_diskPath", "V2V_vmName"},
Expand Down Expand Up @@ -65,12 +71,14 @@ func main() {

if source == vSphere {
if _, err := os.Stat("/etc/secret/cacert"); err == nil {
// use the specified certificate
err = os.Symlink("/etc/secret/cacert", "/opt/ca-bundle.crt")
if err != nil {
fmt.Println("Error creating ca cert link ", err)
os.Exit(1)
}
} else {
// otherwise, keep system pool certificates
err := os.Symlink("/etc/pki/tls/certs/ca-bundle.crt.bak", "/opt/ca-bundle.crt")
if err != nil {
fmt.Println("Error creating ca cert link ", err)
Expand Down Expand Up @@ -163,7 +171,13 @@ func LinkDisks(diskKind string, num int) (err error) {

func executeVirtV2v(args []string) (err error) {
virtV2vCmd := exec.Command(args[0], args[1:]...)
virtV2vCmd.Stdout = os.Stdout
virtV2vStdoutPipe, err := virtV2vCmd.StdoutPipe()
if err != nil {
fmt.Printf("Error setting up stdout pipe: %v\n", err)
return
}

tee := io.TeeReader(virtV2vStdoutPipe, os.Stdout)
virtV2vCmd.Stderr = os.Stderr

fmt.Println("exec ", virtV2vCmd)
Expand All @@ -173,7 +187,7 @@ func executeVirtV2v(args []string) (err error) {
}

virtV2vMonitorCmd := exec.Command("/usr/local/bin/virt-v2v-monitor")
virtV2vMonitorCmd.Stdin, _ = virtV2vCmd.StdoutPipe()
virtV2vMonitorCmd.Stdin = tee
virtV2vMonitorCmd.Stdout = os.Stdout
virtV2vMonitorCmd.Stderr = os.Stderr

Expand All @@ -183,7 +197,7 @@ func executeVirtV2v(args []string) (err error) {
}

if err = virtV2vCmd.Wait(); err != nil {
fmt.Printf("Error waiting for virt-v2v to finish : %v\n", err)
fmt.Printf("Error waiting for virt-v2v to finish: %v\n", err)
return
}
return
Expand Down Expand Up @@ -234,3 +248,13 @@ func shutdownHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Server shut down successfully.")
}
}

func isValidSource(source string) bool {
supportedSources := map[string]bool{
OVA: true,
vSphere: true,
}

_, exists := supportedSources[source]
return exists
}

0 comments on commit 5fcaf2b

Please sign in to comment.