function* createVm (action) {
  const correlationId = action.meta && action.meta.correlationId

  // Create the VM
  const createVmResult = yield callExternalAction('createVm', Api.addNewVm, action)
  const successCreate = !!createVmResult.id

  // Log the success of the action via correlation id
  if (correlationId) {
    yield put(A.setVmActionResult({
      correlationId,
      result: successCreate ? createVmResult.id : false,
    }))
  }

  // if the VM was created, and if one is provided, load the CD
  let successChangeCd = successCreate && !action.payload.cdrom
  if (successCreate && action.payload.cdrom) {
    const changeCdResult = yield changeVmCdRom(A.changeVmCdRom({
      vmId: createVmResult.id,
      cdrom: action.payload.cdrom,
      current: false,
      updateVm: false, // don't auto-refresh the VM since it hasn't been loaded yet
    }, {
      correlationId,
    }))
    successChangeCd = !changeCdResult.error
  }

  // Navigate to (or just load) the VM's details
  if (successCreate && successChangeCd) {
    const vmId = createVmResult.id
    if (action.payload.pushToDetailsOnSuccess) {
      yield put(A.navigateToVmDetails(`/vm/${vmId}`))
    } else {
      yield fetchSingleVm(A.getSingleVm({ vmId }))
    }
    return vmId
  }

  return -1
}
/*
 * Create a new VM, fetch it and optionally push the user to the VM detail page
 * for the new VM.
 */
Create a new VM, fetch it and optionally push the user to the VM detail page
for the new VM.
Create a new VM fetch it and optionally push the user to the VM detail page for the new VM .
function* createVm (action) {
  const correlationId = action.meta && action.meta.correlationId
  const createVmResult = yield callExternalAction('createVm', Api.addNewVm, action)
  const successCreate = !!createVmResult.id
  if (correlationId) {
    yield put(A.setVmActionResult({
      correlationId,
      result: successCreate ? createVmResult.id : false,
    }))
  }
  let successChangeCd = successCreate && !action.payload.cdrom
  if (successCreate && action.payload.cdrom) {
    const changeCdResult = yield changeVmCdRom(A.changeVmCdRom({
      vmId: createVmResult.id,
      cdrom: action.payload.cdrom,
      current: false,
      updateVm: false, 
    }, {
      correlationId,
    }))
    successChangeCd = !changeCdResult.error
  }
  if (successCreate && successChangeCd) {
    const vmId = createVmResult.id
    if (action.payload.pushToDetailsOnSuccess) {
      yield put(A.navigateToVmDetails(`/vm/${vmId}`))
    } else {
      yield fetchSingleVm(A.getSingleVm({ vmId }))
    }
    return vmId
  }
  return -1
}
function * createVm ( action ) { const correlationId = action . meta && action . meta . correlationId const createVmResult = yield callExternalAction ( 'createVm' , Api . addNewVm , action ) const successCreate = ! ! createVmResult . id if ( correlationId ) { yield put ( A . setVmActionResult ( { correlationId , result : successCreate ? createVmResult . id : false , } ) ) } let successChangeCd = successCreate && ! action . payload . cdrom if ( successCreate && action . payload . cdrom ) { const changeCdResult = yield changeVmCdRom ( A . changeVmCdRom ( { vmId : createVmResult . id , cdrom : action . payload . cdrom , current : false , updateVm : false , } , { correlationId , } ) ) successChangeCd = ! changeCdResult . error } if ( successCreate && successChangeCd ) { const vmId = createVmResult . id if ( action . payload . pushToDetailsOnSuccess ) { yield put ( A . navigateToVmDetails ( ` ${ vmId } ` ) ) } else { yield fetchSingleVm ( A . getSingleVm ( { vmId } ) ) } return vmId } return - 1 }
Create a new VM, fetch it and optionally push the user to the VM detail page
 for the new VM.
Create a new VM fetch it and optionally push the user to the VM detail page for the new VM .
// Create the VM // Log the success of the action via correlation id // if the VM was created, and if one is provided, load the CD // don't auto-refresh the VM since it hasn't been loaded yet // Navigate to (or just load) the VM's details