Revision d8784f7d lib/hypervisor/hv_xen.py

b/lib/hypervisor/hv_xen.py
336 336
    self._cmd = _cmd
337 337

  
338 338
  def _GetCommand(self):
339
    """Returns Xen command to use.
340

  
341
    """
339 342
    if self._cmd is None:
340 343
      # TODO: Make command a hypervisor parameter
341 344
      cmd = constants.XEN_CMD
......
663 666
    @param live: perform a live migration
664 667

  
665 668
    """
666
    if self.GetInstanceInfo(instance.name) is None:
669
    port = instance.hvparams[constants.HV_MIGRATION_PORT]
670

  
671
    # TODO: Pass cluster name via RPC
672
    cluster_name = ssconf.SimpleStore().GetClusterName()
673

  
674
    return self._MigrateInstance(cluster_name, instance.name, target, port,
675
                                 live)
676

  
677
  def _MigrateInstance(self, cluster_name, instance_name, target, port, live,
678
                       _ping_fn=netutils.TcpPing):
679
    """Migrate an instance to a target node.
680

  
681
    @see: L{MigrateInstance} for details
682

  
683
    """
684
    if self.GetInstanceInfo(instance_name) is None:
667 685
      raise errors.HypervisorError("Instance not running, cannot migrate")
668 686

  
669
    port = instance.hvparams[constants.HV_MIGRATION_PORT]
687
    cmd = self._GetCommand()
670 688

  
671
    if (self._cmd == constants.XEN_CMD_XM and
672
        not netutils.TcpPing(target, port, live_port_needed=True)):
689
    if (cmd == constants.XEN_CMD_XM and
690
        not _ping_fn(target, port, live_port_needed=True)):
673 691
      raise errors.HypervisorError("Remote host %s not listening on port"
674 692
                                   " %s, cannot migrate" % (target, port))
675 693

  
676 694
    args = ["migrate"]
677 695

  
678
    if self._cmd == constants.XEN_CMD_XM:
696
    if cmd == constants.XEN_CMD_XM:
679 697
      args.extend(["-p", "%d" % port])
680 698
      if live:
681 699
        args.append("-l")
682 700

  
683
    elif self._cmd == constants.XEN_CMD_XL:
684
      cluster_name = ssconf.SimpleStore().GetClusterName()
685
      args.extend(["-s", constants.XL_SSH_CMD % cluster_name])
686
      args.extend(["-C", self._ConfigFileName(instance.name)])
701
    elif cmd == constants.XEN_CMD_XL:
702
      args.extend([
703
        "-s", constants.XL_SSH_CMD % cluster_name,
704
        "-C", self._ConfigFileName(instance_name),
705
        ])
687 706

  
688 707
    else:
689
      raise errors.HypervisorError("Unsupported xen command: %s" % self._cmd)
708
      raise errors.HypervisorError("Unsupported Xen command: %s" % self._cmd)
690 709

  
691
    args.extend([instance.name, target])
710
    args.extend([instance_name, target])
692 711

  
693 712
    result = self._RunXen(args)
694 713
    if result.failed:
695 714
      raise errors.HypervisorError("Failed to migrate instance %s: %s" %
696
                                   (instance.name, result.output))
715
                                   (instance_name, result.output))
697 716

  
698 717
  def FinalizeMigrationSource(self, instance, success, live):
699 718
    """Finalize the instance migration on the source node.

Also available in: Unified diff