Skip to content

Commit

Permalink
[MTV-595] Add checks before running virt-v2v customize step (#992)
Browse files Browse the repository at this point in the history
Ref: 
https://issues.redhat.com/browse/MTV-595

Addressing:

#984 (review)

**Issue:**
We run the virt-v2v customization step in cases we know it is not needed

**Fix:**
Add checks, and exit the customization script when we identify that it's
not neededL
  - We can't parse .xml ( or .yaml in future ) virt-v2v output
  - We don't recognize the OS name
  - We did not find any disks to customize

Signed-off-by: yaacov <[email protected]>
  • Loading branch information
yaacov authored Aug 22, 2024
1 parent 38ac6c9 commit ef4b47d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {
fmt.Println("Error getting XML file:", err)
os.Exit(1)
}
// If needed, customize the VM

err = customizeVM(source, xmlFilePath)
if err != nil {
fmt.Println("Error customizing the VM:", err)
Expand Down Expand Up @@ -93,18 +93,38 @@ func getVmDiskPaths(domain *OvaVmconfig) []string {

func customizeVM(source string, xmlFilePath string) error {
domain, err := GetDomainFromXml(xmlFilePath)
disks := getVmDiskPaths(domain)
if err != nil {
fmt.Printf("Error mapping xml to ova: %v\n", err)
fmt.Printf("Error mapping xml to domain: %v\n", err)

// No customization if we can't parse virt-v2v output.
return err
}

// Get operating system.
operatingSystem := domain.Metadata.LibOsInfo.V2VOS.ID
if operatingSystem == "" {
fmt.Printf("No operating system found")
fmt.Printf("Warning: no operating system found")

// No customization when no known OS detected.
return nil
} else {
fmt.Printf("Operating System ID: %s\n", operatingSystem)
}

// Get domain disks.
disks := getVmDiskPaths(domain)
if len(disks) == 0 {
fmt.Printf("Warning: no V2V domain disks found")

// No customization when no disks found.
return nil
} else {
fmt.Printf("V2V domain disks: %v\n", disks)
}

// Customization for vSphere source.
if source == vSphere {
// Windows
if strings.Contains(operatingSystem, "win") {
err = CustomizeWindows(disks)
if err != nil {
Expand All @@ -113,6 +133,7 @@ func customizeVM(source string, xmlFilePath string) error {
}
}
}

return nil
}

Expand Down

0 comments on commit ef4b47d

Please sign in to comment.