The following Perl example shows how to set up to start interacting with the system. Following the sample are Perl function calls that import the example file, specify a target IP address, retrieve an authentication token, and finally use the authentication token to carry out an action on a system target.
See Spectrum Virtualize RESTful API to view a Python 3 language example or rest_api_usage_examples.html to view examples that use the curl command-line utility.
#!/usr/bin/perl -w use strict; use warnings; use HTTP::Request; use HTTP::Headers; use LWP::UserAgent; use JSON::PP; my $ua = LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => 'SSL_VERIFY_NONE' }j; sub command{ my($host, $target, $method, $header_ref, $data_ref) = @_; my $data_json = %{$data_ref} ? encode_json($data_ref) : ""; my $request = HTTP::Request->new($method => "https://$host:7443/$target", HTTP::Headers->new(%{$header_ref}), $data_json); $request->header(Content_Type => 'application/json'); my $response = $ua->request($request); return decode_json($response->content); }
do “rest_perl.pl”;
$host = “system_IP_address”;
$token = command($host, 'API_version/auth', 'POST', {"X-Auth-Password" => "password", "X-Auth-Username" => "username"}, {})->{"token"};
$out = command($host, '1.0/array', 'POST', {"X-Auth-Token" => $token}, {raid_level => "raid5"});