[pve-devel] r4862 - pve-manager/pve2/bin

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Jul 1 13:24:01 CEST 2010


Author: dietmar
Date: 2010-07-01 11:24:01 +0000 (Thu, 01 Jul 2010)
New Revision: 4862

Modified:
   pve-manager/pve2/bin/pvesh
Log:
further cleanups


Modified: pve-manager/pve2/bin/pvesh
===================================================================
--- pve-manager/pve2/bin/pvesh	2010-07-01 10:03:37 UTC (rev 4861)
+++ pve-manager/pve2/bin/pvesh	2010-07-01 11:24:01 UTC (rev 4862)
@@ -54,6 +54,29 @@
     return $ret;
 }
 
+sub print_result {
+    my ($info, $res, $nodata) = @_;
+
+    my $status = $res->{status};
+    if (!is_success($status)) {
+	if ($res->{errors}) {
+	    foreach my $e (keys %{$res->{errors}}) {
+		warn "$e: $res->{errors}->{$e}\n";
+	    }
+	}
+    }
+
+    my $msg = $res->{message} || status_message($status);
+
+    warn "$status $msg\n";
+
+    return if $nodata;
+    return if $info && $info->{returns} && 
+	$info->{returns}->{type} && $info->{returns}->{type} eq 'null';
+
+    print to_json($res->{data}, {allow_nonref => 1, canonical => 1, pretty => 1 });
+}
+
 sub call_handler {
     my ($handler, $info, $dir, $params) = @_;
 
@@ -67,20 +90,7 @@
     my $resp = {}; 
     my $status = $handler->handle($info, $conn, $resp);
 
-    #print "GOT $status " . Dumper($resp);
-
-    if ($status && ($status != HTTP_OK)) {
-	if ($resp->{errors}) {
-	    foreach my $e (keys %{$resp->{errors}}) {
-		warn "$e: $resp->{errors}->{$e}\n";
-	    }
-	}
-	die "$status $resp->{message}\n" if $resp->{message};
-	die status_message($status) . "\n";
-    }
-
-
-    return $resp->{data};
+    return $resp;
 }
 
 sub read_password {
@@ -148,8 +158,9 @@
 
     # print "CREATE $dir " . Dumper($opts) . "\n";
 
-    my $data = call_handler($handler, $info, $dir, $opts);
+    my $res = call_handler($handler, $info, $dir, $opts);
 
+    print_result($info, $res);
 }
 
 sub get_entry {
@@ -165,9 +176,9 @@
 
     # print "GET $dir " . Dumper($opts) . "\n";
 
-    my $data = call_handler($handler, $info, $dir, $opts);
+    my $res = call_handler($handler, $info, $dir, $opts);
 
-    print to_json($data, {allow_nonref => 1, canonical => 1, pretty => 1 });
+    print_result($info, $res);
 }
 
 sub update_entry {
@@ -183,9 +194,9 @@
 
     # print "PUT $dir " . Dumper($opts) . "\n";
 
-    my $data = call_handler($handler, $info, $dir, $opts);
+    my $res = call_handler($handler, $info, $dir, $opts);
 
-    print to_json($data, {allow_nonref => 1, canonical => 1, pretty => 1});
+    print_result($info, $res);
 }
 
 sub delete_entry {
@@ -199,7 +210,9 @@
     
     # print "DELETE $dir\n";
 
-    my $data = call_handler($handler, $info, $dir, {});
+    my $res = call_handler($handler, $info, $dir, {});
+    
+    print_result($info, $res);
 }
 
 sub test_dir {
@@ -219,8 +232,6 @@
 sub list_dir {
     my ($dir, $args) = @_;
 
-    #print "LIST $dir\n";
-
     my ($handler, $info) = test_dir($dir);
     if (!$handler || !$info) {
 	die "no such directory\n";
@@ -228,9 +239,13 @@
 
     my $params = get_options($info, $args);
 
-    # print "LIST $dir " . Dumper($params) . "\n";
+    my $res = call_handler($handler, $info, $dir, $params);
+    if (!is_success($res->{status})) {
+	print_result($info, $res, 1);
+	return;
+    }
 
-    my $data = call_handler($handler, $info, $dir, $params);
+    my $data = $res->{data};
 
     my $lnk = PVE::JSONSchema::method_get_index_link($info);
     if ($lnk && $data) {
@@ -255,8 +270,6 @@
 	    }
 	}
     }
-
-    #print Dumper($data);
 }
 
 sub pve_command {
@@ -264,7 +277,6 @@
 
     my $args = [ shellwords($input) ];
 
-
     my $cmd = shift @$args;
 
     #print "CMD: $cmd\n";
@@ -350,5 +362,5 @@
     eval {
 	pve_command ($input);
     };
-    print "ERROR: $@" if $@;
+    warn $@ if $@;
 }




More information about the pve-devel mailing list