[pve-devel] r4846 - in pve-manager/pve2: . lib/PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jun 25 17:02:32 CEST 2010


Author: dietmar
Date: 2010-06-25 15:02:32 +0000 (Fri, 25 Jun 2010)
New Revision: 4846

Modified:
   pve-manager/pve2/ChangeLog
   pve-manager/pve2/lib/PVE/API2Client.pm
   pve-manager/pve2/lib/PVE/REST.pm
Log:
impl. PUT/DELETE



Modified: pve-manager/pve2/ChangeLog
===================================================================
--- pve-manager/pve2/ChangeLog	2010-06-25 14:28:36 UTC (rev 4845)
+++ pve-manager/pve2/ChangeLog	2010-06-25 15:02:32 UTC (rev 4846)
@@ -1,5 +1,7 @@
 2010-06-25  Proxmox Support Team  <support at proxmox.com>
 
+	* lib/PVE/REST.pm (proxy_handler): impl. PUT/DELETE
+
 	* lib/PVE/JSONSchema.pm: add 'protected' property to method_shema
 
 	* lib/PVE/REST.pm (proxy_handler): automatically proxy protected

Modified: pve-manager/pve2/lib/PVE/API2Client.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2Client.pm	2010-06-25 14:28:36 UTC (rev 4845)
+++ pve-manager/pve2/lib/PVE/API2Client.pm	2010-06-25 15:02:32 UTC (rev 4846)
@@ -21,6 +21,18 @@
     return $self->call('POST', $path, $param);
 }
 
+sub put {
+    my ($self, $path, $param) = @_;
+
+    return $self->call('PUT', $path, $param);
+}
+
+sub delete {
+    my ($self, $path, $param) = @_;
+
+    return $self->call('DELETE', $path, $param);
+}
+
 sub call {
     my ($self, $method, $path, $param) = @_;
 	
@@ -58,22 +70,25 @@
     $uri->port($self->{port});
     $uri->path($path);
 
+    # print $ua->{cookie_jar}->as_string;
 
-    print $ua->{cookie_jar}->as_string;
-
+    print "CALL $method : " .  $uri->as_string() . "\n";
+ 
     my $response;
     if ($method eq 'GET') {
 	$uri->query_form($param);
-	print "CALL GET : " .  $uri->as_string() . "\n";
-	$response = $ua->get($uri);
-	print "RESP: " . Dumper($response) . "\n";
+	$response = $ua->request(HTTP::Request::Common::GET($uri));			   
     } elsif ($method eq 'POST') {
-	print "CALL POST : " .  $uri->as_string() . "\n";
-	$response = $ua->post($uri, $param);
-	print "RESP: " . Dumper($response) . "\n";
+	$response = $ua->request(HTTP::Request::Common::POST($uri, Content => $param));
+    } elsif ($method eq 'PUT') {
+	$response = $ua->request(HTTP::Request::Common::PUT($uri, Content => $param));
+    } elsif ($method eq 'DELETE') {
+	$response = $ua->request(HTTP::Request::Common::DELETE($uri));
     } else {
 	die "method $method not implemented\n";
     }
+			      
+    print "RESP: " . Dumper($response) . "\n";
 
     if ($response->is_success) {
 	my $ct = $response->header('Content-Type');

Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm	2010-06-25 14:28:36 UTC (rev 4845)
+++ pve-manager/pve2/lib/PVE/REST.pm	2010-06-25 15:02:32 UTC (rev 4846)
@@ -9,6 +9,8 @@
 use CGI;
 use mod_perl2;
 use JSON;
+use LWP::UserAgent;
+use HTTP::Request::Common;
 
 use Data::Dumper; # fixme: remove
 
@@ -102,9 +104,13 @@
     my $response;
     if ($method eq 'GET') {
 	$uri->query_form($params);
-	$response = $ua->get($uri);
+	$response = $ua->request(HTTP::Request::Common::GET($uri));		    
     } elsif ($method eq 'POST') {
-	$response = $ua->post($uri, $params);
+	$response = $ua->request(HTTP::Request::Common::POST($uri, Content => $params));
+    } elsif ($method eq 'PUT') {
+	$response = $ua->request(HTTP::Request::Common::PUT($uri, Content => $params));
+    } elsif ($method eq 'DELETE') {
+	$response = $ua->request(HTTP::Request::Common::DELETE($uri));
     } else {
 	my $code = HTTP_NOT_IMPLEMENTED;
 	$r->status_line("$code proxy method '$method' not implemented");




More information about the pve-devel mailing list