Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
driver/vmwarevsphere: add support for subdirectories to the --vmwarev…
Browse files Browse the repository at this point in the history
…sphere-folder flag

Directories must be VM folders and paths are of the form directory/subdirectory.
It's not necessary to specify /Datacenter/vm/ prefix.

Signed-off-by: Andrew Featherstone <andrew.featherstone@cambridgeconsultants.com>
  • Loading branch information
ajfeatherstone committed Oct 16, 2017
1 parent e5c4ffa commit 1b3d44a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/vmwarevsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Network = flags.String("vmwarevsphere-network")
d.Datastore = flags.String("vmwarevsphere-datastore")
d.Datacenter = flags.String("vmwarevsphere-datacenter")
d.Folder = flags.String("vmwarevsphere-folder")
// Sanitize input on ingress.
d.Folder = strings.Trim(flags.String("vmwarevsphere-folder"), "/")
d.Pool = flags.String("vmwarevsphere-pool")
d.HostSystem = flags.String("vmwarevsphere-hostsystem")
d.SetSwarmConfigFromFlags(flags)
Expand Down Expand Up @@ -335,13 +336,13 @@ func (d *Driver) PreCreateCheck() error {
if err != nil {
return err
}
f, err := object.NewSearchIndex(c.Client).FindChild(ctx, folders.VmFolder, d.Folder)
folder, err := f.Folder(ctx, fmt.Sprintf("%s/%s", folders.VmFolder.InventoryPath, d.Folder))
// It's an error to not find the folder, or for the search itself to fail.
if err != nil {
// The search itself failed.
return err
}
if f == nil {
if folder == nil {
return fmt.Errorf("failed to find VM Folder '%s'", d.Folder)
}
}
Expand Down Expand Up @@ -463,11 +464,10 @@ func (d *Driver) Create() error {
folders, err := dc.Folders(ctx)
folder := folders.VmFolder
if d.Folder != "" {
folderRef, err := object.NewSearchIndex(c.Client).FindChild(ctx, folders.VmFolder, d.Folder)
folder, err = f.Folder(ctx, fmt.Sprintf("%s/%s", folders.VmFolder.InventoryPath, d.Folder))
if err != nil {
return err
}
folder = folderRef.(*object.Folder)
}
task, err := folder.CreateVM(ctx, spec, rp, hs)
if err != nil {
Expand Down

0 comments on commit 1b3d44a

Please sign in to comment.