[pve-devel] [PATCH access-control 1/3] Add parameter userlist to pveum for listing users

Alwin Antreich a.antreich at proxmox.com
Fri Sep 22 16:32:29 CEST 2017


Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 PVE/CLI/pveum.pm | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/PVE/CLI/pveum.pm b/PVE/CLI/pveum.pm
index aef7089..0426cfb 100755
--- a/PVE/CLI/pveum.pm
+++ b/PVE/CLI/pveum.pm
@@ -18,6 +18,7 @@ use PVE::API2::ACL;
 use PVE::API2::AccessControl;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::CLIHandler;
+use POSIX qw(strftime);
 
 use base qw(PVE::CLIHandler);
 
@@ -49,6 +50,26 @@ our $cmddef = {
     useradd => [ 'PVE::API2::User', 'create_user', ['userid'] ],
     usermod => [ 'PVE::API2::User', 'update_user', ['userid'] ],
     userdel => [ 'PVE::API2::User', 'delete_user', ['userid'] ],
+    userlist => [ 'PVE::API2::User', 'index', undef, undef, sub {
+	    my $userlist = shift;
+
+	    exit 0 if (!scalar(@$userlist));
+
+	    my $format = qq(%15s %-5s %-8s %-10s %-15s %-30s %-30s\n);
+	    printf($format, qw(USERID REALM ENABLED EXPIRE NAME EMAIL COMMENT));
+
+	    foreach my $rec (sort {$a->{userid} cmp $b->{userid} } @$userlist) {
+		my $expire = $rec->{expire} eq 0 ? "" : (strftime("%Y-%m-%d",localtime($rec->{expire})));
+		my $fullname = join(" ", ($rec->{firstname} || ""), ($rec->{lastname} || ""));
+		$fullname =~ s/^\s+//;
+		my ($userid, $realm) = split('@', $rec->{userid});
+
+		printf($format, $userid, $realm, $rec->{enable},
+		$expire, $fullname, ($rec->{email} || ""),
+		($rec->{comment} || ""));
+	    }
+
+	} ],
 
     groupadd => [ 'PVE::API2::Group', 'create_group', ['groupid'] ],
     groupmod => [ 'PVE::API2::Group', 'update_group', ['groupid'] ],
-- 
2.11.0





More information about the pve-devel mailing list