[virt-tools-list] [vort-manager PATCH v2] cloudinit: Add cli option root-password-file=/path/to/file
Athina Plaskasoviti
athina.plaskasoviti at gmail.com
Tue Jul 16 12:17:32 UTC 2019
Signed-off-by: Athina Plaskasoviti <athina.plaskasoviti at gmail.com>
---
tests/clitest.py | 3 ++-
virtinst/cli.py | 1 +
virtinst/install/cloudinit.py | 7 +++++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/tests/clitest.py b/tests/clitest.py
index 38a6805e..36844573 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -872,7 +872,8 @@ c.add_compare("--connect %s --os-variant fedora26" % (utils.URIs.test_suite), "o
c.add_compare("--connect %s --os-variant fedora26 --pxe --print-xml" % (utils.URIs.test_suite), "osvariant-defaults-pxe", use_default_args=False) # No arguments
c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init", "cloud-init-default") # default --cloud-init behavior is root-password=generate,disable=yes
c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password=generate,disable=no", "cloud-init-options") # --cloud-init options
-c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password=a1b2c3d4,disable=no", "cloud-init-options") #--cloud-init-options
+c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password=a1b2c3d4,disable=no", "cloud-init-options") # --cloud-init-options
+c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password-file=%(ADMIN-PASSWORD-FILE)s,disable=no", "cloud-init-options") # --cloud-init-options
c.add_valid("--panic help --disk=? --check=help", grep="path_in_use") # Make sure introspection doesn't blow up
c.add_valid("--connect test:///default --test-stub-command", use_default_args=False) # --test-stub-command
c.add_valid("--nodisks --pxe", grep="VM performance may suffer") # os variant warning
diff --git a/virtinst/cli.py b/virtinst/cli.py
index bed83c73..5cbe67db 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1614,6 +1614,7 @@ class ParserCloudInit(VirtCLIParser):
def _init_class(cls, **kwargs):
VirtCLIParser._init_class(**kwargs)
cls.add_arg("root-password", "root_password")
+ cls.add_arg("root-password-file", "root_password_file")
cls.add_arg("disable", "disable", is_onoff=True)
diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py
index 92b29515..dd43a9e6 100644
--- a/virtinst/install/cloudinit.py
+++ b/virtinst/install/cloudinit.py
@@ -7,6 +7,7 @@ from ..logger import log
class CloudInitData():
disable = None
root_password = None
+ root_password_file = None
generated_root_password = None
def generate_password(self):
@@ -15,9 +16,15 @@ class CloudInitData():
self.generated_root_password += random.choice(string.ascii_letters + string.digits)
return self.generated_root_password
+ def _get_password(self, pwdfile):
+ with open(pwdfile, "r") as fobj:
+ return fobj.readline().rstrip("\n\r")
+
def get_root_password(self):
if self.root_password == "generate":
return self.generate_password()
+ elif self.root_password_file:
+ return self._get_password(self.root_password_file)
else:
return self.root_password
--
2.20.1
More information about the virt-tools-list
mailing list