[pve-devel] r4971 - in pve-manager/pve2: . bin

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Aug 11 14:12:20 CEST 2010


Author: dietmar
Date: 2010-08-11 12:12:20 +0000 (Wed, 11 Aug 2010)
New Revision: 4971

Modified:
   pve-manager/pve2/ChangeLog
   pve-manager/pve2/bin/pvesh
Log:
	* bin/pvesh (list_dir): use new PVE::JSONSchema::get_options()


Modified: pve-manager/pve2/ChangeLog
===================================================================
--- pve-manager/pve2/ChangeLog	2010-08-11 12:03:37 UTC (rev 4970)
+++ pve-manager/pve2/ChangeLog	2010-08-11 12:12:20 UTC (rev 4971)
@@ -1,3 +1,7 @@
+2010-08-11  Proxmox Support Team  <support at proxmox.com>
+
+	* bin/pvesh (list_dir): use new PVE::JSONSchema::get_options()
+
 2010-08-10  Proxmox Support Team  <support at proxmox.com>
 
 	* debian/control.in (Depends): we now depend on libpve-common-perl

Modified: pve-manager/pve2/bin/pvesh
===================================================================
--- pve-manager/pve2/bin/pvesh	2010-08-11 12:03:37 UTC (rev 4970)
+++ pve-manager/pve2/bin/pvesh	2010-08-11 12:12:20 UTC (rev 4971)
@@ -9,7 +9,6 @@
 use strict;
 use PVE::API2;
 use Term::ReadLine;
-use Getopt::Long;
 use File::Basename;
 use HTTP::Status qw(:constants :is status_message);
 use Text::ParseWords;
@@ -94,63 +93,15 @@
     return $resp;
 }
 
-sub read_password {
+my $read_password = sub {
     my $attribs = $term->Attribs;
     my $old = $attribs->{redisplay_function};
     $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
     my $input = $term->readline('password: ');
     $attribs->{redisplay_function} = $old;
     return $input;
-}
+};
 
-sub get_options {
-    my ($info, $args, $uri_param) = @_;
-
-    if (!$info->{parameters} || !$info->{parameters}->{properties}) {
-	die "too many arguments\n"
-	    if scalar(@$args) != 0;
-	return {};
-    }
-
-    my @getopt = ();
-    foreach my $prop (keys %{$info->{parameters}->{properties}}) {
-	my $pd = $info->{parameters}->{properties}->{$prop};
-	next if defined($uri_param->{$prop});
-
-	#print "PROP " . Dumper($pd) . "\n";
-
-	# we do not accept plain password on input line, instead
-	# we turn this into a boolean option and ask for password below
-	# using read_password() (for security reasons).
-	if ($pd->{type} eq 'boolean' || $prop eq 'password') {
-	    push @getopt, "$prop";
-	} else {
-	    push @getopt, "$prop=s";
-	}
-    }
-
-    my $opts = {};
-    die "unable to parse option\n"
-	if !Getopt::Long::GetOptionsFromArray($args, $opts, @getopt);
-    
-    die "too many arguments\n"
-	if scalar(@$args) != 0;
-
-    if (my $pd = $info->{parameters}->{properties}->{password}) {
-	if ($pd->{type} ne 'boolean') {
-	    if ($opts->{password} || !$pd->{optional}) {
-		$opts->{password} = read_password(); 
-	    }
-	}
-    }
-
-    foreach my $p (keys %$uri_param) {
-	$opts->{$p} = $uri_param->{$p};
-    }
-
-    return $opts;
-}
-
 sub create_entry {
     my ($dir, $args) = @_;
 
@@ -161,7 +112,7 @@
 	die "no 'create' handler for '$dir'\n";
     }
 
-    my $opts = get_options($info, $args, $uri_param);
+    my $opts = PVE::JSONSchema::get_options($info->{parameters}, $args, $uri_param, $read_password);
 
     # print "CREATE $dir " . Dumper($opts) . "\n";
 
@@ -180,7 +131,7 @@
 	die "no 'get' handler for '$dir'\n";
     }
 
-    my $opts = get_options($info, $args, $uri_param);
+    my $opts = PVE::JSONSchema::get_options($info->{parameters}, $args, $uri_param, $read_password);
 
     # print "GET $dir " . Dumper($opts) . "\n";
 
@@ -199,7 +150,7 @@
 	die "no 'update' handler for '$dir'\n";
     }
 
-    my $opts = get_options($info, $args, $uri_param);
+    my $opts = PVE::JSONSchema::get_options($info->{parameters}, $args, $uri_param, $read_password);
 
     # print "PUT $dir " . Dumper($opts) . "\n";
 
@@ -248,7 +199,7 @@
 	die "resource does not define child links\n";
     }
 
-    my $params = get_options($info, $args, $uri_param);
+    my $params = PVE::JSONSchema::get_options($info->{parameters}, $args, $uri_param, $read_password);
 
     my $res = call_handler($handler, $info, $dir, $params);
     if (!is_success($res->{status})) {




More information about the pve-devel mailing list