Perl ARX ManualMigrateRule

Problem this snippet solves:

This script is an example of how to use the iControl interfaces provided by an ARX to use manual migration rule to migrate files on an ARX.

How to use this snippet:

ARXManualMigrateRuleExample.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 manual migrate rule.
  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 use manual migration rule to migrate files on an ARX.
#
# Usage: ARXManualMigrateRuleExample.pl --url  --user  --pass  --op 
#
# Prerequisites:
#
# This script requires the following:
#
#   * SOAP::Lite perl module
#   * An F5 ARX system configured with at least one configured manual migrate rule.
#   * 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, $op);

# 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,
                "op=s" => \$op)) {
    usage();
    exit(1);
}

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

# The service path for interface "Interface" is this:
#
# http://:/api/services/Interface
#
my $manualMigrateRuleServiceUrl = $url . "/api/services/ManualMigrateRule";

# 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 ManualMigrateRule interface and we're 
# interested in using the WSDL 1.1 version.
#
my $manualMigrateRuleWsdlUrl = $manualMigrateRuleServiceUrl . "?wsdl";

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

print "Please specify a namespace:\n\n";
chomp(my $namespace = <>);
print "\n";

print "Please specify a volume:\n\n";
chomp(my $volume = <>);
print "\n";

if ($op eq "get_list")
{
    get_list($namespace, $volume);
}
elsif ($op eq "get_configuration")
{
    get_configuration($namespace, $volume);
}
elsif ($op eq "get_status")
{
    get_status($namespace, $volume);
}
elsif ($op eq "create")
{
    create($namespace, $volume);
}
elsif ($op eq "set_migrate_close_file")
{
    set_migrate_close_file($namespace, $volume);
}

elsif ($op eq "set_report")
{
    set_report($namespace, $volume);
}
elsif ($op eq "set_enable")
{
    set_enable($namespace, $volume);
}
elsif ($op eq "create_and_configure")
{
    create_and_configure($namespace, $volume);
}
elsif ($op eq "remove")
{
    remove($namespace, $volume);
}
elsif ($op eq "migrate_files")
{
    migrate_files($namespace, $volume);
}


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


#-------------------------------------------------------------------------------
# sub usage
#-------------------------------------------------------------------------------
sub usage
{
    print "\nUsage: ARXManualMigrateRuleExample.pl --url  --user  --pass  --op \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";
    print "--op      The ARXManualMigrateRule API method that will be called:\n";
    print "\n";
    print "          create\n";
    print "          create_and_configure\n";
    print "          set_migrate_close_file\n";
    print "          set_report\n";
    print "          set_enable\n";
    print "          get_list\n";
    print "          get_configuration\n";
    print "          get_status\n";
    print "          migrate_files\n";
    print "          remove\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 create
{
    my ($namespace, $volume) = @_;

    print "Please specify a rule name:\n\n";
    chomp(my $manualMigrateRule = <>);
    print "\n";

    print "Calling the \"create\" method of the ARX ManualMigrateRule interface with the following parameters:\n\n";
    print "namespace: $namespace\n";
    print "volume: $volume\n";
    print "rule: $manualMigrateRule\n\n";

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

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->create(SOAP::Data->name('namespace')->value($namespace), 
                                                                     SOAP::Data->name('volume')->value($volume), 
                                                                     SOAP::Data->name('rule')->value($manualMigrateRule), 
                                                                     $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 $manualMigrateRuleSoapResult->fault && $manualMigrateRuleSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($manualMigrateRuleSoapResult->fault) . "\n");
    }
}

