function* composeAndCreateVm ({ payload: { basic, nics, disks }, meta: { correlationId } }) {
  const osType = yield select(state => state.operatingSystems.getIn([ basic.operatingSystemId, 'name' ]))
  const memory = basic.memory * (1024 ** 2) // input in MiB, stored in bytes
  const memoryPolicy = yield createMemoryPolicyFromCluster(basic.clusterId, memory)

  // Common parts
  const vm = {
    cluster: { id: basic.clusterId },
    cpu: { topology: yield createCpuTopology(basic.cpus) },
    description: basic.description,
    memory_policy: memoryPolicy,
    memory,
    name: basic.name,
    os: { type: osType },
    type: basic.optimizedFor,

    initialization: basic.cloudInitEnabled
      ? {
        authorized_ssh_keys: basic.initSshKeys,
        custom_script: basic.initCustomScript,
        host_name: basic.initHostname,
        root_password: basic.initAdminPassword,
        timezone: basic.initTimezone,
      }
      : {},
  }

  // Provision = ISO (setup boot to CD and "insert" the CD after the VM is created)
  let cdrom
  if (basic.provisionSource === 'iso') {
    // TODO: Verify that we absolutely need to create VM then change CD.
    cdrom = {
      fileId: basic.isoImage,
    }

    merge(vm, {
      template: { id: yield select(state => state.config.get('blankTemplateId')) },

      os: {
        boot: {
          devices: {
            device: [ 'cdrom' ],
          },
        },
      },
    })
  }

  // Provision = TEMPLATE
  if (basic.provisionSource === 'template') {
    const template = yield select(state => state.templates.get(basic.templateId))
    merge(vm, {
      template: { id: template.get('id') },

      cpu: {
        topology: (basic.cpus === template.getIn(['cpu', 'vCPUs']))
          ? template.getIn(['cpu', 'topology']).toJS()
          : vm.cpu.topology,
      },
    })

    // TODO: TimeZone handling (https://github.com/oVirt/ovirt-web-ui/pull/1118)
  }

  /*
   * NOTE: The VM create REST service does not handle adding NICs or Disks. Until
   *       the create service supports this, we will add Nics and Disks individually
   *       after the VM has been created and is no longer image locked.
   */

  const clone = false // TODO: Clone from template based on criteria
  const clonePermissions = basic.provisionSource === 'template'

  const newVmId = yield createVm(
    A.createVm({ vm, cdrom, clone, clonePermissions, transformInput: false }, { correlationId })
  )

  if (newVmId === -1) {
    return
  }

  // Wait for the VM image to be unlocked before adding NICs and Disks
  yield waitForVmToBeUnlocked(newVmId)

  // Assuming NICs cannot be added along with the VM create request, add them now
  yield all(nics.filter(nic => !nic.isFromTemplate).map(nic =>
    call(addVmNic, A.addVmNic({
      vmId: newVmId,
      nic: {
        name: nic.name,
        plugged: true,
        linked: true,
        vnicProfile: { id: nic.vnicProfileId },
        interface: nic.deviceType,
      },
    }))
  ))

  // Assuming Disks cannot be added along with the VM create request, add them now
  yield all(disks.filter(disk => !disk.isFromTemplate).map(disk =>
    call(createDiskForVm, A.createDiskForVm({
      vmId: newVmId,
      disk: {
        active: true,
        bootable: disk.bootable,
        iface: disk.iface,

        name: disk.name,
        type: 'image',
        format: disk.format,
        sparse: disk.format === 'cow',
        provisionedSize: disk.size,

        storageDomainId: disk.storageDomainId,
      },
    }))
  ))

  // start on create, but after everything else is done...
  if (newVmId !== -1 && basic.startOnCreation) {
    yield put(A.startVm({ vmId: newVmId }))
  }
}
/**
 * Compose the VM as JSON consumable directly by the REST API and
 * send it to be created.
 *
 * @see http://ovirt.github.io/ovirt-engine-api-model/master/#types/vm
 */
Compose the VM as JSON consumable directly by the REST API and
send it to be created.


