 }) ->
   try
     # TODO: map multiple VDI and VIF
+    VM = @getObject id, 'VM'
     host = @getObject target_host_id, 'host'
-    migrationNetwork = @getObject migration_network_id, 'network'
-    network = @getObject target_network_id, 'network'
-    SR = @getObject target_sr_id, 'SR'
-    VM = @getObject id, 'VM'
+
+    # Optional parameters
+    # if no target_network_id given, try to use the management network
+    network = if target_network_id
+      @getObject target_network_id, 'network'
+    else
+      PIF = $findWhere (@getObjects host.$PIFs), management: true
+      @getObject PIF.$network, 'network'
+
+    # if no migration_network_id given, use the target_network_id
+    migrationNetwork = if migration_network_id
+      @getObject migration_network_id, 'network'
+    else
+      network
+
+    # if no target_sr_id given, try to find the default Pool SR
+    SR = if target_sr_id
+      @getObject target_sr_id, 'SR'
+    else
+      pool = @getObject host.poolRef, 'pool'
+      target_sr_id = pool.default_SR
+      @getObject target_sr_id, 'SR'
+
   catch
     @throw 'NO_SUCH_OBJECT'
 
   unless $isVMRunning VM
     @throw 'INVALID_PARAMS', 'The VM can only be migrated when running'
+
+  vdiMap = {}
+  for vbdId in VM.$VBDs
+    VBD = @getObject vbdId, 'VBD'
+    continue if VBD.is_cd_drive
+    VDI = @getObject VBD.VDI, 'VDI'
+    vdiMap[VDI.ref] = SR.ref
+
+  vifMap = {}
+  for vifId in VM.VIFs
+    VIF = @getObject vifId, 'VIF'
+    vifMap[VIF.ref] = network.ref
 
   token = $wait (@getXAPI host).call(
     'host.migrate_receive'

    migrationNetwork.ref
    {} # Other parameters
  )

  vdiMap = {}
  for vbdId in VM.$VBDs
    VBD = @getObject vbdId, 'VBD'
    continue if VBD.is_cd_drive
    VDI = @getObject VBD.VDI, 'VDI'
    vdiMap[VDI.ref] = SR.ref

  vifMap = {}
  for vifId in VM.VIFs
    VIF = @getObject vifId, 'VIF'
    vifMap[VIF.ref] = network.ref

  $wait (@getXAPI VM).call(
    'VM.migrate_send'

  )

  return true
exports.migrate_pool.permission = 'admin'
exports.migrate_pool.params = {

  # Identifier of the VM to migrate.
  id: { type: 'string' }

  # Identifier of the host to migrate to.
  target_host_id: { type: 'string' }

  # Identifier of the target SR
  target_sr_id: { type: 'string', optional: true }

  # Identifier of the target Network
  target_network_id: { type: 'string', optional: true }

  # Identifier of the Network use for the migration
  migration_network_id: { type: 'string', optional: true }
}

exports.set = (params) ->
