Revision 5905901c lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
111 111

  
112 112
    return (pidfile, pid, alive)
113 113

  
114
  def _CheckDown(self, instance_name):
115
    """Raises an error unless the given instance is down.
116

  
117
    """
118
    alive = self._InstancePidAlive(instance_name)[2]
119
    if alive:
120
      raise errors.HypervisorError("Failed to start instance %s: %s" %
121
                                   (instance_name, "already running"))
122

  
114 123
  @classmethod
115 124
  def _InstanceMonitor(cls, instance_name):
116 125
    """Returns the instance monitor socket name
......
477 486
    @param incoming: (target_host_ip, port)
478 487

  
479 488
    """
480
    pidfile, _, alive = self._InstancePidAlive(instance.name)
481 489
    hvp = instance.hvparams
482
    if alive:
483
      raise errors.HypervisorError("Failed to start instance %s: %s" %
484
                                   (instance.name, "already running"))
490
    name = instance.name
491
    self._CheckDown(name)
485 492

  
486 493
    temp_files = []
487 494

  
......
519 526
    result = utils.RunCmd(kvm_cmd)
520 527
    if result.failed:
521 528
      raise errors.HypervisorError("Failed to start instance %s: %s (%s)" %
522
                                   (instance.name, result.fail_reason,
523
                                    result.output))
529
                                   (name, result.fail_reason, result.output))
524 530

  
525
    if not utils.IsProcessAlive(utils.ReadPidFile(pidfile)):
526
      raise errors.HypervisorError("Failed to start instance %s" %
527
                                   (instance.name))
531
    if not self._InstancePidAlive(name)[2]:
532
      raise errors.HypervisorError("Failed to start instance %s" % name)
528 533

  
529 534
    if vnc_pwd:
530 535
      change_cmd = 'change vnc password %s' % vnc_pwd
......
537 542
    """Start an instance.
538 543

  
539 544
    """
540
    pidfile, pid, alive = self._InstancePidAlive(instance.name)
541
    if alive:
542
      raise errors.HypervisorError("Failed to start instance %s: %s" %
543
                                   (instance.name, "already running"))
544

  
545
    self._CheckDown(instance.name)
545 546
    kvm_runtime = self._GenerateKVMRuntime(instance, block_devices)
546 547
    self._SaveKVMRuntime(instance, kvm_runtime)
547 548
    self._ExecuteKVMRuntime(instance, kvm_runtime)

Also available in: Unified diff