applyMove nl inst (ReplacePrimary new_pdx) =
  let (old_pdx, old_sdx, old_p, old_s) = instanceNodes nl inst
      tgt_n = Container.find new_pdx nl
      int_p = Node.removePri old_p inst
      int_s = Node.removeSec old_s inst
      force_p = Node.offline old_p
      new_nl = do -- Maybe monad
                  -- check that the current secondary can host the instance
                  -- during the migration
        tmp_s <- Node.addPriEx force_p int_s inst
        let tmp_s' = Node.removePri tmp_s inst
        new_p <- Node.addPriEx force_p tgt_n inst
        new_s <- Node.addSecEx force_p tmp_s' inst new_pdx
        let new_inst = Instance.setPri inst new_pdx
        return (Container.add new_pdx new_p $
                Container.addTwo old_pdx int_p old_sdx new_s nl,
                new_inst, new_pdx, old_sdx)
  in new_nl
applyMove nl inst (ReplacePrimary new_pdx) =
  let (old_pdx, old_sdx, old_p, old_s) = instanceNodes nl inst
      tgt_n = Container.find new_pdx nl
      int_p = Node.removePri old_p inst
      int_s = Node.removeSec old_s inst
      force_p = Node.offline old_p
      new_nl = do -- Maybe monad
                  -- check that the current secondary can host the instance
                  -- during the migration
        tmp_s <- Node.addPriEx force_p int_s inst
        let tmp_s' = Node.removePri tmp_s inst
        new_p <- Node.addPriEx force_p tgt_n inst
        new_s <- Node.addSecEx force_p tmp_s' inst new_pdx
        let new_inst = Instance.setPri inst new_pdx
        return (Container.add new_pdx new_p $
                Container.addTwo old_pdx int_p old_sdx new_s nl,
                new_inst, new_pdx, old_sdx)
  in new_nl
applyMove nl inst (ReplacePrimary new_pdx) =
  let (old_pdx, old_sdx, old_p, old_s) = instanceNodes nl inst
      tgt_n = Container.find new_pdx nl
      int_p = Node.removePri old_p inst
      int_s = Node.removeSec old_s inst
      force_p = Node.offline old_p
      new_nl = do -- Maybe monad
                  -- check that the current secondary can host the instance
                  -- during the migration
        tmp_s <- Node.addPriEx force_p int_s inst
        let tmp_s' = Node.removePri tmp_s inst
        new_p <- Node.addPriEx force_p tgt_n inst
        new_s <- Node.addSecEx force_p tmp_s' inst new_pdx
        let new_inst = Instance.setPri inst new_pdx
        return (Container.add new_pdx new_p $
                Container.addTwo old_pdx int_p old_sdx new_s nl,
                new_inst, new_pdx, old_sdx)
  in new_nl