Submit a ticketCall us

Looking to compare latest NPM features with previous versions of NPM?
The NPM new feature summary offers a comparison of new features and improvements offered with this release.

 

Home > Success Center > Virtualization Manager (VMAN) > VMAN 7.1 Administrator Guide > References > Use Perl SDK scripts

Use Perl SDK scripts

Created by Caroline Juszczak, last modified by MindTouch on Jun 23, 2016

Views: 3 Votes: 0 Revisions: 3

For Windows systems, SolarWinds recommends using ActivePerl 5.16.

Before you begin

The Perl Client ::Client module requires SOAP::Lite.

To install SOAP::Lite on Linux or Mac versions of Perl, run the sudo cpan install SOAP::Lite command.

To install SOAP::Lite on Windows using ActivePerl 5.16, run the ppm install http://ppm4.activestate.com/MSWin32-...Lite-1.11.ppmx command.

Download the Perl Client

  1. Log in to the SolarWinds Customer Portal.
  2. Click License Management > License Management.
  3. Select Virtualization Manager from the product list.
  4. From the Agent Downloads section, download the Perl Client for Virtualization Manager.

The ZIP file includes the Perl Client module (Hyper9::Client) and example scripts. Extract the archive in a folder from where you will be running your scripts.

Access the Perl Client documentation

  1. Access the folder where you extracted the Perl SDK archive.
  2. Run the Perldoc Hyper9/Client.pm command.

Use the Perl SDK example script

This example contains the procedure for writing a script that:

  • Executes a search for VMs that are configured with less than 1 GB RAM
  • Collects the configuration model for each of those VMs
  • Prints the memory size and name of the VM

The example is also provided in the Perl SDK ZIP file, where it is called searchExample.pl.

  1. Create a file called searchMemory.pl, and open the file for editing.
  2. Configure the imports:

    use strict;
    use Hyper9::Client;
    use XML::Simple;
    use Data::Dumper;
    my $pageSize = 20;
    my $total = 0;

  3. Configure the script with a Hyper9::Client reference and use it to log in. Substitute the host address and credentials in the setup of the client. This example script is configured to log in to a SolarWinds Virtualization Manager server at localhost using the admin/admin credentials.

    my $client = Hyper9::Client->new(
    username => 'admin',
    password => 'admin',
    host => 'VirtualizationManagerHostnameOr',
    );
    $client->login() || die "Login failed\n\n";

  4. Use the $client variable to run any of the web service operations. For a complete list of operations, see http://your-server:8983/swvm/ws/hyper9.wsdl. To run the search operation, insert this code into your script:

    # Search for VMs configured with less than 1GB memory and retrieve their total
    # memory and memory usage at the same time
    my @results = $client->searchCustom(
    ciType => 'VirtualMachine',
    query => 'vm.memory:[0 TO 1023]',
    pageData => {
    pageSize => $pageSize,
    pageNumber => 1,
    },
    sort =>{
    sortField => 'vm.memory',
    sortDescending => 0,
    },
    paths => ['vm.memory', 'vm.memload.latest'], # these show up in 'values' on the result
    );

    The result of the search is placed into an array called @results.

  5. Insert this code into the script to collect the VMs and print how much memory they have:

    # Print out the names of the VMs and their memory size, tab delimited
    print "------------------------------------\n";
    print "Memory\tUsed\tVM Name\n";
    print "------------------------------------\n";
    foreach my $result (@results) {
    if (defined $result->{ciRef}) {
    my $memory = $result->{'values'}[0]->{'value'};
    my $memoryUtil = $result->{'values'}[1]->{'value'};
    $memoryUtil = int($memoryUtil) if $memoryUtil;
    print $memory."MB\t".$memoryUtil."%\t".$result->{ciRef}->{displayName}."\n";
    }
    elsif (defined $result->{'total'})
    {
    $total = $result->{'total'};
    }
    }
    print "....Showing $pageSize of $total\n";

  6. Insert this code into the script to log out:

    $client->logout();

  7. Save the searchMemory.pl file and run it by using perl searchMemory.pl. The result should look similar:

    ryankruse$ ./searchExample.pl
    512MBSarasota
    768MBJacksonville
    256MBNatchitoches Parish
    768MBApalachicola
    256MBInx Lake
    512MBReunion Arena
    512MBUbuntu 64 bit
    256MBJohnson Space Center
    256MBInsta-Gator Ranch
    768MBClearwater
    512MBDixie Landing
    512MBLafayette
    512MBOdessa
    512MBRiver Ranch

Place responses into arrays or scalars

You can place the responses from a Hyper9::Client call directly into an array or a scalar, depending on what the web service call sends in its response.

Accept a response into a scalar:
my $response = $client->methodThatReturnsSingleThing();

Accept a response into an array:
my @response = $client->methodThatReturnsMultipleThings();

To check the structure of the response variable, use the Data::Dumper module in Perl:
use Data::Dumper; print Dumper(@response);

 
Last modified
04:20, 23 Jun 2016

Tags

Classifications

Public