From 412f0a19f5f48e59b33c5f38f8f9723eb5ef214c Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Tue, 11 Dec 2018 16:29:25 +0100 Subject: [PATCH] fix cloud ibm softlayer api (#1273) --- cloud/ibm/softlayer/custom/xmlapi.pm | 11 +++++++++-- cloud/ibm/softlayer/mode/events.pm | 4 ++-- cloud/ibm/softlayer/mode/opentickets.pm | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cloud/ibm/softlayer/custom/xmlapi.pm b/cloud/ibm/softlayer/custom/xmlapi.pm index b9d2cd685..0084a7d51 100644 --- a/cloud/ibm/softlayer/custom/xmlapi.pm +++ b/cloud/ibm/softlayer/custom/xmlapi.pm @@ -186,9 +186,16 @@ sub get_endpoint { my $response = $self->{http}->request(url_path => $self->{url_path} . '/' . $options{service}, method => 'POST', query_form_post => $content); - my $xml_hash = XMLin($response); + my $xml_hash = XMLin($response, ForceArray => ['item']); + + if (defined($xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'})) { + $self->{output}->output_add(long_msg => "Returned message: " . $response, debug => 1); + $self->{output}->add_option_msg(short_msg => "API returned error code '" . $xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'}->{faultcode} . + "' with message '" . $xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'}->{faultstring} . "'"); + $self->{output}->option_exit(); + } - return $xml_hash->{'SOAP-ENV:Header'}, $xml_hash->{'SOAP-ENV:Body'}; + return $xml_hash->{'SOAP-ENV:Body'}; } 1; diff --git a/cloud/ibm/softlayer/mode/events.pm b/cloud/ibm/softlayer/mode/events.pm index 87d187fe3..99ff0b3fc 100644 --- a/cloud/ibm/softlayer/mode/events.pm +++ b/cloud/ibm/softlayer/mode/events.pm @@ -179,7 +179,7 @@ sub manage_selection { my $current_time = time(); my %status_hash; - my (undef, $events) = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getAllObjects', extra_content => ''); + my $events = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getAllObjects', extra_content => ''); foreach my $event (@{$events->{'ns1:getAllObjectsResponse'}->{'getAllObjectsReturn'}->{'item'}}) { my $status; $status = $event->{statusCode}->{name}->{content} if (defined($event->{statusCode}->{name}->{content})); @@ -192,7 +192,7 @@ sub manage_selection { ' . $event->{id}->{content} . ' '; - my (undef, $ressources) = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getImpactedResources', extra_content => $extra_content); + my $ressources = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getImpactedResources', extra_content => $extra_content); my $items = 0; if (defined($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'})) { $items = 1; diff --git a/cloud/ibm/softlayer/mode/opentickets.pm b/cloud/ibm/softlayer/mode/opentickets.pm index 0fc78469a..57c904ea0 100644 --- a/cloud/ibm/softlayer/mode/opentickets.pm +++ b/cloud/ibm/softlayer/mode/opentickets.pm @@ -156,7 +156,7 @@ sub manage_selection { my $group_id = ''; my %groups_hash; - my (undef, $groups) = $options{custom}->get_endpoint(service => 'SoftLayer_Ticket', method => 'getAllTicketGroups', extra_content => ''); + my $groups = $options{custom}->get_endpoint(service => 'SoftLayer_Ticket', method => 'getAllTicketGroups', extra_content => ''); foreach my $group (@{$groups->{'ns1:getAllTicketGroupsResponse'}->{'getAllTicketGroupsReturn'}->{'item'}}) { $groups_hash{$group->{id}->{content}} = $group->{name}->{content}; @@ -173,7 +173,7 @@ sub manage_selection { my $current_time = time(); - my (undef, $tickets) = $options{custom}->get_endpoint(service => 'SoftLayer_Account', method => 'getOpenTickets', extra_content => ''); + my $tickets = $options{custom}->get_endpoint(service => 'SoftLayer_Account', method => 'getOpenTickets', extra_content => ''); foreach my $ticket (@{$tickets->{'ns1:getOpenTicketsResponse'}->{'getOpenTicketsReturn'}->{'item'}}) { next if (defined($group_id) && $group_id ne '' && $ticket->{groupId}->{content} ne $group_id);