API-PureStorage
view release on metacpan or search on metacpan
lib/API/PureStorage.pm view on Meta::CPAN
package API::PureStorage;
use Data::Dumper;
use REST::Client;
use JSON;
use Net::SSL;
use warnings;
use strict;
$API::PureStorage::VERSION = '0.03';
our %ENV;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
my $debug = 0;
sub new {
my $class = shift @_;
my $self = {
cookie_file => '/tmp/cookies.txt',
host => $_[0],
token => $_[1]
};
bless $self, $class;
my $client = REST::Client->new( follow => 1 );
$client->setHost('https://'.$self->{host});
$client->addHeader('Content-Type', 'application/json');
$client->getUseragent()->cookie_jar({ file => $self->{cookie_file} });
$client->getUseragent()->ssl_opts(verify_hostname => 0);
$self->{client} = $client;
# Check API compatibility
my @versions = $self->version();
my %api_versions;
for my $version (@versions) {
$api_versions{$version}++;
}
my $api_version = $api_versions{'1.4'} ? '1.4' :
$api_versions{'1.3'} ? '1.3' :
$api_versions{'1.1'} ? '1.1' :
$api_versions{'1.0'} ? '1.0' :
undef;
unless ( $api_version ) {
die "API version 1.3 or 1.4 is not supported by host: $self->{host}\n";
}
$self->{api_version} = $api_version;
### Set the Session Cookie
my $ret = $self->_api_post("/api/$api_version/auth/session", { api_token => $self->{token} });
return $self;
}
sub DESTROY {
( run in 1.401 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )