[pve-devel] [PATCH container 1/1] replace read_password with param_mapping

Dominik Csapak d.csapak at proxmox.com
Tue Jun 12 12:33:52 CEST 2018


and replace Term::ReadLine with PVE::PTY

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/CLI/pct.pm | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 897d595..84560b5 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -6,10 +6,10 @@ use warnings;
 use POSIX;
 use Fcntl;
 use File::Copy 'copy';
-use Term::ReadLine;
 
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
+use PVE::PTY;
 use PVE::CpuSet;
 use PVE::Cluster;
 use PVE::INotify;
@@ -76,14 +76,19 @@ __PACKAGE__->register_method ({
 	return undef;
     }});
 
-sub read_password {
-    my $term = new Term::ReadLine ('pct');
-    my $attribs = $term->Attribs;
-    $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
-    my $input = $term->readline('Enter password: ');
-    my $conf = $term->readline('Retype password: ');
-    die "Passwords do not match.\n" if ($input ne $conf);
-    return $input;
+sub param_mapping {
+    my ($name) = @_;
+    my $mapping = {
+	'create_vm' => [
+	    ['password', sub {
+		my ($value) = @_;
+		return $value if $value;
+		return PVE::PTY::get_confirmed_password();
+	    }, '<password>', 1],
+	],
+    };
+
+    return $mapping->{name};
 }
 
 sub string_param_file_mapping {
-- 
2.11.0




More information about the pve-devel mailing list