[pve-devel] r5053 - pve-access-control/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Aug 25 14:52:18 CEST 2010


Author: dietmar
Date: 2010-08-25 12:52:18 +0000 (Wed, 25 Aug 2010)
New Revision: 5053

Modified:
   pve-access-control/trunk/ChangeLog
   pve-access-control/trunk/pveum
Log:
	* pveum: use new PVE::CLIHandler


Modified: pve-access-control/trunk/ChangeLog
===================================================================
--- pve-access-control/trunk/ChangeLog	2010-08-25 12:04:24 UTC (rev 5052)
+++ pve-access-control/trunk/ChangeLog	2010-08-25 12:52:18 UTC (rev 5053)
@@ -1,3 +1,7 @@
+2010-08-25  Proxmox Support Team  <support at proxmox.com>
+
+	* pveum: use new PVE::CLIHandler
+
 2010-08-24  Proxmox Support Team  <support at proxmox.com>
 
 	* pveum: use new PVE::RPCEnvironment

Modified: pve-access-control/trunk/pveum
===================================================================
--- pve-access-control/trunk/pveum	2010-08-25 12:04:24 UTC (rev 5052)
+++ pve-access-control/trunk/pveum	2010-08-25 12:52:18 UTC (rev 5053)
@@ -13,6 +13,10 @@
 use PVE::API2::Role;
 use PVE::API2::ACL;
 
+use PVE::CLIHandler;
+
+use base qw(PVE::CLIHandler);
+
 use Data::Dumper; # fixme: remove
 
 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
@@ -53,11 +57,6 @@
     print STDERR "\n";
 }
 
-if (!scalar (@ARGV)) {
-    print_usage ("no command specified");
-    exit (-1);
-}
-
 my $read_password = sub {
 
     my $term = new Term::ReadLine ('pveum');
@@ -69,113 +68,30 @@
     return $input;
 };
 
-my $cmd = shift;
+my $cmddef = {
+    ticket => [ 'PVE::API2::User', 'create_ticket', ['userid'], undef,
+		sub {
+		    my $ticket = shift;
+		    print "$ticket\n";
+		}],
+    useradd => [ 'PVE::API2::User', 'create_user', ['userid'] ],
+    usermod => [ 'PVE::API2::User', 'update_user', ['userid'] ],
+    userdel => [ 'PVE::API2::User', 'delete_user', ['userid'] ],
 
-if ($cmd eq 'ticket') {
+    groupadd => [ 'PVE::API2::Group', 'create_group', ['groupid'] ],
+    groupdel => [ 'PVE::API2::Group', 'delete_group', ['groupid'] ],
 
-    my $username = shift;
+    roleadd => [ 'PVE::API2::Role', 'create_role', ['roleid'] ],
+    rolemod => [ 'PVE::API2::Role', 'update_role', ['roleid'] ],
+    roledel => [ 'PVE::API2::Role', 'delete_role', ['roleid'] ],
+    aclmod => [ 'PVE::API2::ACL', 'update_acl', ['path', 'uglist', 'roles'], { delete => 0 }],
+    acldel => [ 'PVE::API2::ACL', 'update_acl', ['path', 'uglist', 'roles'], { delete => 1 }],
+};
 
-    my $ticket = PVE::API2::User->cli_handler('create_ticket', \@ARGV, { userid => $username }, $read_password);
-    print "$ticket\n";
+my $cmd = shift;
 
-    exit (0);
+PVE::CLIHandler::handle_cmd($cmddef, "pveum", $cmd, \@ARGV, $read_password);
 
-} elsif ($cmd eq 'useradd') {
-
-    my $username = shift;
-
-    PVE::API2::User->cli_handler('create_user', \@ARGV, { userid => $username }, $read_password);
-
-    exit(0);
-
-} elsif ($cmd eq 'usermod') {
-
-    my $username = shift;
-
-    PVE::API2::User->cli_handler('update_user', \@ARGV, { userid => $username }, $read_password);
-
-    exit(0);
-
-} elsif ($cmd eq 'userdel') {
-
-    my $username = shift;
-
-    PVE::API2::User->cli_handler('delete_user', \@ARGV, { userid => $username });
-
-    exit(0);
-
-} elsif ($cmd eq 'groupadd') {
-
-    my $group = shift;
-
-    PVE::API2::Group->cli_handler('create_group', \@ARGV, { groupid => $group });
-
-    exit (0);
-
-} elsif ($cmd eq 'groupdel') {
-
-    my $group = shift;
-
-    PVE::API2::Group->cli_handler('delete_group', \@ARGV, { groupid => $group });
-
-    exit(0);
-
-} elsif ($cmd eq 'roleadd') {
-
-    my $role = shift;
-
-    PVE::API2::Role->cli_handler('create_role', \@ARGV, { roleid => $role });
-
-    exit(0);
-
-} elsif ($cmd eq 'rolemod') {
-
-    my $role = shift;
-
-    PVE::API2::Role->cli_handler('update_role', \@ARGV, { roleid => $role });
-
-    exit(0);
-
-} elsif ($cmd eq 'roledel') {
-
-    my $role = shift;
-
-    PVE::API2::Role->cli_handler('delete_role', \@ARGV, { roleid => $role });
-
-    exit(0);
-
-} elsif ($cmd eq 'aclmod') {
-
-    my $opts = {};
-
-    $opts->{path} = shift;
-    $opts->{uglist} = shift;
-    $opts->{roles} = shift;
-
-    PVE::API2::ACL->cli_handler('update_acl', \@ARGV, $opts);
-
-    exit(0);
-
-} elsif ($cmd eq 'acldel') {
-
-    my $opts = {};
-
-    $opts->{path} = shift;
-    $opts->{uglist} = shift;
-    $opts->{roles} = shift;
-    $opts->{delete} = 1;
-
-    PVE::API2::ACL->cli_handler('update_acl', \@ARGV, $opts);
-
-    exit(0);
-
-} else {
-
-    print_usage("unknown command '$cmd'");
-    exit(-1);
-
-}
-
 exit 0;
 
 __END__



More information about the pve-devel mailing list