chef-boneyard / chef-provisioning-vsphere

DEPRECATED: A chef-provisioning provisioner for VMware vSphere
MIT License
17 stars 15 forks source link

Networks under a distributed switch not at the rootFolder cannot be found #56

Closed Brunzer closed 6 years ago

Brunzer commented 7 years ago

Versions:

Platform Details

Scenario:

Chef-provisioning runs cannot find the specified network if the distributed switch is not at the rootFolder. I have a folder which holds the distributed switch and then the networks under that switch. Provisioning continuously states that "vSphere Network not found"

Steps to Reproduce:

Create a folder in vSphere and place your distributed switch in it. Then create a network within that switch. Attempt a provisioning run using that network and it will fail when it attempts to find the network.

Expected Result:

Looking for a network in vsphere should traverse any folders until you get to the leaf object where the network(s) would be stored

Actual Result:

>>>> Caused by RuntimeError: vSphere Network not found [myNetworkName]
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb:406:in `find_network'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb:296:in `backing_info_for'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb:270:in `block in network_device_changes'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb:268:in `each_index'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/vsphere_helpers.rb:268:in `network_device_changes'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/clone_spec_builder.rb:46:in `build'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/driver.rb:668:in `clone_vm'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/driver.rb:223:in `find_or_create_vm'
C:/Users/mahuser/AppData/Local/chefdk/gem/ruby/2.4.0/gems/chef-provisioning-vsphere-2.0.6/lib/chef/provisioning/vsphere_driver/driver.rb:168:in `allocate_machine'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-provisioning-2.4.0/lib/chef/provisioning/driver.rb:241:in `block in allocate_machines'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:263:in `process_input'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:253:in `process_one'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/chef_fs/parallelizer.rb:92:in `call'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20-universal-mingw32/lib/chef/chef_fs/parallelizer.rb:92:in `worker_loop'

This seems similar to an issue from a while back with trying to find the Datacenter that is within a folder. That issue for reference was https://github.com/chef-partners/chef-provisioning-vsphere/issues/23

Brunzer commented 7 years ago

I took a look at the code for the find_network() method and there's a split occuring on "/", so it seems as though we could specify a path for the network in the field network_name rather than just the name of the network.

    def find_network(name)
      base = datacenter.networkFolder
      entity_array = name.split("/").reject(&:empty?)
      entity_array.each do |item|
        case base
        when RbVmomi::VIM::Folder
          base = base.find(item)
        when RbVmomi::VIM::VmwareDistributedVirtualSwitch
          idx = base.summary.portgroupName.find_index(item)
          base = idx.nil? ? nil : base.portgroup[idx]
        end
      end

      raise "vSphere Network not found [#{name}]" if base.nil?

      base
    end

I tested that out by specifying `network_name = 'foldername/networkname'" and sure enough I was able to find the network in this case, though this raises another question.

What's the proper way to specify your network_name if it's located in a port group that is within a folder rather than at the root level? Technically the path in vsphere to my network would be 'folder_name/portgroup_name/network_name', but omitting the portgroup_name in my network_name ensured that the network was actually found.

jjasghar commented 7 years ago

I think we'll have to patch that find_network method to get this fixed for you @Brunzer :(

If you'd like to take a shot at it and PR it I'd love to see it.