[virt-tools-list] [PATCH virt-manager] cli: Fix __init_class__

Marc Hartmayer mhartmay at linux.ibm.com
Wed Jan 9 09:24:37 UTC 2019


For Python versions < 3.6 it's not possible for the metaclass to call
a method in the defined class that uses super() before it is done with
its __new__ and __init__. Therefore let's workaround this by using
hard coded class names instead of super() in __init_class__. See
https://stackoverflow.com/a/28605694 for more details.

In addition, add missing __init_class__ calls to the __init_class__
implementations of ParserVsock and _ParserChar.

Signed-off-by: Marc Hartmayer <mhartmay at linux.ibm.com>
---
 virtinst/cli.py | 77 +++++++++++++++++++++++++------------------------
 1 file changed, 39 insertions(+), 38 deletions(-)

diff --git a/virtinst/cli.py b/virtinst/cli.py
index 55e94cdcf740..7daf39919a63 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1410,7 +1410,7 @@ class ParseCLICheck(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg(None, "path_in_use", is_onoff=True,
                     cb=cls.set_cb)
         cls.add_arg(None, "disk_size", is_onoff=True,
@@ -1440,7 +1440,7 @@ class ParserMetadata(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("name", "name", can_comma=True)
         cls.add_arg("title", "title", can_comma=True)
         cls.add_arg("uuid", "uuid")
@@ -1464,7 +1464,7 @@ class ParserEvents(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("on_poweroff", "on_poweroff")
         cls.add_arg("on_reboot", "on_reboot")
         cls.add_arg("on_crash", "on_crash")
@@ -1482,7 +1482,7 @@ class ParserResource(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("partition", "partition")
 
 
@@ -1497,7 +1497,7 @@ class ParserNumatune(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("memory_nodeset", "nodeset", can_comma=True)
         cls.add_arg("memory_mode", "mode")
 
@@ -1515,7 +1515,7 @@ class ParserMemory(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("memory", "memory", cb=cls.set_memory_cb)
         cls.add_arg("maxmemory", "maxmemory", cb=cls.set_memory_cb)
         cls.add_arg("memoryBacking.hugepages", "hugepages", is_onoff=True)
@@ -1535,7 +1535,7 @@ class ParserMemtune(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("hard_limit", "hard_limit")
         cls.add_arg("soft_limit", "soft_limit")
         cls.add_arg("swap_hard_limit", "swap_hard_limit")
@@ -1553,7 +1553,7 @@ class ParserBlkiotune(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("weight", "weight")
         cls.add_arg("device_path", "device_path")
         cls.add_arg("device_weight", "device_weight")
@@ -1569,7 +1569,7 @@ class ParserMemoryBacking(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("hugepages", "hugepages", is_onoff=True)
         cls.add_arg("page_size", "size")
         cls.add_arg("page_unit", "unit")
@@ -1665,7 +1665,7 @@ class ParserCPU(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg(None, "model", cb=cls.set_model_cb)
         cls.add_arg("mode", "mode")
         cls.add_arg("match", "match")
@@ -1712,7 +1712,7 @@ class ParserCputune(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         # Options for CPU.vcpus config
         cls.add_arg("vcpu", "vcpupin[0-9]*.vcpu",
                     find_inst_cb=cls.vcpu_find_inst_cb)
@@ -1758,7 +1758,7 @@ class ParserVCPU(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("cpu.sockets", "sockets")
         cls.add_arg("cpu.cores", "cores")
         cls.add_arg("cpu.threads", "threads")
@@ -1815,7 +1815,7 @@ class ParserBoot(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         # UEFI depends on these bits, so set them first
         cls.add_arg("arch", "arch")
         cls.add_arg(None, "bootloader", cb=cls.set_bootloader_cb)
@@ -1859,7 +1859,7 @@ class ParserIdmap(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("uid_start", "uid_start")
         cls.add_arg("uid_target", "uid_target")
         cls.add_arg("uid_count", "uid_count")
@@ -1878,7 +1878,7 @@ class ParserSecurity(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("type", "type")
         cls.add_arg("model", "model")
         cls.add_arg("relabel", "relabel", is_onoff=True)
@@ -1896,7 +1896,7 @@ class ParserFeatures(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("acpi", "acpi", is_onoff=True)
         cls.add_arg("apic", "apic", is_onoff=True)
         cls.add_arg("pae", "pae", is_onoff=True)
@@ -1949,7 +1949,7 @@ class ParserClock(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("offset", "offset")
 
         for _tname in DomainClock.TIMER_NAMES:
@@ -1969,7 +1969,7 @@ class ParserPM(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("suspend_to_mem", "suspend_to_mem", is_onoff=True)
         cls.add_arg("suspend_to_disk", "suspend_to_disk", is_onoff=True)
 
@@ -2012,7 +2012,7 @@ class ParserSysinfo(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         # <sysinfo type='smbios'>
         cls.add_arg("type", "type",
                               cb=cls.set_type_cb, can_comma=True)
@@ -2075,7 +2075,7 @@ class ParserQemuCLI(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg(None, "args", cb=cls.args_cb, can_comma=True)
         cls.add_arg(None, "env", cb=cls.env_cb, can_comma=True)
 
@@ -2240,7 +2240,7 @@ class ParserDisk(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         # These are all handled specially in _parse
         cls.add_arg(None, "backing_store", cb=cls.noset_cb)
@@ -2359,7 +2359,7 @@ class ParserNetwork(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("type", "type", cb=cls.set_type_cb)
         cls.add_arg("trustGuestRxFilters", "trustGuestRxFilters",
@@ -2470,7 +2470,7 @@ class ParserGraphics(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg(None, "type", cb=cls.set_type_cb)
         cls.add_arg("port", "port")
@@ -2522,7 +2522,7 @@ class ParserController(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("type", "type")
         cls.add_arg("model", "model")
@@ -2543,7 +2543,7 @@ class ParserInput(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("type", "type", ignore_default=True)
         cls.add_arg("bus", "bus", ignore_default=True)
@@ -2560,7 +2560,7 @@ class ParserSmartcard(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("mode", "mode", ignore_default=True)
         cls.add_arg("type", "type", ignore_default=True)
@@ -2587,7 +2587,7 @@ class ParserRedir(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("bus", "bus", ignore_default=True)
         cls.add_arg("type", "type", ignore_default=True)
@@ -2611,7 +2611,7 @@ class ParserTPM(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("type", "type")
         cls.add_arg("model", "model")
@@ -2671,7 +2671,7 @@ class ParserRNG(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("type", "type")
 
@@ -2700,7 +2700,7 @@ class ParserWatchdog(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("model", "model", ignore_default=True)
         cls.add_arg("action", "action", ignore_default=True)
@@ -2720,7 +2720,7 @@ class ParserMemdev(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("model", "model")
         cls.add_arg("access", "access")
         cls.add_arg("target.size", "target_size", cb=cls.set_target_size)
@@ -2744,7 +2744,7 @@ class ParserMemballoon(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("model", "model")
 
@@ -2774,7 +2774,7 @@ class ParserPanic(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg(None, "model", cb=cls.set_model_cb,
                     ignore_default=True)
         cls.add_arg("iobase", "iobase")
@@ -2792,7 +2792,7 @@ class ParserVsock(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("model", "model")
         cls.add_arg("auto_cid", "auto_cid")
@@ -2843,6 +2843,7 @@ class _ParserChar(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
+        VirtCLIParser.__init_class__(**kwargs)
         cls.add_arg("type", "char_type")
         cls.add_arg("source_path", "path")
         cls.add_arg("protocol",   "protocol")
@@ -2889,7 +2890,7 @@ class ParserFilesystem(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("type", "type")
         cls.add_arg("accessmode", "accessmode", aliases=["mode"])
@@ -2922,7 +2923,7 @@ class ParserVideo(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("model", "model", ignore_default=True)
         cls.add_arg("accel3d", "accel3d", is_onoff=True)
@@ -2957,7 +2958,7 @@ class ParserSound(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("model", "model", ignore_default=True)
         # Options for sound.codecs config
@@ -2994,7 +2995,7 @@ class ParserHostdev(VirtCLIParser):
 
     @classmethod
     def __init_class__(cls, **kwargs):
-        super().__init_class__(**kwargs)
+        VirtCLIParser.__init_class__(**kwargs)
         _add_device_address_args(cls)
         cls.add_arg("type", "type")
         cls.add_arg(None, "name",
-- 
2.17.0




More information about the virt-tools-list mailing list