Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-33129

Unable to change virtual machine port group

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Trying to change the port group of my virtual machine to one that is used for all virtual machines in a particular Resource Pool. I get a null pointer exception, when I try to use the vsphere cloud plugin. Cloud user account is able to do that through Vcenter GUI

      Building on master in workspace /var/lib/jenkins/jobs/test vcenter networking reconfiguration/workspace
      [vSphere]
      [vSphere] Performing vSphere build step: "Power-Off VM"
      [vSphere] Attempting to use server configuration: "vcenter"
      [vSphere] Shutting Down VM FW-DEV...
      [vSphere] Successfully shutdown "FW-DEV"
      [vSphere]
      [vSphere] Performing vSphere build step: "Reconfigure VM"
      [vSphere] Attempting to use server configuration: "vcenter"
      [vSphere] Reconfiguring VM "FW-DEV". Please wait ...
      [vSphere] Preparing reconfigure: Edit Network Adapter ""
      [vSphere] Reconfiguring Distributed Switch Port Group -> pgFirewall Port Id ->
      [vSphere] Exception
      org.jenkinsci.plugins.vsphere.tools.VSphereException: java.lang.NullPointerException
      at org.jenkinsci.plugins.vsphere.tools.VSphere.getDistributedVirtualSwitchByPortGroup(VSphere.java:883)
      at org.jenkinsci.plugins.vsphere.builders.ReconfigureNetworkAdapters.perform(ReconfigureNetworkAdapters.java:173)
      at org.jenkinsci.plugins.vsphere.builders.Reconfigure.reconfigureVm(Reconfigure.java:81)
      at org.jenkinsci.plugins.vsphere.builders.Reconfigure.perform(Reconfigure.java:58)
      at org.jenkinsci.plugins.vsphere.VSphereBuildStepContainer.perform(VSphereBuildStepContainer.java:91)
      at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
      at hudson.model.Build$BuildExecution.build(Build.java:205)
      at hudson.model.Build$BuildExecution.doRun(Build.java:162)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
      at hudson.model.Run.execute(Run.java:1738)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:98)
      at hudson.model.Executor.run(Executor.java:410)
      Caused by: java.lang.NullPointerException
      at org.jenkinsci.plugins.vsphere.tools.VSphere.getDistributedVirtualSwitchByPortGroup(VSphere.java:878)
      ... 13 more
      Build step 'vSphere Build Step' marked build as failure
      Finished: FAILURE

        Attachments

          Activity

          Hide
          wellu veli pekka jutila added a comment -

          It seems this is also a permission issue. Access to the port group is not enough. You need 'read' to datacenter root or something else. Maybe because of this method that I suspect crawls to the pgGroup from bottom-up. closing this issue

          getVsphere().getDistributedVirtualPortGroupByName(getVM(), expandedDistributedPortGroup);

          Show
          wellu veli pekka jutila added a comment - It seems this is also a permission issue. Access to the port group is not enough. You need 'read' to datacenter root or something else. Maybe because of this method that I suspect crawls to the pgGroup from bottom-up. closing this issue getVsphere().getDistributedVirtualPortGroupByName(getVM(), expandedDistributedPortGroup);
          Hide
          wellu veli pekka jutila added a comment -

          user must have suficient permissons to change port groups. This might include permissions to the datacenter root. Permission to the port group is not enough

          Show
          wellu veli pekka jutila added a comment - user must have suficient permissons to change port groups. This might include permissions to the datacenter root. Permission to the port group is not enough
          Hide
          jorgelon Jorge Lon added a comment - - edited

          I have the same issue and i think it is not solved because the user has administrator privileges. i have tried with pipeline and graphically. same result. this is the code in pipeline

          step([$class: 'VSphereBuildStepContainer', buildStep: [$class: 'Reconfigure', reconfigureSteps: [[$class: 'ReconfigureNetworkAdapters', deviceAction: 'ADD', deviceLabel: '', distributedSwitch: false, macAddress: env.MAC, portGroup: 'vlan2223', standardSwitch: true]], vm: 'env.VMCLONED'], serverName: 'myserver'])

          does the virtual machine name accept variables?

          and the error

          [vSphere] Performing vSphere build step: "Reconfigure VM"
          [vSphere] Attempting to use server configuration: "myserver"
          [vSphere] Reconfiguring VM "env.VMCLONED". Please wait ...
          [vSphere] Preparing reconfigure: Add Network Adapter ""
          [vSphere] Reconfiguring MAC Address -> 00:20:56:00:32:04
          [vSphere] Reconfiguring Network Port Group -> vlan2223
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: java.lang.NullPointerException
          Finished: FAILURE

          Show
          jorgelon Jorge Lon added a comment - - edited I have the same issue and i think it is not solved because the user has administrator privileges. i have tried with pipeline and graphically. same result. this is the code in pipeline step([$class: 'VSphereBuildStepContainer', buildStep: [$class: 'Reconfigure', reconfigureSteps: [ [$class: 'ReconfigureNetworkAdapters', deviceAction: 'ADD', deviceLabel: '', distributedSwitch: false, macAddress: env.MAC, portGroup: 'vlan2223', standardSwitch: true] ], vm: 'env.VMCLONED'], serverName: 'myserver']) does the virtual machine name accept variables? and the error [vSphere] Performing vSphere build step: "Reconfigure VM" [vSphere] Attempting to use server configuration: "myserver" [vSphere] Reconfiguring VM "env.VMCLONED". Please wait ... [vSphere] Preparing reconfigure: Add Network Adapter "" [vSphere] Reconfiguring MAC Address -> 00:20:56:00:32:04 [vSphere] Reconfiguring Network Port Group -> vlan2223 [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: java.lang.NullPointerException Finished: FAILURE
          Hide
          pjdarton pjdarton added a comment -

          w.r.t. the original NullPointerException, I've taken a look at the code:

           

              public DistributedVirtualSwitch getDistributedVirtualSwitchByPortGroup(
                      DistributedVirtualPortgroup distributedVirtualPortgroup) throws VSphereException
              {
                  try
                  {
                      ManagedObjectReference managedObjectReference = new ManagedObjectReference();
                      managedObjectReference.setType("DistributedVirtualSwitch");
                      managedObjectReference.setVal(distributedVirtualPortgroup.getConfig().getDistributedVirtualSwitch().getVal());
                      return new DistributedVirtualSwitch(getServiceInstance().getServerConnection(), managedObjectReference);
                  }
                  catch (Exception e)
                  {
                      throw new VSphereException(e);
                  }
              }

           

          ...and the exception that was originally reported is coming from

          distributedVirtualPortgroup.getConfig().getDistributedVirtualSwitch().getVal()

          I don't think it would be possible to prevent an exception at this point, but I guess it would be possible to make the exception a lot more friendly and return some form of "you don't have permission to do that" exception if getConfig() or getDistributedVirtualSwitch() returns null.

           

          As for accepting variable names:  As I understand it, when using pipelines, all the pipeline code is groovy, so you are free to calculate the VM name into a variable and pass that in - as far as the vSphere-plugin code is concerned, it will be being passed a string so it can't tell that the string value was calculated.  It's only if you're using the configuration WebUI for the job that you're limited to the vSphere plugin's own internal functionality.

          My guess is that your VM name of "env.VMCLONED" is not, in fact, the name of a VM, causing the code to fail to find the VM and suffer an exception at that point as a result.  My guess is that you intended to use the value of an environment variable named "VMCLONED", but you've not used the correct syntax for that (I'm not familiar with pipelines so I can't tell you what the correct syntax is, but I'm pretty sure that isn't it).

           

          Show
          pjdarton pjdarton added a comment - w.r.t. the original NullPointerException, I've taken a look at the code:       public DistributedVirtualSwitch getDistributedVirtualSwitchByPortGroup(             DistributedVirtualPortgroup distributedVirtualPortgroup) throws VSphereException     {          try         {             ManagedObjectReference managedObjectReference = new ManagedObjectReference();             managedObjectReference.setType( "DistributedVirtualSwitch" );             managedObjectReference.setVal(distributedVirtualPortgroup.getConfig().getDistributedVirtualSwitch().getVal());              return new DistributedVirtualSwitch(getServiceInstance().getServerConnection(), managedObjectReference);         }          catch (Exception e)         {              throw new VSphereException(e);         }     }   ...and the exception that was originally reported is coming from distributedVirtualPortgroup.getConfig().getDistributedVirtualSwitch().getVal() I don't think it would be possible to prevent an exception at this point, but I guess it would be possible to make the exception a lot more friendly and return some form of "you don't have permission to do that" exception if getConfig() or getDistributedVirtualSwitch() returns null.   As for accepting variable names:  As I understand it, when using pipelines, all the pipeline code is groovy, so you are free to calculate the VM name into a variable and pass that in - as far as the vSphere-plugin code is concerned, it will be being passed a string so it can't tell that the string value was calculated.  It's only if you're using the configuration WebUI for the job that you're limited to the vSphere plugin's own internal functionality. My guess is that your VM name of "env.VMCLONED" is not, in fact, the name of a VM, causing the code to fail to find the VM and suffer an exception at that point as a result.  My guess is that you intended to use the value of an environment variable named "VMCLONED", but you've not used the correct syntax for that (I'm not familiar with pipelines so I can't tell you what the correct syntax is, but I'm pretty sure that isn't it).  
          Hide
          pjdarton pjdarton added a comment -

          While the exception handling could be improved (y'all free to submit a PR for that...) this was user-error.

          Show
          pjdarton pjdarton added a comment - While the exception handling could be improved (y'all free to submit a PR for that...) this was user-error.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            wellu veli pekka jutila
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: