internal/upload: add import.ova support to vmware

This commit is contained in:
Sanne Raymaekers 2023-03-31 14:08:09 +02:00
parent e91dcae110
commit 967306bc47
2 changed files with 47 additions and 16 deletions

View file

@ -1,7 +1,6 @@
package vmware
import (
"errors"
"fmt"
"github.com/vmware/govmomi/govc/cli"
@ -17,9 +16,9 @@ type Credentials struct {
Datastore string
}
// UploadImage is a function that uploads a stream optimized vmdk image to vSphere
// ImportVmdk is a function that uploads a stream optimized vmdk image to vSphere
// uploaded image will be present in a directory of the same name
func UploadImage(creds Credentials, imagePath string) error {
func ImportVmdk(creds Credentials, imagePath string) error {
args := []string{
"import.vmdk",
fmt.Sprintf("-u=%s:%s@%s", creds.Username, creds.Password, creds.Host),
@ -32,7 +31,27 @@ func UploadImage(creds Credentials, imagePath string) error {
retcode := cli.Run(args)
if retcode != 0 {
return errors.New("importing vmdk failed")
return fmt.Errorf("importing %s into vSphere failed", imagePath)
}
return nil
}
func ImportOva(creds Credentials, imagePath, targetName string) error {
args := []string{
"import.ova",
fmt.Sprintf("-u=%s:%s@%s", creds.Username, creds.Password, creds.Host),
"-k=true",
fmt.Sprintf("-pool=%s/Resources", creds.Cluster),
fmt.Sprintf("-dc=%s", creds.Datacenter),
fmt.Sprintf("-ds=%s", creds.Datastore),
fmt.Sprintf("-name=%s", targetName),
imagePath,
}
retcode := cli.Run(args)
if retcode != 0 {
return fmt.Errorf("importing %s into vSphere failed", imagePath)
}
return nil
}