From 22478f307dd9f1c4d80a3dfae8f43c641efbea46 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Tue, 1 Mar 2022 14:11:43 -0500 Subject: virt-install: Add --cloud-init clouduser-ssh-key= This sets the sshkey for the default cloud-init username Resolves: https://github.com/virt-manager/virt-manager/issues/307 Signed-off-by: Cole Robinson --- virtinst/cli.py | 1 + virtinst/install/cloudinit.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'virtinst') diff --git a/virtinst/cli.py b/virtinst/cli.py index 2c199cb1..52be9f29 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -1773,6 +1773,7 @@ class ParserCloudInit(VirtCLIParser): cls.add_arg("root-password-file", "root_password_file") cls.add_arg("disable", "disable", is_onoff=True) cls.add_arg("root-ssh-key", "root_ssh_key") + cls.add_arg("clouduser-ssh-key", "clouduser_ssh_key") cls.add_arg("user-data", "user_data") cls.add_arg("meta-data", "meta_data") cls.add_arg("network-config", "network_config") diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py index f0aa9bf0..33c1df74 100644 --- a/virtinst/install/cloudinit.py +++ b/virtinst/install/cloudinit.py @@ -18,6 +18,7 @@ class CloudInitData(): root_password_file = None generated_root_password = None root_ssh_key = None + clouduser_ssh_key = None user_data = None meta_data = None network_config = None @@ -47,6 +48,10 @@ class CloudInitData(): if self.root_ssh_key: return self._get_password(self.root_ssh_key) + def get_clouduser_ssh_key(self): + if self.clouduser_ssh_key: + return self._get_password(self.clouduser_ssh_key) + def _create_metadata_content(cloudinit_data): content = "" @@ -76,12 +81,17 @@ def _create_userdata_content(cloudinit_data): elif cloudinit_data.root_password_file: content += " expire: False\n" - if cloudinit_data.root_ssh_key: - rootpass = cloudinit_data.get_root_ssh_key() + if cloudinit_data.root_ssh_key or cloudinit_data.clouduser_ssh_key: content += "users:\n" - content += " - name: root\n" - content += " ssh-authorized-keys:\n" - content += " - %s\n" % rootpass + rootkey = cloudinit_data.get_root_ssh_key() + userkey = cloudinit_data.get_clouduser_ssh_key() + + if rootkey: + content += " - name: root\n" + content += " ssh-authorized-keys:\n" + content += " - %s\n" % rootkey + if userkey: + content += " - ssh-authorized-keys: %s\n" % userkey if cloudinit_data.disable: content += "runcmd:\n" -- cgit v1.2.1