Revision a30e9f99

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

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

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

  
2109
    self._CallHotplugCommand(instance.name, command)
2111
    self._CallHotplugCommands(instance.name, cmds)
2110 2112
    # update relevant entries in runtime file
2111 2113
    index = _DEVICE_RUNTIME_INDEX[dev_type]
2112 2114
    entry = _RUNTIME_ENTRY[dev_type](device, extra)
......
2125 2127
    kvm_device = _RUNTIME_DEVICE[dev_type](entry)
2126 2128
    kvm_devid = _GenerateDeviceKVMId(dev_type, kvm_device)
2127 2129
    if dev_type == constants.HOTPLUG_TARGET_DISK:
2128
      command = "device_del %s\n" % kvm_devid
2129
      command += "drive_del %s" % kvm_devid
2130
      cmds = ["device_del %s" % kvm_devid]
2131
      cmds += ["drive_del %s" % kvm_devid]
2130 2132
    elif dev_type == constants.HOTPLUG_TARGET_NIC:
2131
      command = "device_del %s\n" % kvm_devid
2132
      command += "netdev_del %s" % kvm_devid
2133
      cmds = ["device_del %s" % kvm_devid]
2134
      cmds += ["netdev_del %s" % kvm_devid]
2133 2135
      utils.RemoveFile(self._InstanceNICFile(instance.name, seq))
2134
    self._CallHotplugCommand(instance.name, command)
2136
    self._CallHotplugCommands(instance.name, cmds)
2135 2137
    index = _DEVICE_RUNTIME_INDEX[dev_type]
2136 2138
    runtime[index].remove(entry)
2137 2139
    self._SaveKVMRuntime(instance, runtime)
......
2149 2151
      # putting it back in the same pci slot
2150 2152
      device.pci = self.HotDelDevice(instance, dev_type, device, _, seq)
2151 2153
      # TODO: remove sleep when socat gets removed
2152
      time.sleep(2)
2153 2154
      self.HotAddDevice(instance, dev_type, device, _, seq)
2154 2155

  
2155 2156
  def _PassTapFd(self, instance, fd, nic):

Also available in: Unified diff