osbuild-worker: add target for upload to vmware
New upload target for VMWare, similar to the ones for AWS and Azure, allowing users to set credentials for their vSphere instance. Commit also includes function that performs the actual upload.
This commit is contained in:
parent
d686abfffb
commit
1a81489ef1
4 changed files with 81 additions and 0 deletions
|
|
@ -1,11 +1,25 @@
|
|||
package vmware
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
_ "github.com/vmware/govmomi/govc/importx"
|
||||
)
|
||||
|
||||
type Credentials struct {
|
||||
Host string
|
||||
Username string
|
||||
Password string
|
||||
Datacenter string
|
||||
Cluster string
|
||||
Datastore string
|
||||
}
|
||||
|
||||
func OpenAsStreamOptimizedVmdk(imagePath string) (*os.File, error) {
|
||||
newPath := strings.TrimSuffix(imagePath, ".vmdk") + "-stream.vmdk"
|
||||
cmd := exec.Command(
|
||||
|
|
@ -21,3 +35,22 @@ func OpenAsStreamOptimizedVmdk(imagePath string) (*os.File, error) {
|
|||
}
|
||||
return f, err
|
||||
}
|
||||
|
||||
func UploadImage(creds Credentials, imagePath, imageName string) error {
|
||||
args := []string{
|
||||
"import.vmdk",
|
||||
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),
|
||||
imagePath,
|
||||
imageName,
|
||||
}
|
||||
retcode := cli.Run(args)
|
||||
|
||||
if retcode != 0 {
|
||||
return errors.New("importing vmdk failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue