[pve-devel] [PATCH] - add ssl / https support for nexenta -	die	with content for json errors
    Alexandre DERUMIER 
    aderumier at odiso.com
       
    Wed Aug  8 06:15:31 CEST 2012
    
    
  
about
"-    my $obj = from_json($res->content);
-    print $obj->{error}->{message} if $obj->{error}->{message};
-    return undef if $obj->{error}->{message};"
I don't die here, because in alloc_image for exemple:
1)nexenta_create_zvol($name, $size, $scfg);
2)nexenta_create_lu($name, $scfg);
3)die "error create zvol" if !nexenta_add_lun_mapping_entry($name, $scfg);
or free_image
1)nexenta_delete_lu($name, $scfg);
2)die "error deleting volume" if !nexenta_delete_zvol($name, $scfg);
if something goes wrong in last step, and that we wan't retry again to add/remove,
It'll retry the firsts steps and die.
So I never die on the firsts steps.
(I could manage some kind of rollback if something goes wrong, but if something hang in the rollback, this is difficult to manage)
----- Mail original ----- 
De: "Stefan Priebe" <s.priebe at profihost.ag> 
À: pve-devel at pve.proxmox.com 
Cc: "spriebe" <git at profihost.ag> 
Envoyé: Mardi 7 Août 2012 22:14:18 
Objet: [pve-devel] [PATCH] - add ssl / https support for nexenta - die with content for json errors 
From: spriebe <git at profihost.ag> 
Signed-off-by: Stefan Priebe <s.priebe at profihost.ag> 
--- 
PVE/Storage/NexentaPlugin.pm | 16 ++++++++++++---- 
1 files changed, 12 insertions(+), 4 deletions(-) 
diff --git a/PVE/Storage/NexentaPlugin.pm b/PVE/Storage/NexentaPlugin.pm 
index 6ad92d9..34de7ef 100644 
--- a/PVE/Storage/NexentaPlugin.pm 
+++ b/PVE/Storage/NexentaPlugin.pm 
@@ -16,7 +16,7 @@ use base qw(PVE::Storage::Plugin); 
sub nexenta_request { 
my ($scfg, $json) = @_; 
- my $uri = "http://".$scfg->{portal}.":2000/rest/nms/"; 
+ my $uri = ( $scfg->{ssl} ? "https" : "http" ) . "://" . $scfg->{portal} . ":2000/rest/nms/"; 
my $req = HTTP::Request->new( 'POST', $uri ); 
$req->header( 'Content-Type' => 'application/json' ); 
@@ -29,9 +29,12 @@ sub nexenta_request { 
if (!$res->is_success) { 
die $res->content; 
} 
- my $obj = from_json($res->content); 
- print $obj->{error}->{message} if $obj->{error}->{message}; 
- return undef if $obj->{error}->{message}; 
+ 
+ my $obj = eval { from_json($res->content); }; 
+ die "JSON not valid. Content: " . $res->content if ($@); 
+ 
+ die "Nexenta API Error: " . $obj->{error}->{message} if $obj->{error}->{message}; 
+ 
return $obj->{result} if $obj->{result}; 
return 1; 
} 
@@ -139,6 +142,10 @@ sub plugindata { 
sub properties { 
return { 
+ ssl => { 
+ description => "ssl", 
+ type => 'bool', 
+ }, 
login => { 
description => "login", 
type => 'string', 
@@ -156,6 +163,7 @@ sub properties { 
sub options { 
return { 
+ ssl => { fixed => 1 }, 
target => { fixed => 1 }, 
portal => { fixed => 1 }, 
login => { fixed => 1 }, 
-- 
1.7.2.5 
_______________________________________________ 
pve-devel mailing list 
pve-devel at pve.proxmox.com 
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 
-- 
-- 
	
Alexandre D e rumier 
Ingénieur Systèmes et Réseaux 
Fixe : 03 20 68 88 85 
Fax : 03 20 68 90 88 
45 Bvd du Général Leclerc 59100 Roubaix 
12 rue Marivaux 75002 Paris 
    
    
More information about the pve-devel
mailing list