Revision 76431533

b/lib/hypervisor/hv_kvm.py
37 37
from ganeti import errors
38 38
from ganeti import serializer
39 39
from ganeti import objects
40
from ganeti import uidpool
41
from ganeti import ssconf
40 42
from ganeti.hypervisor import hv_base
41 43

  
42 44

  
......
559 561
    kvm_nics = [objects.NIC.FromDict(snic) for snic in serialized_nics]
560 562
    return (kvm_cmd, kvm_nics, hvparams)
561 563

  
564
  def _RunKVMCmd(self, name, kvm_cmd):
565
    """Run the KVM cmd and check for errors
566

  
567
    @type name: string
568
    @param name: instance name
569
    @type kvm_cmd: list of strings
570
    @param kvm_cmd: runcmd input for kvm
571

  
572
    """
573
    result = utils.RunCmd(kvm_cmd)
574
    if result.failed:
575
      raise errors.HypervisorError("Failed to start instance %s: %s (%s)" %
576
                                   (name, result.fail_reason, result.output))
577
    if not self._InstancePidAlive(name)[2]:
578
      raise errors.HypervisorError("Failed to start instance %s" % name)
579

  
562 580
  def _ExecuteKVMRuntime(self, instance, kvm_runtime, incoming=None):
563 581
    """Execute a KVM cmd, after completing it with some last minute data
564 582

  
......
607 625
        raise errors.HypervisorError("Failed to open VNC password file %s: %s"
608 626
                                     % (vnc_pwd_file, err))
609 627

  
610
    result = utils.RunCmd(kvm_cmd)
611
    if result.failed:
612
      raise errors.HypervisorError("Failed to start instance %s: %s (%s)" %
613
                                   (name, result.fail_reason, result.output))
614

  
615
    if not self._InstancePidAlive(name)[2]:
616
      raise errors.HypervisorError("Failed to start instance %s" % name)
628
    if security_model == constants.HT_SM_POOL:
629
      ss = ssconf.SimpleStore()
630
      uid_pool = uidpool.ParseUidPool(ss.GetUidPool(), separator="\n")
631
      all_uids = set(uidpool.ExpandUidPool(uid_pool))
632
      uid = uidpool.RequestUnusedUid(all_uids)
633
      try:
634
        username = pwd.getpwuid(uid.GetUid()).pw_name
635
        kvm_cmd.extend(["-runas", username])
636
        self._RunKVMCmd(name, kvm_cmd)
637
      except:
638
        uidpool.ReleaseUid(uid)
639
        raise
640
      else:
641
        uid.Unlock()
642
        utils.WriteFile(self._InstanceUidFile(name), data=str(uid))
643
    else:
644
      self._RunKVMCmd(name, kvm_cmd)
617 645

  
618 646
    if vnc_pwd:
619 647
      change_cmd = 'change vnc password %s' % vnc_pwd
......
892 920
      if hvparams[constants.HV_SECURITY_DOMAIN]:
893 921
        raise errors.HypervisorError("Cannot have a security domain when the"
894 922
                                     " security model is 'none' or 'pool'")
895
    if security_model == constants.HT_SM_POOL:
896
      raise errors.HypervisorError("Security model pool is not supported yet")
897 923

  
898 924
  @classmethod
899 925
  def ValidateParameters(cls, hvparams):

Also available in: Unified diff