sub create_and_configure
{
    my ($namespace, $volume) = @_;

    print "Please specify a rule name:\n\n";
    chomp(my $manualMigrateRule = <>);
    print "\n";

    print "Please specify a report prefix:\n\n";
    chomp(my $prefix = <>);
    print "\n";

    print "Please specify either 'true' or 'false' for 'verbose':\n\n";
    chomp(my $verbose = <>);
    print "\n";

    print "Please specify either 'ARX_POLICY_REPORT_DELETE_UNKNOWN', 'ARX_POLICY_REPORT_DELETE_EMPTY', or  'ARX_POLICY_REPORT_ERROR_ONLY' for 'delete_report':\n\n";
    chomp(my $delete_report = <>);
    print "\n";

    print "Please specify either 'ARX_POLICY_REPORT_INTERVAL_UNKNOWN', 'ARX_POLICY_REPORT_INTERVAL_HOURLY', or  'ARX_POLICY_REPORT_INTERVAL_DAILY' for 'interval':\n\n";
    chomp(my $interval = <>);
    print "\n";

    print "Please specify either 'true' or 'false' for 'migrate_close_file':\n\n";
    chomp(my $migrateCloseFileValue = <>);
    print "\n";

    print "Please specify files to be included in the 'exclude_file_set':\n\n";
    chomp(my $excludeFileSetValue = <>);
    print "\n";

    print "Please specify either 'true' or 'false' for 'enable':\n\n";
    chomp(my $enable = <>);
    print "\n";

    if ($migrateCloseFileValue ne "true" && $migrateCloseFileValue ne "false") {
        confess("migrate_close_file value must be either 'true' or 'false'.\n");
    }

    my $baseReport = SOAP::Data->name('report' => \SOAP::Data->value(SOAP::Data->name('prefix' => $prefix), 
                                                   SOAP::Data->name('verbose' => $verbose), 
                                                   SOAP::Data->name('delete_report' => $delete_report)));

    my $intervalReport = SOAP::Data->name('report' => \SOAP::Data->value(SOAP::Data->name('interval' => $interval), $baseReport));

    my $migrateCloseFile = SOAP::Data->name('migrate_close_file' => \SOAP::Data->value(SOAP::Data->name('migrate_close_file' => $migrateCloseFileValue), 
                                                                                       SOAP::Data->name('exclude_file_set' => $excludeFileSetValue)));

    my $configuration = SOAP::Data->name('configuration' => \SOAP::Data->value(SOAP::Data->name('rule_name' => $manualMigrateRule), 
                                                                               SOAP::Data->name('enable' => $enable), 
                                                                               SOAP::Data->name('report' => $intervalReport), 
                                                                               $migrateCloseFile));

    print "Calling the \"create_and_configure\" method of the ARX ManualMigrateRule interface with the following parameters:\n\n";
    print "namespace: $namespace\n";
    print "volume: $volume\n";
    print "rule_name: $manualMigrateRule\n";
    print "enable: $enable\n";
    print "report:\n";
    print " interval: $interval\n";
    print " report: \n";
    print "  prefix: $prefix\n";
    print "  verbose: $verbose\n";
    print "  delete_report: $delete_report\n";
    print "migrate_close_file:\n";
    print " migrate_close_file: $migrateCloseFileValue\n";
    print " exclude_file_set: $excludeFileSetValue\n\n";

    my $securityHeader = getSecurityHeader($user, $pass);

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->create_and_configure(SOAP::Data->name('namespace')->value($namespace), 
                                                                                   SOAP::Data->name('volume')->value($volume), 
                                                                                   $configuration, 
                                                                                   $securityHeader);

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

sub set_migrate_close_file
{
    my ($namespace, $volume) = @_;

    print "Please specify a rule name:\n\n";
    chomp(my $manualMigrateRule = <>);
    print "\n";

    print "Please specify either 'true' or 'false' for 'migrate_close_file':\n\n";
    chomp(my $migrateCloseFileValue = <>);
    print "\n";

    print "Please specify files to be included in the 'exclude_file_set':\n\n";
    chomp(my $excludeFileSetValue = <>);
    print "\n";

    if ($migrateCloseFileValue ne "true" && $migrateCloseFileValue ne "false") {
        confess("migrate_close_file value must be either 'true' or 'false'.\n");
    }

    my $migrateCloseFile = SOAP::Data->name('migrate_close_file' => \SOAP::Data->value(SOAP::Data->name('migrate_close_file' => $migrateCloseFileValue), 
                                                                                       SOAP::Data->name('exclude_file_set' => $excludeFileSetValue)));

    print "Calling the \"set_migrate_close_file\" method of the ARX ManualMigrateRule interface with the following parameters:\n\n";
    print "namespace: $namespace\n";
    print "volume: $volume\n";
    print "rule: $manualMigrateRule\n";
    print "migrate_close_file:\n";
    print " migrate_close_file: $migrateCloseFileValue\n";
    print " exclude_file_set: $excludeFileSetValue\n\n";

    my $securityHeader = getSecurityHeader($user, $pass);

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->set_migrate_close_file(SOAP::Data->name('namespace')->value($namespace), 
                                                                                     SOAP::Data->name('volume')->value($volume), 
                                                                                     SOAP::Data->name('rule')->value($manualMigrateRule), 
                                                                                     $migrateCloseFile, 
                                                                                     $securityHeader);

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

sub set_report
{
    my ($namespace, $volume) = @_;

    print "Please specify a rule name:\n\n";
    chomp(my $manualMigrateRule = <>);
    print "\n";

    print "Please specify a report prefix:\n\n";
    chomp(my $prefix = <>);
    print "\n";

    print "Please specify either 'true' or 'false' for 'verbose':\n\n";
    chomp(my $verbose = <>);
    print "\n";

    print "Please specify either 'ARX_POLICY_REPORT_DELETE_UNKNOWN', 'ARX_POLICY_REPORT_DELETE_EMPTY', or  'ARX_POLICY_REPORT_ERROR_ONLY' for 'delete_report':\n\n";
    chomp(my $delete_report = <>);
    print "\n";

    print "Please specify either 'ARX_POLICY_REPORT_INTERVAL_UNKNOWN', 'ARX_POLICY_REPORT_INTERVAL_HOURLY', or  'ARX_POLICY_REPORT_INTERVAL_DAILY' for 'interval':\n\n";
    chomp(my $interval = <>);
    print "\n";

    my $baseReport = SOAP::Data->name('report' => \SOAP::Data->value(SOAP::Data->name('prefix' => $prefix), 
                                                   SOAP::Data->name('verbose' => $verbose), 
                                                   SOAP::Data->name('delete_report' => $delete_report)));

    my $intervalReport = SOAP::Data->name('report' => \SOAP::Data->value(SOAP::Data->name('interval' => $interval), $baseReport));

    print "Calling the \"set_report\" method of the ARX ManualMigrateRule interface with the following parameters:\n\n";
    print "namespace: $namespace\n";
    print "volume: $volume\n";
    print "rule: $manualMigrateRule\n";
    print "report:\n";
    print " interval: $interval\n";
    print " report: \n";
    print "  prefix: $prefix\n";
    print "  verbose: $verbose\n";
    print "  delete_report: $delete_report\n\n";

    my $securityHeader = getSecurityHeader($user, $pass);

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->set_report(SOAP::Data->name('namespace')->value($namespace), 
                                                                         SOAP::Data->name('volume')->value($volume), 
                                                                         SOAP::Data->name('rule')->value($manualMigrateRule), 
                                                                         $intervalReport, 
                                                                         $securityHeader);

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

sub set_enable
{
    my ($namespace, $volume) = @_;

    print "Please specify a rule name:\n\n";
    chomp(my $manualMigrateRule = <>);
    print "\n";

    print "Please specify either 'true' or 'false' for 'enable':\n\n";
    chomp(my $enable = <>);
    print "\n";

    print "Calling the \"set_enable\" method of the ARX ManualMigrateRule interface with the following parameters:\n\n";
    print "namespace: $namespace\n";
    print "volume: $volume\n";
    print "rule: $manualMigrateRule\n";
    print "enable: $enable\n\n";

    my $securityHeader = getSecurityHeader($user, $pass);

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->set_enable(SOAP::Data->name('namespace')->value($namespace), 
                                                                         SOAP::Data->name('volume')->value($volume), 
                                                                         SOAP::Data->name('rule')->value($manualMigrateRule), 
                                                                         SOAP::Data->name('enable' => $enable), 
                                                                         $securityHeader);

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

sub get_list
{
    my ($namespace, $volume) = @_;

    # Get a list of manual migrate rules configured on the ARX.
    print "Calling the \"get_list\" method of the ARX ManualMigrateRule interface.\n\n";

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

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->get_list(SOAP::Data->name('namespace')->value($namespace), 
                                                                       SOAP::Data->name('volume')->value($volume), 
                                                                       $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 $manualMigrateRuleSoapResult->fault && $manualMigrateRuleSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($manualMigrateRuleSoapResult->fault) . "\n");
    }

    print "Printing the results of the call to the \"get_list\" method of the ARX ManualMigrateRule interface.\n\n";

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

    if ($#manualMigrateRuleList < 0) {
        print("The list of manual migrate rules returned from the call to the \"get_list\" method of the ARX ManualMigrateRule interface was empty.\n");
        exit(0);
    }

    # We can now print the list of manual migrate rules
    print "Manual Migrate Rule list:\n";
    foreach my $mmr (@manualMigrateRuleList) {
        print " ", $mmr, "\n";
    }
}

sub get_configuration
{
    my ($namespace, $volume) = @_;

    # Get a list of manual migrate rules configured on the ARX.

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

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->get_list(SOAP::Data->name('namespace')->value($namespace), 
                                                                       SOAP::Data->name('volume')->value($volume), 
                                                                       $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 $manualMigrateRuleSoapResult->fault && $manualMigrateRuleSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($manualMigrateRuleSoapResult->fault) . "\n");
    }

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

    if ($#manualMigrateRuleList < 0) {
        print("The list of manual migrate rules returned from the call to the \"get_list\" method of the ARX ManualMigrateRule interface was empty.\n");
        exit(0);
    }

    # get manual migrate rule configuration from API
    print "Calling the \"get_configuration\" method of the ARX ManualMigrateRule interface.\n\n";

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

    # In addition to printing the list of manual migrate rules, we can actually
    # use that list to retrieve configuration information
    # for all of the manual migrate rules using the same list by calling
    # get_configuration().
    $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->get_configuration(SOAP::Data->name('namespace')->value($namespace), 
                                                                             SOAP::Data->name('volume')->value($volume), 
                                                                             SOAP::Data->name('rules')->value(@manualMigrateRuleList), 
                                                                             $securityHeader);

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

    print "Printing the results of the call to the \"get_configuration\" method of the ARX ManualMigrateRule interface.\n\n";

    my @manualMigrateRuleConfigs = ($manualMigrateRuleSoapResult->result, $manualMigrateRuleSoapResult->paramsout);

    foreach my $manualMigrateRuleConfig (@manualMigrateRuleConfigs) {
        my $rule_name = $manualMigrateRuleConfig->{'rule_name'};

        print "----------------------------------------------\n";
        print "Manual Migrate Rule: ", $rule_name, "\n";
        print "----------------------------------------------\n\n";

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

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

        if (exists $manualMigrateRuleConfig->{'report'}) {
            my $interval_report_config = $manualMigrateRuleConfig->{'report'};
            print "report:\n";

            my $interval = $interval_report_config->{'interval'};
            print " interval: ", $interval, "\n";

            if (exists $interval_report_config->{'report'}) {
                my $base_report_config = $interval_report_config->{'report'};
                print " report:\n";

                my $prefix = $base_report_config->{'prefix'};
                print "  prefix: ", $prefix, "\n";

                my $verbose = $base_report_config->{'verbose'};
                print "  verbose: ", $verbose, "\n";

                my $delete_report = $base_report_config->{'delete_report'};
                print "  delete_report: ", $delete_report, "\n";
            }
        }

        if (exists $manualMigrateRuleConfig->{'migrate_close_file'}) {
            my $migrate_close_file_config = $manualMigrateRuleConfig->{'migrate_close_file'};
            print "migrate_close_file:\n";

            my $migrate_close_file = $migrate_close_file_config->{'migrate_close_file'};
            print " migrate_close_file: ", $migrate_close_file, "\n";

            my $exclude_file_set = $migrate_close_file_config->{'exclude_file_set'};
            print " exclude_file_set: ", $exclude_file_set, "\n";
        }

        print "\n";
    }
}

sub get_status
{
    my ($namespace, $volume) = @_;

    # Get a list of manual migrate rules configured on the ARX.

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

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->get_list(SOAP::Data->name('namespace')->value($namespace), 
                                                                       SOAP::Data->name('volume')->value($volume), 
                                                                       $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 $manualMigrateRuleSoapResult->fault && $manualMigrateRuleSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($manualMigrateRuleSoapResult->fault) . "\n");
    }

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

    if ($#manualMigrateRuleList < 0) {
        print("The list of manual migrate rules returned from the call to the \"get_list\" method of the ARX ManualMigrateRule interface was empty.\n");
        exit(0);
    }

    # get manual migrate rule status from API
    print "Calling the \"get_status\" method of the ARX ManualMigrateRule interface.\n\n";

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

    # 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().
    $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->get_status(SOAP::Data->name('namespace')->value($namespace), 
            SOAP::Data->name('volume')->value($volume), 
            SOAP::Data->name('rules')->value(@manualMigrateRuleList), 
            $securityHeader);

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

    print "Printing the results of the call to the \"get_status\" method of the ARX ManualMigrateRule interface.\n\n";

    my @manualMigrateRuleStatuses = ($manualMigrateRuleSoapResult->result, $manualMigrateRuleSoapResult->paramsout);

    foreach my $manualMigrateRuleStatus (@manualMigrateRuleStatuses) {
        my $mmr_status_rule_name = $manualMigrateRuleStatus->{'rule_name'};

        print "----------------------------------------------\n";
        print "Manual Migrate Rule: ", $mmr_status_rule_name, "\n";
        print "----------------------------------------------\n\n";

        print "rule_name: ", $mmr_status_rule_name, "\n";

        my $available_request_slots = $manualMigrateRuleStatus->{'available_request_slots'};
        print "available_request_slots: ", $available_request_slots, "\n";

    }
}

sub migrate_files
{
    my ($namespace, $volume) = @_;

    print "Please specify a rule name:\n\n";
    chomp(my $manualMigrateRule = <>);
    print "\n";

    print "Please specify a file list:\n\n";
    chomp(my $fileList = <>);
    my @fileListArray = ($fileList);
    print "\n";

    print "Please specify a target share (hit  to specify a target share farm instead):\n\n";
    chomp(my $share = <>);
    print "\n";

    print "Please specify a target share farm (hit  if a target share was previously specified):\n\n";
    chomp(my $shareFarm = <>);
    print "\n";

    print "Calling the \"migrate_files\" method of the ARX ManualMigrateRule interface with the following parameters:\n\n";
    print "namespace: $namespace\n";
    print "volume: $volume\n";
    print "rule: $manualMigrateRule\n";
    print "files: $fileList\n";
    print "share: $share\n";
    print "share_farm: $shareFarm\n\n";

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

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->migrate_files(SOAP::Data->name('namespace')->value($namespace), 
                                                                            SOAP::Data->name('volume')->value($volume), 
                                                                            SOAP::Data->name('rule')->value($manualMigrateRule), 
                                                                            SOAP::Data->name('files')->value(@fileListArray), 
                                                                            SOAP::Data->name('share')->value($share), 
                                                                            SOAP::Data->name('share_farm')->value($shareFarm), 
                                                                            $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 $manualMigrateRuleSoapResult->fault && $manualMigrateRuleSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($manualMigrateRuleSoapResult->fault) . "\n");
    }
}

sub remove
{
    my ($namespace, $volume) = @_;

    print "Please specify a rule name:\n\n";
    chomp(my $manualMigrateRule = <>);
    print "\n";

    print "Calling the \"remove\" method of the ARX ManualMigrateRule interface with the following parameters:\n\n";
    print "namespace: $namespace\n";
    print "volume: $volume\n";
    print "rule: $manualMigrateRule\n\n";

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

    my $manualMigrateRuleSoapResult = $manualMigrateRuleSoap->remove(SOAP::Data->name('namespace')->value($namespace), 
                                                                     SOAP::Data->name('volume')->value($volume), 
                                                                     SOAP::Data->name('rule')->value($manualMigrateRule), 
                                                                     $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 $manualMigrateRuleSoapResult->fault && $manualMigrateRuleSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($manualMigrateRuleSoapResult->fault) . "\n");
    }
}

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 3.0
No CommentsBe the first to comment