Revision a05ff8a2 lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
42 42
  import affinity   # pylint: disable=F0401
43 43
except ImportError:
44 44
  affinity = None
45
try:
46
  import fdsend   # pylint: disable=F0401
47
except ImportError:
48
  fdsend = None
45 49

  
46 50
from ganeti import utils
47 51
from ganeti import constants
......
1928 1932

  
1929 1933
    dev.pci = int(free)
1930 1934

  
1935
  def HotplugSupported(self, instance, action, dev_type):
1936
    """Check if hotplug is supported.
1937

  
1938
    Hotplug is *not* supported in case of:
1939
     - qemu versions < 1.0
1940
     - security models and chroot (disk hotplug)
1941
     - fdsend module is missing (nic hot-add)
1942

  
1943
    @raise errors.HypervisorError: in previous cases
1944

  
1945
    """
1946
    output = self._CallMonitorCommand(instance.name, self._INFO_VERSION_CMD)
1947
    # TODO: search for netdev_add, drive_add, device_add.....
1948
    match = self._INFO_VERSION_RE.search(output.stdout)
1949
    if not match:
1950
      raise errors.HotplugError("Try hotplug only in running instances.")
1951
    v_major, v_min, _, _ = match.groups()
1952
    if (v_major, v_min) < (1, 0):
1953
      raise errors.HotplugError("Hotplug not supported for qemu versions < 1.0")
1954

  
1955
    if dev_type == constants.HOTPLUG_TARGET_DISK:
1956
      hvp = instance.hvparams
1957
      security_model = hvp[constants.HV_SECURITY_MODEL]
1958
      use_chroot = hvp[constants.HV_KVM_USE_CHROOT]
1959
      if use_chroot:
1960
        raise errors.HotplugError("Disk hotplug is not supported"
1961
                                  " in case of chroot.")
1962
      if security_model != constants.HT_SM_NONE:
1963
        raise errors.HotplugError("Disk Hotplug is not supported in case"
1964
                                  " security models are used.")
1965

  
1966
    if (dev_type == constants.HOTPLUG_TARGET_NIC and
1967
        action == constants.HOTPLUG_ACTION_ADD and not fdsend):
1968
      raise errors.HotplugError("Cannot hot-add NIC."
1969
                                " fdsend python module is missing.")
1970
    return True
1971

  
1972
  def _CallHotplugCommand(self, name, cmd):
1973
    output = self._CallMonitorCommand(name, cmd)
1974
    # TODO: parse output and check if succeeded
1975
    for line in output.stdout.splitlines():
1976
      logging.info("%s", line)
1977

  
1931 1978
  @classmethod
1932 1979
  def _ParseKVMVersion(cls, text):
1933 1980
    """Parse the KVM version from the --help output.

Also available in: Unified diff