Revision 6a1434d7 lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
1574 1574
    incoming_address = (target, instance.hvparams[constants.HV_MIGRATION_PORT])
1575 1575
    self._ExecuteKVMRuntime(instance, kvm_runtime, incoming=incoming_address)
1576 1576

  
1577
  def FinalizeMigration(self, instance, info, success):
1578
    """Finalize an instance migration.
1577
  def FinalizeMigrationDst(self, instance, info, success):
1578
    """Finalize the instance migration on the target node.
1579 1579

  
1580 1580
    Stop the incoming mode KVM.
1581 1581

  
......
1622 1622
    """
1623 1623
    instance_name = instance.name
1624 1624
    port = instance.hvparams[constants.HV_MIGRATION_PORT]
1625
    pidfile, pid, alive = self._InstancePidAlive(instance_name)
1625
    _, _, alive = self._InstancePidAlive(instance_name)
1626 1626
    if not alive:
1627 1627
      raise errors.HypervisorError("Instance not running, cannot migrate")
1628 1628

  
......
1640 1640
    migrate_command = "migrate -d tcp:%s:%s" % (target, port)
1641 1641
    self._CallMonitorCommand(instance_name, migrate_command)
1642 1642

  
1643
  def FinalizeMigrationSource(self, instance, success, live):
1644
    """Finalize the instance migration on the source node.
1645

  
1646
    @type instance: L{objects.Instance}
1647
    @param instance: the instance that was migrated
1648
    @type success: bool
1649
    @param success: whether the migration succeeded or not
1650
    @type live: bool
1651
    @param live: whether the user requested a live migration or not
1652

  
1653
    """
1654
    if success:
1655
      pidfile, pid, _ = self._InstancePidAlive(instance.name)
1656
      utils.KillProcess(pid)
1657
      self._RemoveInstanceRuntimeFiles(pidfile, instance.name)
1658
    elif live:
1659
      self._CallMonitorCommand(instance.name, self._CONT_CMD)
1660

  
1661
  def GetMigrationStatus(self, instance):
1662
    """Get the migration status
1663

  
1664
    @type instance: L{objects.Instance}
1665
    @param instance: the instance that is being migrated
1666
    @rtype: L{objects.MigrationStatus}
1667
    @return: the status of the current migration (one of
1668
             L{constants.HV_MIGRATION_VALID_STATUSES}), plus any additional
1669
             progress info that can be retrieved from the hypervisor
1670

  
1671
    """
1643 1672
    info_command = "info migrate"
1644
    done = False
1645
    broken_answers = 0
1646
    while not done:
1647
      result = self._CallMonitorCommand(instance_name, info_command)
1673
    for _ in range(self._MIGRATION_INFO_MAX_BAD_ANSWERS):
1674
      result = self._CallMonitorCommand(instance.name, info_command)
1648 1675
      match = self._MIGRATION_STATUS_RE.search(result.stdout)
1649 1676
      if not match:
1650
        broken_answers += 1
1651 1677
        if not result.stdout:
1652 1678
          logging.info("KVM: empty 'info migrate' result")
1653 1679
        else:
1654 1680
          logging.warning("KVM: unknown 'info migrate' result: %s",
1655 1681
                          result.stdout)
1656
        time.sleep(self._MIGRATION_INFO_RETRY_DELAY)
1657 1682
      else:
1658 1683
        status = match.group(1)
1659
        if status == "completed":
1660
          done = True
1661
        elif status == "active":
1662
          # reset the broken answers count
1663
          broken_answers = 0
1664
          time.sleep(self._MIGRATION_INFO_RETRY_DELAY)
1665
        elif status == "failed" or status == "cancelled":
1666
          if not live:
1667
            self._CallMonitorCommand(instance_name, self._CONT_CMD)
1668
          raise errors.HypervisorError("Migration %s at the kvm level" %
1669
                                       status)
1670
        else:
1671
          logging.warning("KVM: unknown migration status '%s'", status)
1672
          broken_answers += 1
1673
          time.sleep(self._MIGRATION_INFO_RETRY_DELAY)
1674
      if broken_answers >= self._MIGRATION_INFO_MAX_BAD_ANSWERS:
1675
        raise errors.HypervisorError("Too many 'info migrate' broken answers")
1684
        if status in constants.HV_KVM_MIGRATION_VALID_STATUSES:
1685
          migration_status = objects.MigrationStatus(status=status)
1686
          return migration_status
1676 1687

  
1677
    utils.KillProcess(pid)
1678
    self._RemoveInstanceRuntimeFiles(pidfile, instance_name)
1688
        logging.warning("KVM: unknown migration status '%s'", status)
1689

  
1690
      time.sleep(self._MIGRATION_INFO_RETRY_DELAY)
1691

  
1692
    return objects.MigrationStatus(status=constants.HV_MIGRATION_FAILED,
1693
                                  info="Too many 'info migrate' broken answers")
1679 1694

  
1680 1695
  def GetNodeInfo(self):
1681 1696
    """Return information about the node.

Also available in: Unified diff