A backward compatibility code handling the conversion of VMDK image to stream-optimized sub-format has been kept in the implementation since PR#2529 [1] merged on May 4th 2022. Since this change, no API implementation is submitting jobs, which would hit this conversion code, because VMDK images are already being produced in the desired sub-format. On-premise deployments are expected to use the same composer and worker versions. There are no composer / worker instances in production, which are not running the modified code. Delete the backward compatibility code. [1] https://github.com/osbuild/osbuild-composer/pull/2529
38 lines
866 B
Go
38 lines
866 B
Go
package vmware
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"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
|
|
}
|
|
|
|
// UploadImage 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 {
|
|
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,
|
|
}
|
|
retcode := cli.Run(args)
|
|
|
|
if retcode != 0 {
|
|
return errors.New("importing vmdk failed")
|
|
}
|
|
return nil
|
|
}
|