[pve-devel] [PATCH] - add ssl / https support for nexenta - die with content for json errors

Stefan Priebe s.priebe at profihost.ag
Wed Aug 8 08:36:22 CEST 2012


OK.

The SSL patch ist still needed ;-) Should i make a seperate patch just 
for https?

In general we need some useful error messages if something goes wrong. 
Your print goes to /dev/null so nobody can use it.

Why not use something like try catch in case we know an error might be 
raised?

Greets,
Stefan

Am 08.08.2012 06:15, schrieb Alexandre DERUMIER:
> 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 },
>


More information about the pve-devel mailing list