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

As a vSphere cloud plugin user, I cannot create VM from Jenkins pipeline because template does not have snapshot, not possible in vSphere Version 6.5.0 Build 7070488

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Blocker
    • Resolution: Unresolved
    • Component/s: vsphere-cloud-plugin
    • Labels:
      None
    • Environment:
      Jenkins Jenkins v. 2.130
      vSphere v. 6.5.0 Build 7070488
      vSphere cloud plugin v. 2.18
    • Similar Issues:

      Description

      I'm trying to create a VM from template via Jenkins pipeline using the following code

      node() {
       vSphere buildStep: [$class: 'Clone', clone: 'windwaker-gccloned', powerOn: false, sourceName: 'windwaker-gc', datastore:'Datastore2_Dev_Qa', resourcePool:'Normal'], serverName:'vcr-dev'
       }

      The code fails with the following exception: 

      ERROR: vSphere Error: Source Template "windwaker-gc" requires at least one snapshot.

       

      This was supposed to be fixed in https://issues.jenkins-ci.org/browse/JENKINS-24661

        Attachments

          Activity

          Hide
          pjdarton pjdarton added a comment -

          As far as I am aware, to clone a VM from a template, you need a snapshot in that template.

          (and you can't create a snapshot in a template, only in a VM, and you can't delete a template that contains a snapshot either - vSphere's kinda quirky that way).

          If you know different, and are willing to explain to me what vSphere rules are for creating VMs from Templates (e.g. what's needed to make a linked clone from a template, what's needed for a non-linked clone of a template etc) then I may be able to tweak the code more to your liking (or, if you want to submit a pull-request, that'd be welcome too).

          Show
          pjdarton pjdarton added a comment - As far as I am aware, to clone a VM from a template, you need a snapshot in that template. (and you can't create a snapshot in a template, only in a VM, and you can't delete a template that contains a snapshot either - vSphere's kinda quirky that way). If you know different, and are willing to explain to me what vSphere rules are for creating VMs from Templates (e.g. what's needed to make a linked clone from a template, what's needed for a non-linked clone of a template etc) then I may be able to tweak the code more to your liking (or, if you want to submit a pull-request, that'd be welcome too).
          Hide
          gcimpoies George Cimpoies added a comment -

          Hi pjdarton! To my understanding, a template can't have snapshots so the exception shouldn't be thrown. Only VMs can have snapshots, templates can't.

          Show
          gcimpoies George Cimpoies added a comment - Hi pjdarton ! To my understanding, a template can't have snapshots so the exception shouldn't be thrown. Only VMs can have snapshots, templates can't.
          Hide
          pjdarton pjdarton added a comment -

          You'd think that, wouldn't you? And it'd be perfectly sensible to expect that ... but Templates can contain snapshots, and they even need to contain snapshots for some operations.
          vSphere doesn't let you see snapshots in a template (and now doesn't even let you delete a template that contains a snapshot, claiming that the VM is in an invalid state), but any snapshots that were present in the VM that the template was made from are preserved when a VM is turned into a Template (so that's how one creates a snapshot in a Template - turn it into a VM, add/remove snapshots as needed, then turn it back into a Template).

          As far as I am aware, you need a snapshot in order to make a linked-clone. According to vSphere's documentation, setting the VirtualMachineRelocateSpec's diskMoveType field to "createNewChildDiskBacking"...

          is only safe if the clone was taken from a snapshot point, because snapshot points are always read-only. Thus for a clone this option is only valid when cloning from a snapshot.

          So, unless the vSphere documentation is wrong, to create a linked-clone VM off a Template, you need a snapshot in that Template.

          FYI what the plugin has to do is to fill out a VirtualMachineCloneSpec, which in turn contains all the data describing how the new VM is to be created. This contains the "config" field which holds the VirtualMachineRelocateSpec which is where we set diskMoveType to either "createNewChildDiskBacking" (linked clone) or "moveAllDiskBackingsAndDisallowSharing" (a full-fat copy, which usually takes ages). This also contains the "snapshot" field which I've previously found has to be non-null for a linked clone to work, even when cloning a template.

          Personally, I suspect that vSphere themselves haven't quite made up their mind what the difference is between a Template and a VM. Personally, I would've expected a Template to effectively be a VM with an implicit readonly single "Latest" snapshot and that turning a VM into a Template would remove all user-defined snapshots and leave you with just a single vSphere-defined "this is what the template looks like" snapshot within the Template and's both invisible and implicit such that cloning from that Template is always a clone based off that Template's implicit snapshot ... but that's not how it works.

          It may be, of course, that vSphere's functionality has changed over the years and my old findings are now out of date such that it'd be possible to relax some of these "you must have a snapshot, even on a template" requirements these days; if you can provide information showing this then I'm all ears

          Show
          pjdarton pjdarton added a comment - You'd think that, wouldn't you? And it'd be perfectly sensible to expect that ... but Templates can contain snapshots, and they even need to contain snapshots for some operations. vSphere doesn't let you see snapshots in a template (and now doesn't even let you delete a template that contains a snapshot, claiming that the VM is in an invalid state), but any snapshots that were present in the VM that the template was made from are preserved when a VM is turned into a Template (so that's how one creates a snapshot in a Template - turn it into a VM, add/remove snapshots as needed, then turn it back into a Template). As far as I am aware, you need a snapshot in order to make a linked-clone. According to vSphere's documentation, setting the VirtualMachineRelocateSpec's diskMoveType field to "createNewChildDiskBacking"... is only safe if the clone was taken from a snapshot point, because snapshot points are always read-only. Thus for a clone this option is only valid when cloning from a snapshot. So, unless the vSphere documentation is wrong, to create a linked-clone VM off a Template, you need a snapshot in that Template. FYI what the plugin has to do is to fill out a VirtualMachineCloneSpec , which in turn contains all the data describing how the new VM is to be created. This contains the "config" field which holds the VirtualMachineRelocateSpec which is where we set diskMoveType to either "createNewChildDiskBacking" (linked clone) or "moveAllDiskBackingsAndDisallowSharing" (a full-fat copy, which usually takes ages). This also contains the "snapshot" field which I've previously found has to be non-null for a linked clone to work, even when cloning a template. Personally, I suspect that vSphere themselves haven't quite made up their mind what the difference is between a Template and a VM. Personally, I would've expected a Template to effectively be a VM with an implicit readonly single "Latest" snapshot and that turning a VM into a Template would remove all user-defined snapshots and leave you with just a single vSphere-defined "this is what the template looks like" snapshot within the Template and's both invisible and implicit such that cloning from that Template is always a clone based off that Template's implicit snapshot ... but that's not how it works. It may be, of course, that vSphere's functionality has changed over the years and my old findings are now out of date such that it'd be possible to relax some of these "you must have a snapshot, even on a template" requirements these days; if you can provide information showing this then I'm all ears

            People

            • Assignee:
              Unassigned
              Reporter:
              gcimpoies George Cimpoies
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: