Skip to content

Commit

Permalink
Update how template disks are created
Browse files Browse the repository at this point in the history
Changes have been made to following how Admin Portal works when
creating VMs from a template.  How template disks are created depends
on (1) the VM's optimized for selection, and (2) if a new storage
domain needs to be selected.

The VM's "Optimized For" selection drives the default disk type for
the template disks.  In Admin Portal, selecting **Desktop** resets
the "Storage Allocation" selection to **Thin**.  Selecting **Server**
or **High Performance** resets "Storage Allocation" to **Clone**.

  If VM's optimized for selection is **Desktop**:
    - behavior matches when Admin Portal **Storage Allocation** is **Thin**
    - all of the template disks' disk types are forced to "Thin Provisioned"

    - the VM create is sent:
      - `clone=true` if AT LEAST ONE of the disks has a storage domain
        that differs from the template's disk
      - `clone=false` as long as all of the template disk's storage
        domains remain unchanged

  If VM's optimized for selection is **Server**:
    - behavior matches when Admin Portal's Storage Allocation** is **Clone**
    - the template disks use the disk type as defined by the template

    - the VM create is sent `clone=true`

Fixes: #1371
  • Loading branch information
sjd78 committed Apr 8, 2021
1 parent 6f4406d commit d4bd67a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/components/CreateVmWizard/CreateVmWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,16 @@ class CreateVmWizard extends React.Component {
const canUserUseStorageDomain =
!!dataCenterStorageDomainsList.find(sd => sd.id === disk.get('storageDomainId'))

/*
* To be consistent with webadmin VM creation from a template:
* - desktop: diskType forced to 'thin' (match storage allocation = Thin)
* - server: diskType as defined in the template (match storage allocation = Clone)
* - any other optimizedFor: follow server's logic
*/
const diskType = // constrain to values from createDiskTypeList()
this.state.steps.basic.optimizedFor === 'desktop'
this.state.steps.basic.optimizedFor !== 'desktop'
? disk.get('sparse') ? 'thin' : 'pre'
: 'pre'
: 'thin'

return {
id: disk.get('attachmentId'),
Expand Down
16 changes: 8 additions & 8 deletions src/sagas/vmChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,23 @@ function* composeProvisionSourceTemplate ({ vm, basic, disks }) {
id: disk.id,
}

// did the diskType change? 'thin' === sparse, 'pre' === !sparse
const templateDiskType = templateDisk.get('sparse') ? 'thin' : 'pre'
if (disk.diskType !== templateDiskType) {
changesToTemplateDisk.sparse = disk.diskType === 'thin'
changesToTemplateDisk.format = disk.diskType === 'thin' ? 'cow' : 'sparse'
}

// did the storage domain change?
if (disk.storageDomainId !== templateDisk.get('storageDomainId')) {
vmRequiresClone = true
changesToTemplateDisk.format = 'raw'
changesToTemplateDisk.storage_domains = {
storage_domain: [{ id: disk.storageDomainId }],
}
}

// did the diskType (disk's sparse ) change? 'thin' === sparse, 'pre' === !sparse
const templateDiskType = templateDisk.get('sparse') ? 'thin' : 'pre'
if (disk.diskType !== templateDiskType) {
changesToTemplateDisk.sparse = disk.diskType === 'thin'
}

if (Object.keys(changesToTemplateDisk).length > 1) {
vmRequiresClone = true

if (vmUpdates.disk_attachments) {
// add another disk to clone
vmUpdates.disk_attachments.disk_attachment.push({ disk: changesToTemplateDisk })
Expand Down

0 comments on commit d4bd67a

Please sign in to comment.