chef-boneyard / chef-provisioning-vsphere

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

Network disconnected on virtual machine creation #34

Open geoff-carr-bzy opened 7 years ago

geoff-carr-bzy commented 7 years ago

Versions:

Platform Details

Scenario:

Trying to deploy / clone a Windows Server 2012 R2 virtual machine from a template using Test Kitchen configuration and customization.

Steps to Reproduce:

In the VM template that we are using the network is set to the only network that the cluster has. This is a VMware Distributed Switch / port group with static binding. Whether we set the desired network within the customization section of the .kichen.yml file or leave it out the result is the same.

Expected Result:

The network should be connected in both the Virtual Machine settings and in the guest OS.

Actual Result:

Once the virtual machine comes up the network is disconnected i.e. in VM settings under Network adapter 1> Device Status the Connected and Connect at power on boxes are unchecked and the network status within the guest OS is showing as unplugged.

Possible related issues:

Issue #19: Automatically connect network by mrmarbury in CenturyLinkCloud/chef-provisioning-vsphere on GitHub Issue #100: Cloned Machines Have Disconnected Network Adapters by dan-rose in CenturyLinkCloud/chef-provisioning-vsphere on GitHub

jjasghar commented 7 years ago

Unfortunately, I don't have a 5.X ESXi or vCenter instance. I can't verify or recreate this, and I won't have that version anytime soon. I'll label this as a 5.x issue, but I don't think we'll have a fix anytime soon. That's not saying that if someone figures out the PR to fix this without breaking 6.0+ compat, I'd love to get it merged.

Thanks for the report!

donwlewis commented 7 years ago

@IcedGoblin I believe this is a problem within VSphere itself. I have seen this issue even when not leveraging chef-provisioning-vsphere. What version of distributed switch are you using?

hrmmmwhynot commented 6 years ago

Not sure if this applies to the current state of the code here, but try adding this into "driver.rb" > def clone_vm(action_handler, bootstrap_options, machine_name) right after "vm = vsphere_helper.find_vm(vm_folder, machine_name)"

      # fix network not connected after clone
      dnic = vm.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).find{|nic| nic.props}
      if dnic[:connectable][:startConnected].eql?false
          puts "Switch cloned NIC to: Connect at power on"
          dnic[:connectable][:startConnected] = true
          dnic[:connectable][:connected] = true
          dnic[:connectable][:allowGuestControl] = true
          spec = RbVmomi::VIM.VirtualMachineConfigSpec({
              :deviceChange => [{
                  :operation => :edit,
                  :device => dnic
              }]
          })
          vm.ReconfigVM_Task(:spec => spec).wait_for_completion
      end