Revision 84ba0048

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

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

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

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

  
2148 2149
  def _PassTapFd(self, instance, fd, nic):

Also available in: Unified diff