Perl ARX Volume

Problem this snippet solves:

This script is an example of how to use the iControl interfaces provided by an ARX to retrieve all volumes and their configurations, statuses and statistics on an ARX.

How to use this snippet:

ARXVolumeExample.pl --url  --user  --pass 

Prerequisites

  1. SOAP::Lite perl module
  2. An F5 ARX system running release V6.02.000 or later and configured with at least one volume.
  3. Management access on the ARX must be permitted for HTTPs-API or HTTP-API services.

Code :

#!/usr/bin/perl
#-------------------------------------------------------------------------------
# The contents of this file are subject to the "END USER LICENSE AGREEMENT 
# FOR F5 Software Development Kit for iControl"; you may not use this file 
# except in compliance with the License. The License is included in the 
# iControl Software Development Kit.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is iControl Code and related documentation
# distributed by F5.
#
# The Initial Developer of the Original Code is F5 Networks,
# Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2012
# F5 Networks, Inc. All Rights Reserved.  iControl (TM) is a registered 
# trademark of F5 Networks, Inc.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above.  If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#-------------------------------------------------------------------------------
#
# Description
#
# This script is an example of how to use the iControl interfaces provided by
# an ARX to retrieve all volumes and their configuration on an ARX.
#
# Usage: ARXVolumeExample.pl --url  --user  --pass 
#
# Prerequisites:
#
# This script requires the following:
#
#   * SOAP::Lite perl module
#   * An F5 ARX system configured with at least one configured volume.
#   * Management access on the ARX must be permitted for HTTP-API and HTTPS-API
#     services.
#
# For more information on ARX configuration, please consult the
# documentation that was provided with your ARX system.
#-------------------------------------------------------------------------------

# SOAP::Lite lets us send SOAP requests and parse them
use SOAP::Lite
    autotype => 0,
    default_ns => 'urn:iControl';

# If you need to debug problems with your script, you can use the +trace 
# option with SOAP::Lite and it will print the XML sent to and received from
# the server:
#
# use SOAP::Lite
#     autotype => 0,
#     default_ns => 'urn:iControl' + trace;

# Getopt::Long lets us easily parse command line options
use Getopt::Long;

use POSIX qw(strftime);

use Carp;

use strict;
use warnings;

#-------------------------------------------------------------------------------
# Main program logic
#-------------------------------------------------------------------------------

our ($url, $user, $pass);

# Load command line options - if the load fails, then we print the usage
# instructions and exit.
if (!GetOptions("url=s" =>  \$url,
                "user=s" => \$user,
                "pass=s" => \$pass)) {
    usage();
    exit(1);
}

# If any arguments were skipped, print the usage instructions and exit.
if (!defined $url || !defined $user || !defined $pass) {
    usage();
    exit(1);
}

# The service path for interface "Interface" is this:
#
# http://:/api/services/Interface
#
my $namespaceServiceUrl = $url . "/api/services/Namespace";
my $volumeServiceUrl = $url . "/api/services/Volume";

# In order for SOAP to access a web service, it needs to read the WSDL
# for the interface you want to use.  The WSDL file for an interface
# called "Interface" is available via http/https on the ARX at:
#
# http://:/api/services/Interface?wsdl
#
# If you need a WSDL 2.0 version, that is also available at:
#
# http://:/arx-api/wsdl/Interface.wsdl2
#
# In this case, we're using the Volume interface and we're 
# interested in using the WSDL 1.1 version.
#
my $namespaceWsdlUrl = $namespaceServiceUrl . "?wsdl";
my $volumeWsdlUrl = $volumeServiceUrl . "?wsdl";

# Now we build our SOAP::Lite object using the service and WSDL
# URLs
my $namespaceSoap = SOAP::Lite->new(proxy   => $namespaceServiceUrl,
                                    service => $namespaceWsdlUrl);

my $volumeSoap = SOAP::Lite->new(proxy   => $volumeServiceUrl,
                                 service => $volumeWsdlUrl);

# Build a security header 
our $securityHeader = getSecurityHeader($user, $pass);

my $namespaceSoapResult = $namespaceSoap->get_list($securityHeader);

if (defined $namespaceSoapResult->fault && $namespaceSoapResult->fault) {
    confess("SOAP request failed:\n" . objdump($namespaceSoapResult->fault) . "\n");
}

my @namespaceList = ($namespaceSoapResult->result, 
                     $namespaceSoapResult->paramsout);

