[virt-tools-list] [virt-install PATCH v2 01/14] virt-install: Add --unattended

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


--unattended is currently a no-op parameter that will be used to perform
unattended installations.

For now, if someone tries to use --unattended virt-install will fail as
the option is still not supported.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 tests/clitest.py       |  6 +++++-
 virt-install           | 10 ++++++++++
 virtinst/cli.py        | 26 +++++++++++++++++++++++++-
 virtinst/unattended.py | 13 +++++++++++++
 4 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 virtinst/unattended.py

diff --git a/tests/clitest.py b/tests/clitest.py
index abfca031..c78a1be5 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -721,7 +721,6 @@ c.add_invalid("--nodisks --pxe --name test")  # Colliding name
 c.add_compare("--cdrom %(EXISTIMG1)s --disk size=1 --disk %(EXISTIMG2)s,device=cdrom", "cdrom-double")  # ensure --disk device=cdrom is ordered after --cdrom, this is important for virtio-win installs with a driver ISO
 
 
-
 #############################
 # Remote URI specific tests #
 #############################
@@ -1105,6 +1104,11 @@ _add_argcomplete_cmd("virt-install --location k", "kernel")
 _add_argcomplete_cmd("virt-install --os-variant nam", "name")
 _add_argcomplete_cmd("virt-install --test-stub", None,
         nogrep="--test-stub-command")
+_add_argcomplete_cmd("virt-install --un", "--unattended")
+_add_argcomplete_cmd("virt-install --unattended ", "profile=") # will list all --unattended subprops
+_add_argcomplete_cmd("virt-install --unattended p", "profile=")
+_add_argcomplete_cmd("virt-install --unattended a", "admin-password=")
+_add_argcomplete_cmd("virt-install --unattended u", "user-password=")
 _add_argcomplete_cmd("virt-clone --preserve", "--preserve-data")
 _add_argcomplete_cmd("virt-xml --sound mode", "model")
 _add_argcomplete_cmd("virt-convert --dest", "--destination")
diff --git a/virt-install b/virt-install
index 257a91bd..8b1d800f 100755
--- a/virt-install
+++ b/virt-install
@@ -333,6 +333,10 @@ def validate_required_options(options, guest, installer):
             _("An install method must be specified\n(%(methods)s)") %
             {"methods": install_methods})
 
+    if options.unattended:
+        if options.os_variant.is_none or options.os_variant.is_auto:
+            msg += "\n" + _("--unattended requires an explicit --os-variant")
+
     if msg:
         fail(msg)
 
@@ -441,6 +445,10 @@ def build_installer(options, guest):
     install_bootdev = None
 
     has_installer = True
+
+    if options.unattended:
+        fail(_("--unattended is not supported yet"))
+
     if options.os_variant.install == "location":
         if not options.location:
             location = guest.osinfo.get_location(guest.os.arch)
@@ -791,6 +799,8 @@ def parse_args():
                            "booted from --location"))
     insg.add_argument("--initrd-inject", action="append",
                     help=_("Add given file to root of initrd from --location"))
+    insg.add_argument("--unattended",
+                    help=_("Perform a unattended installation"))
 
     # Takes a URL and just prints to stdout the detected distro name
     insg.add_argument("--test-media-detection", help=argparse.SUPPRESS)
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 06c6d33e..8f8f0a69 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -28,6 +28,7 @@ from .devices import (Device, DeviceController, DeviceDisk, DeviceGraphics,
 from .domain import DomainClock, DomainOs
 from .nodedev import NodeDevice
 from .storage import StoragePool, StorageVolume
+from .unattended import UnattendedData
 
 
 ##########################
@@ -462,7 +463,8 @@ def get_meter():
 ###########################
 
 def _get_completer_parsers():
-    return VIRT_PARSERS + [ParseCLICheck, ParserLocation, ParserOSVariant]
+    return VIRT_PARSERS + [ParseCLICheck, ParserLocation, ParserOSVariant,
+            ParseCLIUnattended]
 
 
 def _virtparser_completer(prefix, **kwargs):
@@ -1417,6 +1419,28 @@ class VirtCLIParser(metaclass=InitClass):
         """Do nothing callback"""
 
 
+########################
+# --unattended parsing #
+########################
+
+class ParseCLIUnattended(VirtCLIParser):
+    cli_arg_name = "unattended"
+
+    @classmethod
+    def __init_class__(cls, **kwargs):
+        VirtCLIParser.__init_class__(**kwargs)
+        cls.add_arg("profile", "profile")
+        cls.add_arg("admin_password", "admin-password")
+        cls.add_arg("user_password", "user-password")
+
+
+def parse_unattended(unattended):
+    ret = UnattendedData()
+    parser = ParseCLIUnattended(None, unattended)
+    parser.parse(ret)
+    return ret
+
+
 ###################
 # --check parsing #
 ###################
diff --git a/virtinst/unattended.py b/virtinst/unattended.py
new file mode 100644
index 00000000..01f6f5a2
--- /dev/null
+++ b/virtinst/unattended.py
@@ -0,0 +1,13 @@
+#
+# Common code for unattended installations
+#
+# Copyright 2019 Red Hat, Inc.
+#
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+
+class UnattendedData():
+    profile = None
+    admin_password = None
+    user_password = None
-- 
2.20.1




More information about the virt-tools-list mailing list