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

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Aug 27 13:08:00 CEST 2010


Author: dietmar
Date: 2010-08-27 11:08:00 +0000 (Fri, 27 Aug 2010)
New Revision: 5075

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


Modified: pve-manager/pve2/bin/pvesh
===================================================================
--- pve-manager/pve2/bin/pvesh	2010-08-27 10:43:46 UTC (rev 5074)
+++ pve-manager/pve2/bin/pvesh	2010-08-27 11:08:00 UTC (rev 5075)
@@ -52,18 +52,11 @@
 
 	my @res = ();
 
-	my $uri_param = {};
-	my ($handler, $info) = PVE::API2->find_handler('GET', $path, $uri_param);
-	if ($handler && $info) {
-	    eval {
-		my $data = $handler->handle($info, $uri_param);
-		my $lnk = PVE::JSONSchema::method_get_child_link($info);
-		my $children = extract_children($lnk, $data);
-
-		foreach my $c (@$children) {
-		    push @res, $dir ? "$dir$c" : $c;
-		}
-	    }; # ignore errors
+	my $di = dir_info($path);
+	if (my $children = $di->{children}) {
+	    foreach my $c (@$children) {
+		push @res, $dir ? "$dir$c" : $c;
+	    }
 	}
 	return @res;
     }
@@ -195,20 +188,12 @@
 	die "no such resource\n";
     }
 
-    my $uri_param = {};
-    my ($handler, $info, $pm) = PVE::API2->find_handler('GET', $path, $uri_param);
-    if ($handler && $info) {
-	# gather info about children	
-	eval {
-	    my $data = $handler->handle($info, $uri_param);
-	    my $lnk = PVE::JSONSchema::method_get_child_link($info);
-	    my $children = extract_children($lnk, $data);
-
-	    foreach my $c (@$children) {
-		my $cp = abs_path($path, $c);
-		find_resource_methods($cp, $ihash);
-	    }
-	}; # ignore errors ?
+    my $di = dir_info($path);
+    if (my $children = $di->{children}) {
+	foreach my $c (@$children) {
+	    my $cp = abs_path($path, $c);
+	    find_resource_methods($cp, $ihash);
+	}
     }
 
     foreach my $mi (sort { $a->{path} cmp $b->{path} } values %$ihash) {
@@ -290,6 +275,22 @@
     return $res;
 }
 
+sub dir_info {
+    my ($path) = @_;
+
+    my $res = { path => $path };
+    my $uri_param = {};
+    my ($handler, $info, $pm) = PVE::API2->find_handler('GET', $path, $uri_param);
+    if ($handler && $info) {
+	eval {
+	    my $data = $handler->handle($info, $uri_param);
+	    my $lnk = PVE::JSONSchema::method_get_child_link($info);
+	    $res->{children} = extract_children($lnk, $data);
+	}; # ignore errors ?
+    }
+    return $res;
+}
+
 sub list_dir {
     my ($dir, $args) = @_;
 




More information about the pve-devel mailing list