if ($#namespaceList < 0) {
    print("The list of namespaces returned from the call to the \"get_list\" method of the ARX Namespace interface was empty.\n");
    exit(0);
}

foreach my $namespace (@namespaceList) {
    print "##############################################\n";
    print "Namespace: $namespace\n";
    print "##############################################\n\n";

    print "Calling the \"get_list\" method of the ARX Volume interface on namespace '$namespace'.\n\n";

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    # Get a list of volumes configured on the ARX.
    my $volumeSoapResult = $volumeSoap->get_list(SOAP::Data->name('namespace')->value($namespace), 
                                                 $securityHeader);

    # Check if there were any faults encountered during the operation.
    # We find this by checking if the fault member of the result object
    # is set.  If there is a fault, then we can print the detailed 
    # fault text using the faultstring member of the result object.
    if (defined $volumeSoapResult->fault && $volumeSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($volumeSoapResult->fault) . "\n");
    }

    print "Printing the results of the call to the \"get_list\" method of the ARX Volume interface on namespace '$namespace'.\n\n";

    # The get_list() call did not fail, so we build a list of volume
    # names from the result.  Note that the full result is a
    # concatenation of the result and paramsout members of the SOAP
    # result object.
    my @volumeList = ($volumeSoapResult->result, 
                      $volumeSoapResult->paramsout);

    if ($#volumeList < 0) {
        print("The list of volumes returned from the call to the \"get_list\" method of the ARX Volume interface was empty.\n");
        exit(0);
    }

    # We can now print the list of volumes
    print "Volume list:\n";
    foreach my $volume (@volumeList) {
        print " ", $volume, "\n";
    }
    print "\n";

    print "Calling the \"get_configuration\" method of the ARX Volume interface on namespace '$namespace'.\n\n";

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    # get volume configuration from API

    # In addition to printing the list of volumes, we can actually
    # use that list to retrieve configuration information
    # for all of the volumes using the same list by calling
    # get_configuration().
    $volumeSoapResult = $volumeSoap->get_configuration(SOAP::Data->name('namespace')->value($namespace), 
                                                       SOAP::Data->name('volumes')->value(@volumeList), 
                                                       $securityHeader);

    if (defined $volumeSoapResult->fault && $volumeSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($volumeSoapResult->fault) . "\n");
    }

    print "Printing the results of the call to the \"get_configuration\" method of the ARX Volume interface on namespace '$namespace'.\n\n";

    my @volumeConfigs = ($volumeSoapResult->result, $volumeSoapResult->paramsout);

    foreach my $volumeConfig (@volumeConfigs) {
        my $name = $volumeConfig->{'name'};

        print "----------------------------------------------\n";
        print "Volume: ", $name, "\n";
        print "----------------------------------------------\n\n";

        print "name: ", $name, "\n";

        my $description = $volumeConfig->{'description'};
        print "description: ", $description, "\n";

        my $direct = $volumeConfig->{'direct'};
        print "direct: ", $direct, "\n";

        my $freespace_mode = $volumeConfig->{'freespace_mode'};
        print "freespace_mode: ", $freespace_mode, "\n";

        my $freespace_cifs_quota = $volumeConfig->{'freespace_cifs_quota'};
        print "freespace_cifs_quota: ", $freespace_cifs_quota, "\n";

        my $metadata_critical = $volumeConfig->{'metadata_critical'};
        print "metadata_critical: ", $metadata_critical, "\n";

        if (exists $volumeConfig->{'metadata_shares'}) {
            print "metadata_shares:\n";

            my @metadata_shares = ();

            if (ref($volumeConfig->{'metadata_shares'}) eq "ARRAY") {
                @metadata_shares = @{$volumeConfig->{'metadata_shares'}};
            } else {
                @metadata_shares = $volumeConfig->{'metadata_shares'};
            }

            foreach my $metadata_share (@metadata_shares) {
                my $file_server = $metadata_share->{'file_server'};
                print " file_server: ", $file_server, "\n";

                my $protocol = $metadata_share->{'protocol'};
                print " protocol: ", $protocol, "\n";

                my $share = $metadata_share->{'share'};
                print " share: ", $share, "\n";

                my $cluster = $metadata_share->{'cluster'};
                print " cluster: ", $cluster, "\n";
                print "\n";
            }
        }

        my $modify = $volumeConfig->{'modify'};
        print "modify: ", $modify, "\n";

        my $reimport_modify = $volumeConfig->{'reimport_modify'};
        print "reimport_modify: ", $reimport_modify, "\n";

        my $reserved_files = $volumeConfig->{'reserved_files'};
        print "reserved_files: ", $reserved_files, "\n";

        my $shadow = $volumeConfig->{'shadow'};
        print "shadow: ", $shadow, "\n";

        my $volume_group_id = $volumeConfig->{'volume_group_id'};
        print "volume_group_id: ", $volume_group_id, "\n";

        my $auto_reserve_files = $volumeConfig->{'auto_reserve_files'};
        print "auto_reserve_files: ", $auto_reserve_files, "\n";

        my $auto_sync_files = $volumeConfig->{'auto_sync_files'};
        print "auto_sync_files: ", $auto_sync_files, "\n";

        my $auto_sync_rename_files = $volumeConfig->{'auto_sync_rename_files'};
        print "auto_sync_rename_files: ", $auto_sync_rename_files, "\n";

        my $cifs_access_based_enum = $volumeConfig->{'cifs_access_based_enum'};
        print "cifs_access_based_enum: ", $cifs_access_based_enum, "\n";

        my $cifs_access_based_enum_auto_enable = $volumeConfig->{'cifs_access_based_enum_auto_enable'};
        print "cifs_access_based_enum_auto_enable: ", $cifs_access_based_enum_auto_enable, "\n";

        my $cifs_case_sensitive = $volumeConfig->{'cifs_case_sensitive'};
        print "cifs_case_sensitive: ", $cifs_case_sensitive, "\n";

        my $cifs_compressed_files = $volumeConfig->{'cifs_compressed_files'};
        print "cifs_compressed_files: ", $cifs_compressed_files, "\n";

        my $cifs_deny_symlinks = $volumeConfig->{'cifs_deny_symlinks'};
        print "cifs_deny_symlinks: ", $cifs_deny_symlinks, "\n";

        my $cifs_file_server_subshares = $volumeConfig->{'cifs_file_server_subshares'};
        print "cifs_file_server_subshares: ", $cifs_file_server_subshares, "\n";

        my $cifs_file_server_subshares_native_names_only = $volumeConfig->{'cifs_file_server_subshares_native_names_only'};
        print "cifs_file_server_subshares_native_names_only: ", $cifs_file_server_subshares_native_names_only, "\n";

        my $cifs_file_system_name = $volumeConfig->{'cifs_file_system_name'};
        print "cifs_file_system_name: ", $cifs_file_system_name, "\n";

        my $cifs_named_streams = $volumeConfig->{'cifs_named_streams'};
        print "cifs_named_streams: ", $cifs_named_streams, "\n";

        my $cifs_notify_change_mode = $volumeConfig->{'cifs_notify_change_mode'};
        print "cifs_notify_change_mode: ", $cifs_notify_change_mode, "\n";

        my $cifs_oplocks = $volumeConfig->{'cifs_oplocks'};
        print "cifs_oplocks: ", $cifs_oplocks, "\n";

        my $cifs_path_cache = $volumeConfig->{'cifs_path_cache'};
        print "cifs_path_cache: ", $cifs_path_cache, "\n";

        my $cifs_persistent_acls = $volumeConfig->{'cifs_persistent_acls'};
        print "cifs_persistent_acls: ", $cifs_persistent_acls, "\n";

        my $cifs_sparse_files = $volumeConfig->{'cifs_sparse_files'};
        print "cifs_sparse_files: ", $cifs_sparse_files, "\n";

        my $cifs_unicode_on_disk = $volumeConfig->{'cifs_unicode_on_disk'};
        print "cifs_unicode_on_disk: ", $cifs_unicode_on_disk, "\n";

        my $nfs_rsize = $volumeConfig->{'nfs_rsize'};
        print "nfs_rsize: ", $nfs_rsize, "\n";

        my $nfs_wsize = $volumeConfig->{'nfs_wsize'};
        print "nfs_wsize: ", $nfs_wsize, "\n";

        my $policy_pause_schedule = $volumeConfig->{'policy_pause_schedule'};
        print "policy_pause_schedule: ", $policy_pause_schedule, "\n";

        my $snapshot_consistency = $volumeConfig->{'snapshot_consistency'};
        print "snapshot_consistency: ", $snapshot_consistency, "\n";

        my $snapshot_display = $volumeConfig->{'snapshot_display'};
        print "snapshot_display: ", $snapshot_display, "\n";

        my $snapshot_display_hidden = $volumeConfig->{'snapshot_display_hidden'};
        print "snapshot_display_hidden: ", $snapshot_display_hidden, "\n";

        my $snapshot_directory = $volumeConfig->{'snapshot_directory'};
        print "snapshot_directory: ", $snapshot_directory, "\n";

        my $snapshot_privileged_access = $volumeConfig->{'snapshot_privileged_access'};
        print "snapshot_privileged_access: ", $snapshot_privileged_access, "\n";

        my $snapshot_vss_mode = $volumeConfig->{'snapshot_vss_mode'};
        print "snapshot_vss_mode: ", $snapshot_vss_mode, "\n";

        my $enable = $volumeConfig->{'enable'};
        print "enable: ", $enable, "\n";
        print "\n";
    }

    print "Calling the \"get_status\" method of the ARX Volume interface on namespace '$namespace'.\n\n";

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    # get volume configuration from API

    # In addition to printing the list of volumes, we can actually
    # use that list to retrieve status information for all of the volumes 
    # using the same list by calling get_status().
    $volumeSoapResult = $volumeSoap->get_status(SOAP::Data->name('namespace')->value($namespace), 
                                                SOAP::Data->name('volumes')->value(@volumeList), 
                                                $securityHeader);

    if (defined $volumeSoapResult->fault && $volumeSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($volumeSoapResult->fault) . "\n");
    }

    print "Printing the results of the call to the \"get_status\" method of the ARX Volume interface on namespace '$namespace'.\n\n";

    my @volumeStatuses = ($volumeSoapResult->result, $volumeSoapResult->paramsout);

    foreach my $volumeStatus (@volumeStatuses) {
        my $name = $volumeStatus->{'name'};

        print "----------------------------------------------\n";
        print "Volume: ", $name, "\n";
        print "----------------------------------------------\n\n";

        print "name: ", $name, "\n";

        my $host = $volumeStatus->{'host'};
        print "host: ", $host, "\n";

        my $instance = $volumeStatus->{'instance'};
        print "instance: ", $instance, "\n";

        my $processor = $volumeStatus->{'processor'};
        print "processor: ", $processor, "\n";

        my $state = $volumeStatus->{'state'};
        print "state: ", $state, "\n";

        my $state_detail = $volumeStatus->{'state_detail'};
        print "state_detail: ", $state_detail, "\n";

        my $metadata_size = $volumeStatus->{'metadata_size'};
        print "metadata_size: ", $metadata_size, "\n";

        my $metadata_migrating = $volumeStatus->{'metadata_migrating'};
        print "metadata_migrating: ", $metadata_migrating, "\n";

        if (exists $volumeStatus->{'metadata_share_statuses'}) {
            print "metadata_share_statuses:\n";

            my @metadata_share_statuses = ();

            if (ref($volumeStatus->{'metadata_share_statuses'}) eq "ARRAY") {
                @metadata_share_statuses = @{$volumeStatus->{'metadata_share_statuses'}};
            } else {
                @metadata_share_statuses = $volumeStatus->{'metadata_share_statuses'};
            }

            foreach my $metadata_share_status (@metadata_share_statuses) {
                my $file_server = $metadata_share_status->{'file_server'};
                print " file_server: ", $file_server, "\n";

                my $protocol = $metadata_share_status->{'protocol'};
                print " protocol: ", $protocol, "\n";

                my $share = $metadata_share_status->{'share'};
                print " share: ", $share, "\n";

                my $contains_metadata = $metadata_share_status->{'contains_metadata'};
                print " contains_metadata: ", $contains_metadata, "\n";

                my $available = $metadata_share_status->{'available'};
                print " available: ", $available, "\n";

                my $online = $metadata_share_status->{'online'};
                print " online: ", $online, "\n";

                my $error_detail = $metadata_share_status->{'error_detail'};
                print " error_detail: ", $error_detail, "\n";

                my $free_space = $metadata_share_status->{'free_space'};
                print " free_space: ", $free_space, "\n";

                my $total_space = $metadata_share_status->{'total_space'};
                print " total_space: ", $total_space, "\n";

                my $migrate_source = $metadata_share_status->{'migrate_source'};
                print " migrate_source: ", $migrate_source, "\n";
                print "\n";
            }
        }

        my $free_space = $volumeStatus->{'free_space'};
        print "free_space: ", $free_space, "\n";

        my $total_space = $volumeStatus->{'total_space'};
        print "total_space: ", $total_space, "\n";

        my $used_files = $volumeStatus->{'used_files'};
        print "used_files: ", $used_files, "\n";

        my $used_dirs = $volumeStatus->{'used_dirs'};
        print "used_dirs: ", $used_dirs, "\n";

        my $free_files = $volumeStatus->{'free_files'};
        print "free_files: ", $free_files, "\n";

        my $max_files = $volumeStatus->{'max_files'};
        print "max_files: ", $max_files, "\n";
        print "\n";
    }
}

#-------------------------------------------------------------------------------
# End of main program logic
#-------------------------------------------------------------------------------


#-------------------------------------------------------------------------------
# sub usage
#-------------------------------------------------------------------------------
sub usage
{
    print "\nUsage: ARXVolumeExample.pl --url  --user  --pass \n";
    print "\n";
    print "Argument  Description\n";
    print "--------  -----------\n";
    print "--url     The base URL of the web service on the ARX. Both http and https\n";
    print "          are supported. The format is:\n";
    print "\n";
    print "          http(s)://:\n";
    print "\n";
    print "          : DNS resolvable hostname or IP address\n";
    print "          :     83 for http or 843 for https\n";
    print "\n";
    print "--user    The username for authentication.\n";
    print "--pass    The password for authentication.\n";
    print "\n";
}

#-------------------------------------------------------------------------------
# sub getSecurityHeader(user, pass)
#
# This subroutine builds a security header that will be used for
# authentication.  This type of security header is required for all calls to
# iControl::ARX interfaces, so it makes sense to have this subroutine stored in
# a library for common access.
#-------------------------------------------------------------------------------
sub getSecurityHeader
{
    my $user = shift;
    my $pass = shift;
    my $now = time();
    my $then = time() + 60;
    my $created = strftime("%Y-%m-%dT%H:%M:%S", gmtime($now)) . 'Z';
    my $expires = strftime("%Y-%m-%dT%H:%M:%S", gmtime($then)) . 'Z';

    my $secExt = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
    my $secUtil = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
    my $securityHeader = SOAP::Header->name("wsse:Security")->attr(
            {
                'xmlns:wsse'=> $secExt,
                'xmlns:wsu'=> $secUtil
            }
    );
    my $timestamp = SOAP::Data->name("wsu:Timestamp" =>
                            \SOAP::Data->value(
                                SOAP::Data->name('wsu:Created')->value($created)
                                                               ->type(''),
                                SOAP::Data->name('wsu:Expires')->value($expires)
                                                               ->type('')));
    my $usernameTokenType = 
        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
    my $usernameToken = SOAP::Data->name("wsse:UsernameToken" =>
                            \SOAP::Data->value(
                                SOAP::Data->name('wsse:Username')->value($user)
                                                                 ->type(''),
                                SOAP::Data->name('wsse:Password')->value($pass)
                                                                 ->type('')
                                                                 ->attr({'Type'=>$usernameTokenType})));

    $securityHeader->value(\SOAP::Data->value($timestamp, $usernameToken));

    return $securityHeader;
}

sub objdump
{
    my ($obj, $indent) = @_;
    my $content = '';

    if (!defined $obj) {
        return $content;
    }

    if (!defined $indent) {
        $indent = '    ';
    }

    my $type = ref $obj;

    if (!defined $type || $type eq '' || $type eq 'SCALAR') {
        $content = $content . $indent . $obj . "\n";
    }
    elsif ($type eq 'ARRAY') {
        foreach my $node (@$obj) {
            $content = $content . objdump($node, $indent);
        }
    }
    else {
        my $key;
        my $value;

        while (($key, $value) = each %$obj) {
            my $type2 = ref $value;
            if (!defined $type2 || $type2 eq '' || $type2 eq 'SCALAR') {
                $content = $content . $indent . "\'$key\' => $value;\n";
            }
            else {
                $content = $content . $indent . "\'$key\' => {\n";
                $content = $content . objdump($value, $indent.'    ');
                $content = $content . $indent . "}\n";
            }
        }
    }

    return $content;
}
Updated Jun 06, 2023
Version 2.0

Was this article helpful?

No CommentsBe the first to comment