[virt-tools-list] [virt-install PATCH v2 06/14] osdict: Add set_install_script_preferred_injection_method()

Fabiano Fidêncio fidencio at redhat.com
Fri Feb 22 08:40:13 UTC 2019


As not all unattended installations will be done by the same method,
let's have a wrapper around set_preferred_injection_method(), from
Libosinfo.InstallSript, in order to be able to properly set which is
going to be the preferred injection method for a script.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 virtinst/osdict.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index c15add02..b348844c 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -538,6 +538,31 @@ class _OsVariant(object):
         # scripts when its actually needed, though.
         return filtered_script_list.get_nth(0)
 
+    def set_install_script_preferred_injection_method(self, script, method):
+        def nick_to_value(method):
+            injection_methods = [
+                    libosinfo.InstallScriptInjectionMethod.CDROM,
+                    libosinfo.InstallScriptInjectionMethod.DISK,
+                    libosinfo.InstallScriptInjectionMethod.FLOPPY,
+                    libosinfo.InstallScriptInjectionMethod.INITRD,
+                    libosinfo.InstallScriptInjectionMethod.WEB]
+
+            for m in injection_methods:
+                if method == m.value_nicks[0]:
+                    return m
+
+            raise RuntimeError(
+                _("%s is a non-valid injection method in libosinfo."))
+
+        injection_method = nick_to_value(method)
+        supported_injection_methods = script.get_injection_methods()
+        if (injection_method & supported_injection_methods == 0):
+            raise RuntimeError(
+                _("OS '%s' unattended install is not supported") % (self.name))
+
+        logging.debug("Using '%s' injection method", method)
+        script.set_preferred_injection_method(injection_method)
+
     def get_install_script_config(self, script, unattended_data, arch,
             hostname):
         def requires_param(config_param):
-- 
2.20.1




More information about the virt-tools-list mailing list