chef-provisioning-vsphere icon indicating copy to clipboard operation
chef-provisioning-vsphere copied to clipboard

Network disconnected on virtual machine creation

Open geoff-carr-bzy opened this issue 7 years ago • 3 comments

Versions:

  • Version of Chef-Provisioning: 2.2.1
  • Version of Chef-Provisioning-vSphere: 2.0.2

Platform Details

  • Version of vSphere/vCenter: 5.5.0, 418647
  • Version of ESXi: 5.5.0, 356722

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

geoff-carr-bzy avatar May 17 '17 15:05 geoff-carr-bzy

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!

jjasghar avatar Jun 01 '17 19:06 jjasghar

@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?

donwlewis avatar Jun 23 '17 17:06 donwlewis

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

hrmmmwhynot avatar May 26 '18 01:05 hrmmmwhynot