Compose the VM as JSON consumable directly by the REST API and send it to be created .
function* composeAndCreateVm ({ payload: { basic, nics, disks }, meta: { correlationId } }) {
  const osType = yield select(state => state.operatingSystems.getIn([ basic.operatingSystemId, 'name' ]))
  const memory = basic.memory * (1024 ** 2) 
  const memoryPolicy = yield createMemoryPolicyFromCluster(basic.clusterId, memory)
  const vm = {
    cluster: { id: basic.clusterId },
    cpu: { topology: yield createCpuTopology(basic.cpus) },
    description: basic.description,
    memory_policy: memoryPolicy,
    memory,
    name: basic.name,
    os: { type: osType },
    type: basic.optimizedFor,
    initialization: basic.cloudInitEnabled
      ? {
        authorized_ssh_keys: basic.initSshKeys,
        custom_script: basic.initCustomScript,
        host_name: basic.initHostname,
        root_password: basic.initAdminPassword,
        timezone: basic.initTimezone,
      }
      : {},
  }
  let cdrom
  if (basic.provisionSource === 'iso') {
    cdrom = {
      fileId: basic.isoImage,
    }
    merge(vm, {
      template: { id: yield select(state => state.config.get('blankTemplateId')) },
      os: {
        boot: {
          devices: {
            device: [ 'cdrom' ],
          },
        },
      },
    })
  }
  if (basic.provisionSource === 'template') {
    const template = yield select(state => state.templates.get(basic.templateId))
    merge(vm, {
      template: { id: template.get('id') },
      cpu: {
        topology: (basic.cpus === template.getIn(['cpu', 'vCPUs']))
          ? template.getIn(['cpu', 'topology']).toJS()
          : vm.cpu.topology,
      },
    })
  }
  const clone = false 
  const clonePermissions = basic.provisionSource === 'template'
  const newVmId = yield createVm(
    A.createVm({ vm, cdrom, clone, clonePermissions, transformInput: false }, { correlationId })
  )
  if (newVmId === -1) {
    return
  }
  yield waitForVmToBeUnlocked(newVmId)
  yield all(nics.filter(nic => !nic.isFromTemplate).map(nic =>
    call(addVmNic, A.addVmNic({
      vmId: newVmId,
      nic: {
        name: nic.name,
        plugged: true,
        linked: true,
        vnicProfile: { id: nic.vnicProfileId },
        interface: nic.deviceType,
      },
    }))
  ))
  yield all(disks.filter(disk => !disk.isFromTemplate).map(disk =>
    call(createDiskForVm, A.createDiskForVm({
      vmId: newVmId,
      disk: {
        active: true,
        bootable: disk.bootable,
        iface: disk.iface,
        name: disk.name,
        type: 'image',
        format: disk.format,
        sparse: disk.format === 'cow',
        provisionedSize: disk.size,
        storageDomainId: disk.storageDomainId,
      },
    }))
  ))
  if (newVmId !== -1 && basic.startOnCreation) {
    yield put(A.startVm({ vmId: newVmId }))
  }
}
function * composeAndCreateVm ( { payload : { basic , nics , disks } , meta : { correlationId } } ) { const osType = yield select ( state => state . operatingSystems . getIn ( [ basic . operatingSystemId , 'name' ] ) ) const memory = basic . memory * ( 1024 ** 2 ) const memoryPolicy = yield createMemoryPolicyFromCluster ( basic . clusterId , memory ) const vm = { cluster : { id : basic . clusterId } , cpu : { topology : yield createCpuTopology ( basic . cpus ) } , description : basic . description , memory_policy : memoryPolicy , memory , name : basic . name , os : { type : osType } , type : basic . optimizedFor , initialization : basic . cloudInitEnabled ? { authorized_ssh_keys : basic . initSshKeys , custom_script : basic . initCustomScript , host_name : basic . initHostname , root_password : basic . initAdminPassword , timezone : basic . initTimezone , } : { } , } let cdrom if ( basic . provisionSource === 'iso' ) { cdrom = { fileId : basic . isoImage , } merge ( vm , { template : { id : yield select ( state => state . config . get ( 'blankTemplateId' ) ) } , os : { boot : { devices : { device : [ 'cdrom' ] , } , } , } , } ) } if ( basic . provisionSource === 'template' ) { const template = yield select ( state => state . templates . get ( basic . templateId ) ) merge ( vm , { template : { id : template . get ( 'id' ) } , cpu : { topology : ( basic . cpus === template . getIn ( [ 'cpu' , 'vCPUs' ] ) ) ? template . getIn ( [ 'cpu' , 'topology' ] ) . toJS ( ) : vm . cpu . topology , } , } ) } const clone = false const clonePermissions = basic . provisionSource === 'template' const newVmId = yield createVm ( A . createVm ( { vm , cdrom , clone , clonePermissions , transformInput : false } , { correlationId } ) ) if ( newVmId === - 1 ) { return } yield waitForVmToBeUnlocked ( newVmId ) yield all ( nics . filter ( nic => ! nic . isFromTemplate ) . map ( nic => call ( addVmNic , A . addVmNic ( { vmId : newVmId , nic : { name : nic . name , plugged : true , linked : true , vnicProfile : { id : nic . vnicProfileId } , interface : nic . deviceType , } , } ) ) ) ) yield all ( disks . filter ( disk => ! disk . isFromTemplate ) . map ( disk => call ( createDiskForVm , A . createDiskForVm ( { vmId : newVmId , disk : { active : true , bootable : disk . bootable , iface : disk . iface , name : disk . name , type : 'image' , format : disk . format , sparse : disk . format === 'cow' , provisionedSize : disk . size , storageDomainId : disk . storageDomainId , } , } ) ) ) ) if ( newVmId !== - 1 && basic . startOnCreation ) { yield put ( A . startVm ( { vmId : newVmId } ) ) } }
Compose the VM as JSON consumable directly by the REST API and
 send it to be created.
Compose the VM as JSON consumable directly by the REST API and send it to be created .
// input in MiB, stored in bytes // Common parts // Provision = ISO (setup boot to CD and "insert" the CD after the VM is created) // TODO: Verify that we absolutely need to create VM then change CD. // Provision = TEMPLATE // TODO: TimeZone handling (https://github.com/oVirt/ovirt-web-ui/pull/1118) /*
   * NOTE: The VM create REST service does not handle adding NICs or Disks. Until
   *       the create service supports this, we will add Nics and Disks individually
   *       after the VM has been created and is no longer image locked.
   */ // TODO: Clone from template based on criteria // Wait for the VM image to be unlocked before adding NICs and Disks // Assuming NICs cannot be added along with the VM create request, add them now // Assuming Disks cannot be added along with the VM create request, add them now // start on create, but after everything else is done...