Revision d7583563 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
......
1921 1925

  
1922 1926
    dev.pci = int(free)
1923 1927

  
1928
  def HotplugSupported(self, instance, action, dev_type):
1929
    """Check if hotplug is supported.
1930

  
1931
    Hotplug is *not* supported in case of:
1932
     - qemu versions < 1.0
1933
     - security models and chroot (disk hotplug)
1934
     - fdsend module is missing (nic hot-add)
1935

  
1936
    @raise errors.HypervisorError: in previous cases
1937

  
1938
    """
1939
    output = self._CallMonitorCommand(instance.name, self._INFO_VERSION_CMD)
1940
    # TODO: search for netdev_add, drive_add, device_add.....
1941
    match = self._INFO_VERSION_RE.search(output.stdout)
1942
    if not match:
1943
      raise errors.HotplugError("Try hotplug only in running instances.")
1944
    v_major, v_min, _, _ = match.groups()
1945
    if (v_major, v_min) < (1, 0):
1946
      raise errors.HotplugError("Hotplug not supported for qemu versions < 1.0")
1947

  
1948
    if dev_type == constants.HOTPLUG_TARGET_DISK:
1949
      hvp = instance.hvparams
1950
      security_model = hvp[constants.HV_SECURITY_MODEL]
1951
      use_chroot = hvp[constants.HV_KVM_USE_CHROOT]
1952
      if use_chroot:
1953
        raise errors.HotplugError("Disk hotplug is not supported"
1954
                                  " in case of chroot.")
1955
      if security_model != constants.HT_SM_NONE:
1956
        raise errors.HotplugError("Disk Hotplug is not supported in case"
1957
                                  " security models are used.")
1958

  
1959
    if (dev_type == constants.HOTPLUG_TARGET_NIC and
1960
        action == constants.HOTPLUG_ACTION_ADD and not fdsend):
1961
      raise errors.HotplugError("Cannot hot-add NIC."
1962
                                " fdsend python module is missing.")
1963
    return True
1964

  
1965
  def _CallHotplugCommand(self, name, cmd):
1966
    output = self._CallMonitorCommand(name, cmd)
1967
    # TODO: parse output and check if succeeded
1968
    for line in output.stdout.splitlines():
1969
      logging.info("%s", line)
1970

  
1924 1971
  @classmethod
1925 1972
  def _ParseKVMVersion(cls, text):
1926 1973
    """Parse the KVM version from the --help output.

Also available in: Unified diff