Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Folder create on #traverse only creates Parent (not recursive?) #110

Open
Brunzer opened this issue May 2, 2017 · 4 comments
Open

Folder create on #traverse only creates Parent (not recursive?) #110

Brunzer opened this issue May 2, 2017 · 4 comments

Comments

@Brunzer
Copy link

Brunzer commented May 2, 2017

I'm trying to use the traverse method for folders to create a new Folder path within a DC. The top level folder gets created just fine but it doesn't follow through to create the children that I have specified.

My Code:

vim = RbVmomi::VIM.connect(host: 'some host', user: 'some user', password: 'my pass', insecure: true)
dc = vim.serviceInstance.find_datacenter('MyDataCenter') || fail('datacenter not found')

folder = dc.vmFolder.traverse!('Parent/Child', type = Object)

This code creates the "Parent" folder, but seems to ignore the "Child" folder in the path supplied.

Version of rbvmomi is 1.11.2, version of vsphere is 6.0.0

@jrgarcia
Copy link
Contributor

jrgarcia commented May 2, 2017

Not sure​ about this. I'll take a look and see what I can find. Thanks for reporting!

@Brunzer
Copy link
Author

Brunzer commented May 2, 2017

Seems like it might just not be creating the leaf folder. I attempted changing the path to 'Parent/Child/Offspring' and both Parent and Child folders were created, but not Offspring.

Also attempted just passing 'Parent/Child/' to see if the code was maybe just looking for the trailing slash, but that didn't do the trick

@jrgarcia jrgarcia self-assigned this May 2, 2017
@Brunzer
Copy link
Author

Brunzer commented May 29, 2017

I found out why the leaf folder isn't being created, though I'm not sure what the best approach (if any) would be for a patch.

In the traverse method, the path is split into an array and then the last object is popped off (the leaf folder in my case). The original path/array is then created successfully as we already know.

The problem comes in the next section in the if statements. In order to create the folder correctly, it needs to fall into the elsif create and type == RbVmomi::VIM::Folder statement, which it doesn't because I was relying on the default of "Object" for type.

Simply supplying the type of RbVmomi::VIM::Folder in my code made this work.

Ex.

folder = dc.vmFolder.traverse!('Parent/Child', RbVmomi::VIM::Folder)

Curious if there is a way to simplify this for folder creations. A few thoughts came to mind:

  1. Simply do not pop off the last element in the array unless the type is RbVmomi::VIM::Datacenter, though this may break the first if statement that performs a find.
  2. Bump the Folder create elsif statement to after the Datacenter create statement, and remove the condition on the type (ie. assume we are creating a folder if create = true).
    Ex.
if x = p.find(final, type)
  x
elsif create and type == RbVmomi::VIM::Datacenter
  p.CreateDatacenter(:name => final)
elsif create
  p.CreateFolder(:name => final)
else
  nil
end

Any reason why #2 might not work or if it would break something else?

@jrgarcia
Copy link
Contributor

Sorry, I never mentioned it. I found the issue to this (the same as you). My concern with changing this is changing how others use this. If people previously used this to create all folders up to the last, then this would be a breaking change. Let me think think on this for a day. I'll make a change either today or tomorrow. Thanks!

@jrgarcia jrgarcia removed their assignment Apr 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants