diff options
author | Cole Robinson <crobinso@redhat.com> | 2022-03-01 14:11:43 -0500 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2022-03-01 14:29:46 -0500 |
commit | 22478f307dd9f1c4d80a3dfae8f43c641efbea46 (patch) | |
tree | 0c8b4f445f5524fdc454c533eb45fc86fdc22fbe /virtinst | |
parent | c8afd1f51ed97d17095e6c135d2c588a65fe17e5 (diff) | |
download | virt-manager-22478f307dd9f1c4d80a3dfae8f43c641efbea46.tar.gz |
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 <crobinso@redhat.com>
Diffstat (limited to 'virtinst')
-rw-r--r-- | virtinst/cli.py | 1 | ||||
-rw-r--r-- | virtinst/install/cloudinit.py | 20 |
2 files changed, 16 insertions, 5 deletions
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" |