Revision 89c10241 lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
2069 2069
    if (int(v_major), int(v_min)) < (1, 0):
2070 2070
      raise errors.HotplugError("Hotplug not supported for qemu versions < 1.0")
2071 2071

  
2072
  def _CallHotplugCommand(self, name, cmd):
2073
    output = self._CallMonitorCommand(name, cmd)
2074
    # TODO: parse output and check if succeeded
2075
    for line in output.stdout.splitlines():
2076
      logging.info("%s", line)
2072
  def _CallHotplugCommands(self, name, cmds):
2073
    for c in cmds:
2074
      output = self._CallMonitorCommand(name, c)
2075
      # TODO: parse output and check if succeeded
2076
      for line in output.stdout.splitlines():
2077
        logging.info("%s", line)
2078
      time.sleep(1)
2077 2079

  
2078 2080
  def HotAddDevice(self, instance, dev_type, device, extra, seq):
2079 2081
    """ Helper method to hot-add a new device
......
2088 2090
    kvm_devid = _GenerateDeviceKVMId(dev_type, device)
2089 2091
    runtime = self._LoadKVMRuntime(instance)
2090 2092
    if dev_type == constants.HOTPLUG_TARGET_DISK:
2091
      command = "drive_add dummy file=%s,if=none,id=%s,format=raw\n" % \
2092
                 (extra, kvm_devid)
2093
      command += ("device_add virtio-blk-pci,bus=pci.0,addr=%s,drive=%s,id=%s" %
2094
                  (hex(device.pci), kvm_devid, kvm_devid))
2093
      cmds = ["drive_add dummy file=%s,if=none,id=%s,format=raw" %
2094
                (extra, kvm_devid)]
2095
      cmds += ["device_add virtio-blk-pci,bus=pci.0,addr=%s,drive=%s,id=%s" %
2096
                (hex(device.pci), kvm_devid, kvm_devid)]
2095 2097
    elif dev_type == constants.HOTPLUG_TARGET_NIC:
2096 2098
      (tap, fd) = _OpenTap()
2097 2099
      self._ConfigureNIC(instance, seq, device, tap)
2098 2100
      self._PassTapFd(instance, fd, device)
2099
      command = "netdev_add tap,id=%s,fd=%s\n" % (kvm_devid, kvm_devid)
2101
      cmds = ["netdev_add tap,id=%s,fd=%s" % (kvm_devid, kvm_devid)]
2100 2102
      args = "virtio-net-pci,bus=pci.0,addr=%s,mac=%s,netdev=%s,id=%s" % \
2101 2103
               (hex(device.pci), device.mac, kvm_devid, kvm_devid)
2102
      command += "device_add %s" % args
2104
      cmds += ["device_add %s" % args]
2103 2105
      utils.WriteFile(self._InstanceNICFile(instance.name, seq), data=tap)
2104 2106

  
2105
    self._CallHotplugCommand(instance.name, command)
2107
    self._CallHotplugCommands(instance.name, cmds)
2106 2108
    # update relevant entries in runtime file
2107 2109
    index = _DEVICE_RUNTIME_INDEX[dev_type]
2108 2110
    entry = _RUNTIME_ENTRY[dev_type](device, extra)
......
2121 2123
    kvm_device = _RUNTIME_DEVICE[dev_type](entry)
2122 2124
    kvm_devid = _GenerateDeviceKVMId(dev_type, kvm_device)
2123 2125
    if dev_type == constants.HOTPLUG_TARGET_DISK:
2124
      command = "device_del %s\n" % kvm_devid
2125
      command += "drive_del %s" % kvm_devid
2126
      cmds = ["device_del %s" % kvm_devid]
2127
      cmds += ["drive_del %s" % kvm_devid]
2126 2128
    elif dev_type == constants.HOTPLUG_TARGET_NIC:
2127
      command = "device_del %s\n" % kvm_devid
2128
      command += "netdev_del %s" % kvm_devid
2129
      cmds = ["device_del %s" % kvm_devid]
2130
      cmds += ["netdev_del %s" % kvm_devid]
2129 2131
      utils.RemoveFile(self._InstanceNICFile(instance.name, seq))
2130
    self._CallHotplugCommand(instance.name, command)
2132
    self._CallHotplugCommands(instance.name, cmds)
2131 2133
    index = _DEVICE_RUNTIME_INDEX[dev_type]
2132 2134
    runtime[index].remove(entry)
2133 2135
    self._SaveKVMRuntime(instance, runtime)
......
2144 2146
    if dev_type == constants.HOTPLUG_TARGET_NIC:
2145 2147
      # putting it back in the same pci slot
2146 2148
      device.pci = self.HotDelDevice(instance, dev_type, device, _, seq)
2147
      # TODO: remove sleep when socat gets removed
2148
      time.sleep(2)
2149 2149
      self.HotAddDevice(instance, dev_type, device, _, seq)
2150 2150

  
2151 2151
  def _PassTapFd(self, instance, fd, nic):

Also available in: Unified diff