jhyland87 has asked for the wisdom of the Perl Monks concerning the following question:

So I am creating my own perl module to manage a Big-IP F5 load balancer. I realize theres already a module for it, but it sucks, and it doesn't have many features, if you want it done right, do it yourself! right?

Anyways, heres my WORKING example of how to do it, without just using subroutines in the same file.

#!/usr/bin/perl use strict; use Data::Dumper; use SOAP::Lite; use UNIVERSAL 'isa'; my $user = "xxxx"; my $pass = "xxxx"; my $host = "xxxx"; $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; sub newF5 { my ($server, $user, $pass) = (@_); my $proxy_uri = sprintf("https://%s:443/iControl/iControlPortal.cg +i", $server); my $soap = SOAP::Lite->proxy($proxy_uri); sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $user => $pass; } return $soap; } sub getActivePartition { my ($soap) = (@_); my $soapResponse = $soap->uri("urn:iControl:Management/Partition") +->get_active_partition(); #$self->checkResponse($soapResponse); my $partition = $soapResponse->result; return $partition; } my $connection = newF5($host, $user, $pass); print getActivePartition($connection)."\n";

Now that works just fine, but I cant get it to work when I put it in a .pm file and try to use it as a module. Code is below.

PERL MODULE (File: ./BigIP/F5/F5.pm)

package BigIP::F5; #use strict; use SOAP::Lite; use UNIVERSAL 'isa'; use Data::Dumper; $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; sub new { my ($server, $user, $pass) = (@_); my $proxy_uri = sprintf("https://%s:443/iControl/iControlPortal.cg +i", $server); my $soap = SOAP::Lite->proxy($proxy_uri); sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $user => $pass; } return $soap; } sub getActivePartition { my ($self, $soap) = (@_); my $soapResponse = $soap->uri("urn:iControl:Management/Partition") +->get_active_partition(); #$self->checkResponse($soapResponse); my @partition = @{$soapResponse->result}; return @partition; } 1;

Example of using the perl module

#!/usr/bin/perl #use strict; use Data::Dumper; use lib "./"; use BigIP::F5; my $user = "xxxx"; my $pass = "xxxx"; my $host = "xxxx"; my $connection = BigIP::F5->new($host, $user, $pass); my $partition = BigIP::F5->getActivePartition($connection); print $partition."\n";

That doesn't work, the error I get is: 500 Can't connect to BigIP::F5:443 (Bad service '443') at /BigIP/F5.pm line 50

I cant figure out what the problem is, i know the un/pw works because the first example works, its just not in the perl module.

Any ideas?

Replies are listed 'Best First'.
Re: Creating my own perl module, having issues with SOAP tho
by Eliya (Vicar) on Dec 30, 2011 at 21:05 UTC
    my $connection = BigIP::F5->new($host, $user, $pass);

    You're calling new() the object oriented style, but the routine isn't written to act as such, i.e. it doesn't expect the package/class ("BigIP::F5") as the first parameter (and it doesn't return a proper (blessed) object of that class).  The unexpected parameter causes the error message, because it sets $server to "BigIP::F5".

    When you say BigIP::F5->new($host,...) the first parameter passed to the routine is the package/class name, while if you call it non-OO style, i.e. BigIP::F5::new($host,...), the first parameter will be $host.

      Do you have an example of how to set this up correctly? Im kinda new to scripting in OOP style

        Ohhh hold on, I get it. In my Subroutine in the perl module, it needs to be...

        ... my ($self, $server, $user, $pass) = (@_); ...

        Ill try that tomorrow at work and let you know how it goes

Re: Creating my own perl module, having issues with SOAP tho
by ~~David~~ (Hermit) on Dec 30, 2011 at 21:08 UTC
    Updated: See answer above... mine was wrong