cloudinit: Only print generated password if it was requested

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2019-11-20 17:42:14 -05:00
parent f107aaab02
commit 9a3f73710e
2 changed files with 8 additions and 5 deletions

View File

@ -12,7 +12,7 @@ class CloudInitData():
generated_root_password = None generated_root_password = None
ssh_key = None ssh_key = None
def generate_password(self): def _generate_password(self):
self.generated_root_password = "" self.generated_root_password = ""
for dummy in range(16): for dummy in range(16):
self.generated_root_password += random.choice(string.ascii_letters + string.digits) self.generated_root_password += random.choice(string.ascii_letters + string.digits)
@ -22,11 +22,14 @@ class CloudInitData():
with open(pwdfile, "r") as fobj: with open(pwdfile, "r") as fobj:
return fobj.readline().rstrip("\n\r") return fobj.readline().rstrip("\n\r")
def get_root_password(self): def get_password_if_generated(self):
if self.root_password_generate: if self.root_password_generate:
return self.generate_password() return self._generate_password()
elif self.root_password_file:
def get_root_password(self):
if self.root_password_file:
return self._get_password(self.root_password_file) return self._get_password(self.root_password_file)
return self.get_password_if_generated()
def get_ssh_key(self): def get_ssh_key(self):
if self.ssh_key: if self.ssh_key:

View File

@ -433,7 +433,7 @@ class Installer(object):
def get_generated_password(self): def get_generated_password(self):
if self._cloudinit_data: if self._cloudinit_data:
return self._cloudinit_data.generate_password() return self._cloudinit_data.get_password_if_generated()
########################## ##########################