unattended: Add option to set the user-login

Let's allow setting the login of the guest user.

Using the user from the system is a quite good fallback, but would break
unattended installations when running virt-install as root. Thus, for
those cases, it makes sense to have the option of setting the user
login.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
Fabiano Fidêncio 2019-10-17 18:01:25 +02:00 committed by Cole Robinson
parent 0e9905d057
commit cdcec1fb03
4 changed files with 18 additions and 5 deletions

View File

@ -628,12 +628,18 @@ password-file.
Note that only the first line of the file will be considered, including
any whitespace characters and excluding new-line.
=item B<user-login=>
The user login name to be used in th VM. virt-install will default to your
current host username if this is unspecified.
=item B<user-password-file=>
A file used to set the VM user password. This option can be used either as
"user-password-file=/path/to/password-file" or as
"user-password-file=/dev/fd/n", being n the file descriptor of the
password-file. The username is your current host username.
password-file. The username is either the user-login specified or your current
host username.
Note that only the first line of the file will be considered, including
any whitespace characters and excluding new-line.

View File

@ -887,7 +887,7 @@ c.add_valid("--connect %s --pxe --disk size=1" % utils.URIs.test_defaultpool_col
####################
c = vinst.add_category("unattended-install", "--connect %(URI-KVM)s --nographics --noautoconsole --disk none", prerun_check=no_osinfo_unattend_cb)
c.add_compare("--install fedora26 --unattended profile=desktop,admin-password-file=%(ADMIN-PASSWORD-FILE)s,user-password-file=%(USER-PASSWORD-FILE)s,product-key=1234", "osinfo-url-unattended", prerun_check=lambda: not unattended.OSInstallScript.have_libosinfo_installation_url()) # unattended install for fedora, using initrd injection
c.add_compare("--install fedora26 --unattended profile=desktop,admin-password-file=%(ADMIN-PASSWORD-FILE)s,user-password-file=%(USER-PASSWORD-FILE)s,product-key=1234,user-login=foobar", "osinfo-url-unattended", prerun_check=lambda: not unattended.OSInstallScript.have_libosinfo_installation_url()) # unattended install for fedora, using initrd injection
c.add_compare("--cdrom %(ISO-WIN7)s --unattended profile=desktop,admin-password-file=%(ADMIN-PASSWORD-FILE)s", "osinfo-win7-unattended", prerun_check=no_osinfo_unattended_win_drivers_cb) # unattended install for win7
c.add_compare("--os-variant fedora26 --unattended profile=jeos,admin-password-file=%(ADMIN-PASSWORD-FILE)s --location %(ISO-F26-NETINST)s", "osinfo-netinst-unattended") # triggering the special netinst checking code
c.add_compare("--os-variant silverblue29 --location http://example.com", "network-install-resources") # triggering network-install resources override

View File

@ -1514,6 +1514,7 @@ class ParserUnattended(VirtCLIParser):
VirtCLIParser._init_class(**kwargs)
cls.add_arg("profile", "profile")
cls.add_arg("admin-password-file", "admin_password_file")
cls.add_arg("user-login", "user_login")
cls.add_arg("user-password-file", "user_password_file")
cls.add_arg("product-key", "product_key")

View File

@ -36,9 +36,14 @@ def _make_installconfig(script, osobj, unattended_data, arch, hostname, url):
config = Libosinfo.InstallConfig()
# Set user login and name based on the one from the system
config.set_user_login(getpass.getuser())
config.set_user_realname(pwd.getpwnam(getpass.getuser()).pw_gecos)
# Set user login and name
# In case it's specified via command-line, use the specified one as login
# and realname. Otherwise, fallback fto the one from the system
login = unattended_data.user_login or getpass.getuser()
login = login.lower()
realname = unattended_data.user_login or pwd.getpwnam(login).pw_gecos
config.set_user_login(login)
config.set_user_realname(realname)
# Set user-password.
# In case it's required and not passed, just raise a RuntimeError.
@ -252,6 +257,7 @@ class OSInstallScript:
class UnattendedData():
profile = None
admin_password_file = None
user_login = None
user_password_file = None
product_key = None