cloud-init: make cipassword interactive on the CLI

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2018-03-12 13:04:16 +01:00 committed by Dietmar Maurer
parent e4d4cda113
commit 29d1f14708

View File

@ -13,6 +13,7 @@ use IO::Select;
use URI::Escape; use URI::Escape;
use PVE::Tools qw(extract_param); use PVE::Tools qw(extract_param);
use PVE::PTY;
use PVE::Cluster; use PVE::Cluster;
use PVE::SafeSyslog; use PVE::SafeSyslog;
use PVE::INotify; use PVE::INotify;
@ -670,9 +671,18 @@ sub param_mapping {
my $ssh_key_map = ['sshkeys', sub { my $ssh_key_map = ['sshkeys', sub {
return URI::Escape::uri_escape(PVE::Tools::file_get_contents($_[0])); 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 = { my $mapping = {
'update_vm' => [$ssh_key_map], 'update_vm' => [$ssh_key_map, $cipassword_map],
'create_vm' => [$ssh_key_map], 'create_vm' => [$ssh_key_map, $cipassword_map],
}; };
return $mapping->{$name}; return $mapping->{$name};