[virt-tools-list] [virt-manager PATCH] cloudinit: Move password generation inside class CloudInitData
Athina Plaskasoviti
athina.plaskasoviti at gmail.com
Sat Jul 13 15:37:39 UTC 2019
Function generate_password() provides random 16 digit password and
get_root_password() handling root_password assignment.
Signed-off-by: Athina Plaskasoviti <athina.plaskasoviti at gmail.com>
---
virtinst/install/cloudinit.py | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py
index 91a131c1..7c4facf5 100644
--- a/virtinst/install/cloudinit.py
+++ b/virtinst/install/cloudinit.py
@@ -7,6 +7,16 @@ from ..logger import log
class CloudInitData():
disable = None
root_password = None
+ generated_root_password = None
+
+ def generate_password(self):
+ self.generated_root_password = ""
+ for dummy in range(16):
+ self.generated_root_password += random.choice(string.ascii_letters + string.digits)
+
+ def get_root_password(self):
+ if self.root_password == "generate":
+ return self.generate_password()
def create_metadata(scratchdir):
@@ -26,13 +36,7 @@ def create_metadata(scratchdir):
def create_userdata(scratchdir, cloudinit_data):
content = "#cloud-config\n"
- rootpass = cloudinit_data.root_password
- if rootpass == "generate":
- rootpass = ""
- for dummy in range(16):
- rootpass += random.choice(string.ascii_letters + string.digits)
- log.warning("Generated password for first boot: %s", rootpass)
-
+ rootpass = cloudinit_data.get_root_password()
if rootpass:
content += "chpasswd:\n"
content += " list: |\n"
@@ -45,7 +49,6 @@ def create_userdata(scratchdir, cloudinit_data):
content += "- [ sudo, touch, /etc/cloud/cloud-init.disabled ]\n"
log.debug("Generated cloud-init userdata:\n%s", content)
-
fileobj = tempfile.NamedTemporaryFile(
prefix="virtinst-", suffix="-userdata",
dir=scratchdir, delete=False)
--
2.20.1
More information about the virt-tools-list
mailing list