internal/vmware: add support for the GOVC_FOLDER option
When importing the ova it also creates a VM, and users don't always have permission to register in the default folder.
This commit is contained in:
parent
ce52f658d1
commit
8a8607cdf6
4 changed files with 24 additions and 12 deletions
|
|
@ -437,6 +437,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
||||||
Cluster: targetOptions.Cluster,
|
Cluster: targetOptions.Cluster,
|
||||||
Datacenter: targetOptions.Datacenter,
|
Datacenter: targetOptions.Datacenter,
|
||||||
Datastore: targetOptions.Datastore,
|
Datastore: targetOptions.Datastore,
|
||||||
|
Folder: targetOptions.Folder,
|
||||||
}
|
}
|
||||||
|
|
||||||
tempDirectory, err := os.MkdirTemp(impl.Output, job.Id().String()+"-vmware-*")
|
tempDirectory, err := os.MkdirTemp(impl.Output, job.Id().String()+"-vmware-*")
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ type VMWareTargetOptions struct {
|
||||||
Datacenter string `json:"datacenter"`
|
Datacenter string `json:"datacenter"`
|
||||||
Cluster string `json:"cluster"`
|
Cluster string `json:"cluster"`
|
||||||
Datastore string `json:"datastore"`
|
Datastore string `json:"datastore"`
|
||||||
|
Folder string `json:"folder"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (VMWareTargetOptions) isTargetOptions() {}
|
func (VMWareTargetOptions) isTargetOptions() {}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,22 @@ type Credentials struct {
|
||||||
Datacenter string
|
Datacenter string
|
||||||
Cluster string
|
Cluster string
|
||||||
Datastore string
|
Datastore string
|
||||||
|
Folder string
|
||||||
|
}
|
||||||
|
|
||||||
|
func commonOptions(creds Credentials) []string {
|
||||||
|
args := []string{
|
||||||
|
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),
|
||||||
|
}
|
||||||
|
if creds.Folder != "" {
|
||||||
|
args = append(args, fmt.Sprintf("-folder=%s", creds.Folder))
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportVmdk 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
|
||||||
|
|
@ -21,13 +37,9 @@ type Credentials struct {
|
||||||
func ImportVmdk(creds Credentials, imagePath string) error {
|
func ImportVmdk(creds Credentials, imagePath string) error {
|
||||||
args := []string{
|
args := []string{
|
||||||
"import.vmdk",
|
"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,
|
|
||||||
}
|
}
|
||||||
|
args = append(args, commonOptions(creds)...)
|
||||||
|
args = append(args, imagePath)
|
||||||
retcode := cli.Run(args)
|
retcode := cli.Run(args)
|
||||||
|
|
||||||
if retcode != 0 {
|
if retcode != 0 {
|
||||||
|
|
@ -39,14 +51,10 @@ func ImportVmdk(creds Credentials, imagePath string) error {
|
||||||
func ImportOva(creds Credentials, imagePath, targetName string) error {
|
func ImportOva(creds Credentials, imagePath, targetName string) error {
|
||||||
args := []string{
|
args := []string{
|
||||||
"import.ova",
|
"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),
|
fmt.Sprintf("-name=%s", targetName),
|
||||||
imagePath,
|
|
||||||
}
|
}
|
||||||
|
args = append(args, commonOptions(creds)...)
|
||||||
|
args = append(args, imagePath)
|
||||||
retcode := cli.Run(args)
|
retcode := cli.Run(args)
|
||||||
|
|
||||||
if retcode != 0 {
|
if retcode != 0 {
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ type vmwareUploadSettings struct {
|
||||||
Datacenter string `json:"datacenter"`
|
Datacenter string `json:"datacenter"`
|
||||||
Cluster string `json:"cluster"`
|
Cluster string `json:"cluster"`
|
||||||
Datastore string `json:"datastore"`
|
Datastore string `json:"datastore"`
|
||||||
|
Folder string `json:"folder"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vmwareUploadSettings) isUploadSettings() {}
|
func (vmwareUploadSettings) isUploadSettings() {}
|
||||||
|
|
@ -340,6 +341,7 @@ func uploadRequestToTarget(u uploadRequest, imageType distro.ImageType) *target.
|
||||||
Cluster: options.Cluster,
|
Cluster: options.Cluster,
|
||||||
Datacenter: options.Datacenter,
|
Datacenter: options.Datacenter,
|
||||||
Datastore: options.Datastore,
|
Datastore: options.Datastore,
|
||||||
|
Folder: options.Folder,
|
||||||
}
|
}
|
||||||
case *ociUploadSettings:
|
case *ociUploadSettings:
|
||||||
t.Name = target.TargetNameOCI
|
t.Name = target.TargetNameOCI
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue