Skip to content

Commit

Permalink
fix virt-v2v progress
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed May 19, 2024
1 parent a674470 commit 1a8727c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cmd/virt-v2v-monitor/virt-v2v-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"flag"
"fmt"
"net/http"
"os"
"regexp"
Expand All @@ -15,7 +16,7 @@ import (
)

var COPY_DISK_RE = regexp.MustCompile(`^.*Copying disk (\d+)/(\d+)`)
var DISK_PROGRESS_RE = regexp.MustCompile(`^..\s*(\d+)% \[.*\]`)
var DISK_PROGRESS_RE = regexp.MustCompile(`\s+\((\d+).*|.+ (\d+)% \[[*-]+\]`)
var FINISHED_RE = regexp.MustCompile(`^\[[ .0-9]*\] Finishing off`)

// Here is a scan function that imposes limit on returned line length. virt-v2v
Expand Down Expand Up @@ -64,6 +65,7 @@ func main() {

// Start prometheus metrics HTTP handler
klog.Info("Setting up prometheus endpoint :2112/metrics")
klog.Info("this is Bella test")
http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":2112", nil)

Expand Down Expand Up @@ -98,13 +100,16 @@ func main() {
klog.Fatal("Output monitoring failed! ", err)
}

fmt.Println("this is the line we scanning now ", string(line))

if match := COPY_DISK_RE.FindSubmatch(line); match != nil {
diskNumber, _ = strconv.ParseUint(string(match[1]), 10, 0)
disks, _ = strconv.ParseUint(string(match[2]), 10, 0)
klog.Infof("Copying disk %d out of %d", diskNumber, disks)
progress = 0
err = updateProgress(progressCounter, diskNumber, progress)
} else if match := DISK_PROGRESS_RE.FindSubmatch(line); match != nil {
klog.Info("we are here at progress ", line)
progress, _ = strconv.ParseUint(string(match[1]), 10, 0)
klog.Infof("Progress update, completed %d %%", progress)
err = updateProgress(progressCounter, diskNumber, progress)
Expand All @@ -116,7 +121,7 @@ func main() {
err = updateProgress(progressCounter, disk, 100)
}
} else {
klog.V(1).Info("Ignoring line: ", string(line))
klog.Infof("Ignoring line: ", string(line))
}
if err != nil {
// Don't make processing errors fatal.
Expand Down
6 changes: 3 additions & 3 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {
}

func buildCommand() []string {
virtV2vArgs := []string{"virt-v2v", "-v", "-x"}
virtV2vArgs := []string{"virt-v2v"}
source := os.Getenv("V2V_source")

if !isValidSource(source) {
Expand Down Expand Up @@ -199,7 +199,7 @@ func executeVirtV2v(source string, args []string) (err error) {
fmt.Printf("Error setting up stdout pipe: %v\n", err)
return
}
teeOut := io.TeeReader(virtV2vStdoutPipe, os.Stdout)
//teeOut := io.TeeReader(virtV2vStdoutPipe, os.Stdout)

var teeErr io.Reader
if source == OVA {
Expand All @@ -220,7 +220,7 @@ func executeVirtV2v(source string, args []string) (err error) {
}

virtV2vMonitorCmd := exec.Command("/usr/local/bin/virt-v2v-monitor")
virtV2vMonitorCmd.Stdin = teeOut
virtV2vMonitorCmd.Stdin = virtV2vStdoutPipe
virtV2vMonitorCmd.Stdout = os.Stdout
virtV2vMonitorCmd.Stderr = os.Stderr

Expand Down

0 comments on commit 1a8727c

Please sign in to comment.