[pve-devel] [RFC qemu-server] cloud-init: make cipassword interactive on the CLI

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Mar 12 13:04:16 CET 2018


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 PVE/CLI/qm.pm | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 3347612..c017a59 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -13,6 +13,7 @@ use IO::Select;
 use URI::Escape;
 
 use PVE::Tools qw(extract_param);
+use PVE::PTY;
 use PVE::Cluster;
 use PVE::SafeSyslog;
 use PVE::INotify;
@@ -670,9 +671,18 @@ sub param_mapping {
     my $ssh_key_map = ['sshkeys', sub {
 	return URI::Escape::uri_escape(PVE::Tools::file_get_contents($_[0]));
     }];
+    my $cipassword_map = ['cipassword', sub {
+	my ($value) = @_;
+	return $value if $value;
+
+	my $pw = PVE::PTY::read_password('New cloud-init user password: ');
+	my $pw2 = PVE::PTY::read_password('Repeat password: ');
+	die "passwords do not match\n" if $pw ne $pw2;
+	return $pw;
+    }, '<password>', 1];
     my $mapping = {
-	'update_vm' => [$ssh_key_map],
-	'create_vm' => [$ssh_key_map],
+	'update_vm' => [$ssh_key_map, $cipassword_map],
+	'create_vm' => [$ssh_key_map, $cipassword_map],
     };
 
     return $mapping->{$name};
-- 
2.11.0





More information about the pve-devel mailing list