OnCommand Storage Management Software Discussions

Re: perl webservices client

Here are some more examples of using Perl to interact with WFA via SOAP...along with comments that give some hints about where I had struggles.  I'm not sure if my struggles were due to the immaturity of the SOAP::Lite module or my own lack of SOAP experience, but I suspect it's a combination of both .

wfa_get_all_workflows.pl

------------------------------------

#!/usr/bin/perl -w

use strict;

# Use 'trace' if you need to debug the XML interactions.

#use SOAP::Lite 'trace';

use SOAP::Lite;

# We have to use the RPC interface for SOAP calls that don't have

# any arguments.  Google xsi:nil true soap::lite if you want the gory

# details about how SOAP::Lite is broken.  Thankfully, WFA supports

# both doc and rpc interfaces.

my $soapurl   = 'http://WFA_IP/wfa-ws/WorkflowService_rpc?wsdl';

my $namespace = 'http://ws.wfa.netapp.com/';

my $user      = "admin";

my $pass      = "admin";

sub SOAP::Transport::HTTP::Client::get_basic_credentials {

        return $user => $pass;

}

my $service = new SOAP::Lite

        uri   => $namespace,

        proxy => $soapurl,

;

$service->ns($namespace);

# Setting autotype is not really necessary, but I like it when debugging.

$service->autotype('0');

# The use_prefix setting is deprecated, but I think it makes debbuing easier

# if you have tracing enabled.

#$service->use_prefix('0');

my $som    = $service->getAllWorkflows();

my $result = $som->result;

my $items  = $result->{'item'};

for my $item (@$items) {

        print "Workflow ID:          $item->{'id'}\n";

        print "Workflow Category:    $item->{'category'}\n";

        print "Workflow Name:        $item->{'name'}\n";

        print "Workflow Description: $item->{'description'}\n";

        print "Workflow Input: \n";

        my $inputs = $item->{'userInput'};

        for my $input (sort @$inputs) {

                print "  $input->{'name'} ($input->{'type'})\n";

        }

        print "\n";

}

------------------------------------

wfa_run_workflow.pl

----------------------------

#!/usr/bin/perl -w

use strict;

# Use 'trace' if you need to debug the XML interactions.

#use SOAP::Lite 'trace';

use SOAP::Lite;

# Oddly, the doc interface works and the rpc interface does not work when

# making a SOAP call with arguments.  The opposite is true when making

# SOAP calls with no arguments.  Good thing WFA supports both.  SOAP is fun.

my $soapurl   = 'http://WFA_IP/wfa-ws/WorkflowService_doc?wsdl';

my $namespace = 'http://ws.wfa.netapp.com/';

my $user      = "admin";

my $pass      = "admin";

sub SOAP::Transport::HTTP::Client::get_basic_credentials {

        return $user => $pass;

}

my $service = new SOAP::Lite

        uri   => $namespace,

        proxy => $soapurl,

;

$service->ns($namespace);

# Setting autotype is not really necessary, but I like it when debugging.

$service->autotype('0');

# The use_prefix setting is deprecated, but I think it makes debbuing easier

# if you have tracing enabled.

#$service->use_prefix('0');

my $wfid      = 31;

my $wfidparam = SOAP:Smiley Very Happyata->name('workflowId')->value($wfid);

my $wfparams  = SOAP:Smiley Very Happyata->name('userInputsEqualsValues')->value

([

        'controllerName=demo3020a.demo.ntapmn.com',

        'vfilerName=dmvfiler1',

        'volName_1=arndt_test',

        'qtreeName_1=wfasoapqt4',

        'qtreeStyle_1=unix',

        'create_Share_1=no',

        'create_Export_1=yes',

        'rootHosts=10.26.69.212:10.26.69.213',

]);

# I had to set even the optional arguments to make this work.

my $wftime   = SOAP:Smiley Very Happyata->name('executionDateAndTime')->value('');

my $wfcom    = SOAP:Smiley Very Happyata->name('comment')->value('');

my $som = $service->runWorkflow($wfidparam,$wfparams,$wftime,$wfcom);

if ($som->faultcode) {

        print "Fault Code:", $som->faultcode, "\n";

        print "Fault String:", $som->faultstring, "\n";

} else {

        my $result   = $som->result;

        print "Job $result has been submitted.\n";

}

----------------------------

wfa_get_job_status.pl

-------------------------------

#!/usr/bin/perl -w

use strict;

# Use 'trace' if you need to debug the XML interactions.

#use SOAP::Lite 'trace';

use SOAP::Lite;

# Oddly, the doc interface works and the rpc interface does not work when

# making a SOAP call with arguments.  The opposite is true when making

# SOAP calls with no arguments.  Good thing WFA supports both.  SOAP is fun.

my $soapurl   = 'http://WFA_IP/wfa-ws/WorkflowService_doc?wsdl';

my $namespace = 'http://ws.wfa.netapp.com/';

my $user      = "admin";

my $pass      = "admin";

sub SOAP::Transport::HTTP::Client::get_basic_credentials {

        return $user => $pass;

}

my $service = new SOAP::Lite

        uri   => $namespace,

        proxy => $soapurl,

;

$service->ns($namespace);

# Setting autotype is not really necessary, but I like it when debugging.

$service->autotype('0');

# The use_prefix setting is deprecated, but I think it makes debbuing easier

# if you have tracing enabled.

#$service->use_prefix('0');

my $jobid      = 392;

my $jobidparam = SOAP:Smiley Very Happyata->name('jobId')->value($jobid);

my $som = $service->getJobStatus($jobidparam);

if ($som->faultcode) {

        print "Fault Code:", $som->faultcode, "\n";

        print "Fault String:", $som->faultstring, "\n";

} else {

        my $result   = $som->result;

        print "Job start time: $result->{'startTime'}\n";

        print "Job end time:   $result->{'endTime'}\n" if ($result->{'endTime'});

        print "Job status:     $result->{'jobStatus'}\n";

        print "Job messages:   $result->{'errorMessage'}\n" if ($result->{'errorMessage'});

}

-------------------------------

Forums