 endsWith = require 'lodash/endsWith'
 escapeStringRegexp = require 'escape-string-regexp'
 eventToPromise = require 'event-to-promise'
+maxBy = require 'lodash/maxBy'
 merge = require 'lodash/merge'
 sortBy = require 'lodash/sortBy'
 startsWith = require 'lodash/startsWith'

    vms: 1
  }
  vdiSizesByDevice = {}
  forEach(xapi.getObject(template._xapiId).$VBDs, (vbd) =>
    if (
      vbd.type is 'Disk' and
      (vdi = vbd.$VDI)

    limits.disk += size

    return $assign({}, vdi, {
      device: ++highestDevice,
      size,
      SR: sr._xapiId,
      type: vdi.type
