From 9a3f73710ef0f581acb9adbaae48ed204ecf759d Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 20 Nov 2019 17:42:14 -0500 Subject: [PATCH] cloudinit: Only print generated password if it was requested Signed-off-by: Cole Robinson --- virtinst/install/cloudinit.py | 11 +++++++---- virtinst/install/installer.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py index e6365467..931d40b4 100644 --- a/virtinst/install/cloudinit.py +++ b/virtinst/install/cloudinit.py @@ -12,7 +12,7 @@ class CloudInitData(): generated_root_password = None ssh_key = None - def generate_password(self): + def _generate_password(self): self.generated_root_password = "" for dummy in range(16): self.generated_root_password += random.choice(string.ascii_letters + string.digits) @@ -22,11 +22,14 @@ class CloudInitData(): with open(pwdfile, "r") as fobj: return fobj.readline().rstrip("\n\r") - def get_root_password(self): + def get_password_if_generated(self): if self.root_password_generate: - return self.generate_password() - elif self.root_password_file: + return self._generate_password() + + def get_root_password(self): + if self.root_password_file: return self._get_password(self.root_password_file) + return self.get_password_if_generated() def get_ssh_key(self): if self.ssh_key: diff --git a/virtinst/install/installer.py b/virtinst/install/installer.py index 34f47ac4..a0ac63ab 100644 --- a/virtinst/install/installer.py +++ b/virtinst/install/installer.py @@ -433,7 +433,7 @@ class Installer(object): def get_generated_password(self): if self._cloudinit_data: - return self._cloudinit_data.generate_password() + return self._cloudinit_data.get_password_if_generated() ##########################