On 09/15/2016 11:28 AM, Sascha Silbe wrote: > Dear Eric, > > Sascha Silbe <si...@linux.vnet.ibm.com> writes: > >> result = self.vm.qmp('blockdev-change-medium', >> id=self.device_name or 'drive0', >> filename=new_img, >> format=iotests.imgfmt) > > Sorry, my eyes deceived me. I thought the original code was setting the > "id" parameter in both cases. QEMUMachine.qmp() and > QEMUMonitorProtocol.cmd() together translate the keyword arguments > directly into QMP arguments, so passing None is different from not > passing anything at all. The if/else is probably the best approach in > that case; everything else I can think of would just be more > complicated.
If there were some way to do: arglist = (all other parameters) if self.device_name: arglist.append(id=self.device_name) else: arglist.append(device='drive0') invoke(self.vm.qmp, arglist) that might be a little cleaner (no repetition on all the other parameters); but I don't know enough python to know if there is some sort of invoke() mechanism for pairing a method object and an arbitrary list as though it were a normal method call (I suspect there is, and I just don't know it). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature