Move openAsStreamOptimizedVmdk() into importable package
so it can be used later within tests
This commit is contained in:
parent
5803abfeee
commit
e7aa9c10c2
2 changed files with 28 additions and 22 deletions
26
internal/upload/vmware/vmware.go
Normal file
26
internal/upload/vmware/vmware.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package vmware
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func OpenAsStreamOptimizedVmdk(imagePath string) (*os.File, error) {
|
||||
newPath := imagePath + ".stream"
|
||||
cmd := exec.Command(
|
||||
"/usr/bin/qemu-img", "convert", "-O", "vmdk", "-o", "subformat=streamOptimized",
|
||||
imagePath, newPath)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := os.Open(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = os.Remove(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue