Revision 5fbb57ab
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
2070 | 2070 |
if (int(v_major), int(v_min)) < (1, 0): |
2071 | 2071 |
raise errors.HotplugError("Hotplug not supported for qemu versions < 1.0") |
2072 | 2072 |
|
2073 |
def _CallHotplugCommand(self, name, cmd): |
|
2074 |
output = self._CallMonitorCommand(name, cmd) |
|
2075 |
# TODO: parse output and check if succeeded |
|
2076 |
for line in output.stdout.splitlines(): |
|
2077 |
logging.info("%s", line) |
|
2073 |
def _CallHotplugCommands(self, name, cmds): |
|
2074 |
for c in cmds: |
|
2075 |
output = self._CallMonitorCommand(name, c) |
|
2076 |
# TODO: parse output and check if succeeded |
|
2077 |
for line in output.stdout.splitlines(): |
|
2078 |
logging.info("%s", line) |
|
2079 |
time.sleep(2) |
|
2078 | 2080 |
|
2079 | 2081 |
def HotAddDevice(self, instance, dev_type, device, extra, seq): |
2080 | 2082 |
""" Helper method to hot-add a new device |
... | ... | |
2089 | 2091 |
kvm_devid = _GenerateDeviceKVMId(dev_type, device) |
2090 | 2092 |
runtime = self._LoadKVMRuntime(instance) |
2091 | 2093 |
if dev_type == constants.HOTPLUG_TARGET_DISK: |
2092 |
command = "drive_add dummy file=%s,if=none,id=%s,format=raw\n" % \
|
|
2093 |
(extra, kvm_devid)
|
|
2094 |
command += ("device_add virtio-blk-pci,bus=pci.0,addr=%s,drive=%s,id=%s" %
|
|
2095 |
(hex(device.pci), kvm_devid, kvm_devid))
|
|
2094 |
cmds = ["drive_add dummy file=%s,if=none,id=%s,format=raw" %
|
|
2095 |
(extra, kvm_devid)]
|
|
2096 |
cmds += ["device_add virtio-blk-pci,bus=pci.0,addr=%s,drive=%s,id=%s" %
|
|
2097 |
(hex(device.pci), kvm_devid, kvm_devid)]
|
|
2096 | 2098 |
elif dev_type == constants.HOTPLUG_TARGET_NIC: |
2097 | 2099 |
(tap, fd) = _OpenTap() |
2098 | 2100 |
self._ConfigureNIC(instance, seq, device, tap) |
2099 | 2101 |
self._PassTapFd(instance, fd, device) |
2100 |
command = "netdev_add tap,id=%s,fd=%s\n" % (kvm_devid, kvm_devid)
|
|
2102 |
cmds = ["netdev_add tap,id=%s,fd=%s" % (kvm_devid, kvm_devid)]
|
|
2101 | 2103 |
args = "virtio-net-pci,bus=pci.0,addr=%s,mac=%s,netdev=%s,id=%s" % \ |
2102 | 2104 |
(hex(device.pci), device.mac, kvm_devid, kvm_devid) |
2103 |
command += "device_add %s" % args
|
|
2105 |
cmds += ["device_add %s" % args]
|
|
2104 | 2106 |
utils.WriteFile(self._InstanceNICFile(instance.name, seq), data=tap) |
2105 | 2107 |
|
2106 |
self._CallHotplugCommand(instance.name, command)
|
|
2108 |
self._CallHotplugCommands(instance.name, cmds)
|
|
2107 | 2109 |
# update relevant entries in runtime file |
2108 | 2110 |
index = _DEVICE_RUNTIME_INDEX[dev_type] |
2109 | 2111 |
entry = _RUNTIME_ENTRY[dev_type](device, extra) |
... | ... | |
2122 | 2124 |
kvm_device = _RUNTIME_DEVICE[dev_type](entry) |
2123 | 2125 |
kvm_devid = _GenerateDeviceKVMId(dev_type, kvm_device) |
2124 | 2126 |
if dev_type == constants.HOTPLUG_TARGET_DISK: |
2125 |
command = "device_del %s\n" % kvm_devid
|
|
2126 |
command += "drive_del %s" % kvm_devid
|
|
2127 |
cmds = ["device_del %s" % kvm_devid]
|
|
2128 |
cmds += ["drive_del %s" % kvm_devid]
|
|
2127 | 2129 |
elif dev_type == constants.HOTPLUG_TARGET_NIC: |
2128 |
command = "device_del %s\n" % kvm_devid
|
|
2129 |
command += "netdev_del %s" % kvm_devid
|
|
2130 |
cmds = ["device_del %s" % kvm_devid]
|
|
2131 |
cmds += ["netdev_del %s" % kvm_devid]
|
|
2130 | 2132 |
utils.RemoveFile(self._InstanceNICFile(instance.name, seq)) |
2131 |
self._CallHotplugCommand(instance.name, command)
|
|
2133 |
self._CallHotplugCommands(instance.name, cmds)
|
|
2132 | 2134 |
index = _DEVICE_RUNTIME_INDEX[dev_type] |
2133 | 2135 |
runtime[index].remove(entry) |
2134 | 2136 |
self._SaveKVMRuntime(instance, runtime) |
Also available in: Unified diff