perl
87 TopicsPerl 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 SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later and configured with at least one manual migrate rule. 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; }306Views0likes0CommentsPerl ARX Network
Problem this snippet solves: This script is an example of how to use the iControl interfaces provided by an ARX to retrieve all networks and their configurations, statuses and statistics on an ARX. How to use this snippet: ARXNetworkExample.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later and configured with at least one configured network. 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 networks and their configurations, statuses and # statistics on an ARX. # # Usage: ARXNetworkExample.pl --url --user --pass # # Prerequisites: # # This script requires the following: # # * SOAP::Lite perl module # * An F5 ARX system configured with at least one configured network. # * 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 $networkServiceUrl = $url . "/api/services/Network"; # 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 Network interface and we're # interested in using the WSDL 1.1 version. # my $networkWsdlUrl = $networkServiceUrl . "?wsdl"; # Now we build our SOAP::Lite object using the service and WSDL # URLs my $networkSoap = SOAP::Lite->new(proxy => $networkServiceUrl, service => $networkWsdlUrl); #------------------------------------------------------------------------------- # get_list #------------------------------------------------------------------------------- my @networkList = (); print "Calling the \"get_list\" method of the ARX Network interface.\n\n"; # Build a security header our $securityHeader = getSecurityHeader($user, $pass); my $networkSoapResult = $networkSoap->get_list($securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_list\" method of the ARX Network interface.\n\n"; @networkList = ($networkSoapResult->result, $networkSoapResult->paramsout); if ($#networkList < 0) { print("The list of networks returned from the call to the \"get_list\" method of the ARX Network interface was empty.\n"); } else { print "Networks:\n"; foreach my $network (@networkList) { print "$network\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_stats #------------------------------------------------------------------------------- print "Calling the \"get_stats\" method of the ARX Network interface.\n\n"; if ($#networkList < 0) { print("The list of networks returned from the call to the \"get_list\" method of the ARX Network interface was empty.\n"); } else { # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_stats(SOAP::Data->name('interface_ids')->value(@networkList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_stats\" method of the ARX Network interface.\n\n"; my @networkStats = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $networkStat (@networkStats) { my $id = $networkStat->{'id'}; print "----------------------------------------------\n"; print "Network: ", $id, "\n"; print "----------------------------------------------\n\n"; print "id: ", $id, "\n"; my $collisions = $networkStat->{'collisions'}; print "collisions: ", $collisions, "\n"; my $crc_errors = $networkStat->{'crc_errors'}; print "crc_errors: ", $crc_errors, "\n"; my $discarded = $networkStat->{'discarded'}; print "discarded: ", $discarded, "\n"; my $rx_broadcast = $networkStat->{'rx_broadcast'}; print "rx_broadcast: ", $rx_broadcast, "\n"; my $rx_multicast = $networkStat->{'rx_multicast'}; print "rx_multicast: ", $rx_multicast, "\n"; my $rx_octets = $networkStat->{'rx_octets'}; print "rx_octets: ", $rx_octets, "\n"; my $rx_total = $networkStat->{'rx_total'}; print "rx_total: ", $rx_total, "\n"; my $rx_unicast = $networkStat->{'rx_unicast'}; print "rx_unicast: ", $rx_unicast, "\n"; my $tx_broadcast = $networkStat->{'tx_broadcast'}; print "tx_broadcast: ", $tx_broadcast, "\n"; my $tx_multicast = $networkStat->{'tx_multicast'}; print "tx_multicast: ", $tx_multicast, "\n"; my $tx_octets = $networkStat->{'tx_octets'}; print "tx_octets: ", $tx_octets, "\n"; my $tx_total = $networkStat->{'tx_total'}; print "tx_total: ", $tx_total, "\n"; my $tx_unicast = $networkStat->{'tx_unicast'}; print "tx_unicast: ", $tx_unicast, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_gigabit_interface_list #------------------------------------------------------------------------------- my @gigabitNetworkList = (); print "Calling the \"get_gigabit_interface_list\" method of the ARX Network interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_gigabit_interface_list($securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_gigabit_interface_list\" method of the ARX Network interface.\n\n"; @gigabitNetworkList = ($networkSoapResult->result, $networkSoapResult->paramsout); if ($#gigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_gigabit_interface_list\" method of the ARX Network interface was empty.\n"); } else { print "Gigabit Network Ports:\n"; foreach my $gigabitNetworkPort (@gigabitNetworkList) { my $slot = $gigabitNetworkPort->{'slot'}; print "slot: ", $slot, "\n"; my $port = $gigabitNetworkPort->{'port'}; print "port: ", $port, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_gigabit_interface_configuration #------------------------------------------------------------------------------- print "Calling the \"get_gigabit_interface_configuration\" method of the ARX Network interface.\n\n"; if ($#gigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_gigabit_interface_list\" method of the ARX Network interface was empty.\n"); } else { my @soapGigabitNetworkList = ConvertNetworkPortToSoapData(\@gigabitNetworkList); # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_gigabit_interface_configuration(SOAP::Data->name('ports')->value(@soapGigabitNetworkList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_gigabit_interface_configuration\" method of the ARX Network interface.\n\n"; my @gigabitInterfaceConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $gigabitInterfaceConfig (@gigabitInterfaceConfigs) { if (exists $gigabitInterfaceConfig->{'port'}) { my $gigabitInterfacePort = $gigabitInterfaceConfig->{'port'}; my $slot = $gigabitInterfacePort->{'slot'}; my $port = $gigabitInterfacePort->{'port'}; print "----------------------------------------------\n"; print "Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $description = $gigabitInterfaceConfig->{'description'}; print "description: ", $description, "\n"; my $flow_control_receive = $gigabitInterfaceConfig->{'flow_control_receive'}; print "flow_control_receive: ", $flow_control_receive, "\n"; my $flow_control_send = $gigabitInterfaceConfig->{'flow_control_send'}; print "flow_control_send: ", $flow_control_send, "\n"; my $redundancy_protocol = $gigabitInterfaceConfig->{'redundancy_protocol'}; print "redundancy_protocol: ", $redundancy_protocol, "\n"; my $speed = $gigabitInterfaceConfig->{'speed'}; print "speed: ", $speed, "\n"; my $enable = $gigabitInterfaceConfig->{'enable'}; print "enable: ", $enable, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_gigabit_interface_status #------------------------------------------------------------------------------- print "Calling the \"get_gigabit_interface_status\" method of the ARX Network interface.\n\n"; if ($#gigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_gigabit_interface_list\" method of the ARX Network interface was empty.\n"); } else { my @soapGigabitNetworkList = ConvertNetworkPortToSoapData(\@gigabitNetworkList); # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_gigabit_interface_status(SOAP::Data->name('ports')->value(@soapGigabitNetworkList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_gigabit_interface_status\" method of the ARX Network interface.\n\n"; my @gigabitInterfaceStatuses = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $gigabitInterfaceStatus (@gigabitInterfaceStatuses) { if (exists $gigabitInterfaceStatus->{'port'}) { my $gigabitInterfacePort = $gigabitInterfaceStatus->{'port'}; my $slot = $gigabitInterfacePort->{'slot'}; my $port = $gigabitInterfacePort->{'port'}; print "----------------------------------------------\n"; print "Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $type = $gigabitInterfaceStatus->{'type'}; print "type: ", $type, "\n"; my $mode = $gigabitInterfaceStatus->{'mode'}; print "mode: ", $mode, "\n"; my $enabled = $gigabitInterfaceStatus->{'enabled'}; print "enabled: ", $enabled, "\n"; my $link_status = $gigabitInterfaceStatus->{'link_status'}; print "link_status: ", $link_status, "\n"; my $speed = $gigabitInterfaceStatus->{'speed'}; print "speed: ", $speed, "\n"; my $mac = $gigabitInterfaceStatus->{'mac'}; print "mac: ", $mac, "\n"; my $accept_all_frame = $gigabitInterfaceStatus->{'accept_all_frame'}; print "accept_all_frame: ", $accept_all_frame, "\n"; my $mtu_size = $gigabitInterfaceStatus->{'mtu_size'}; print "mtu_size: ", $mtu_size, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_ten_gigabit_interface_list #------------------------------------------------------------------------------- my @tenGigabitNetworkList = (); print "Calling the \"get_ten_gigabit_interface_list\" method of the ARX Network interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_ten_gigabit_interface_list($securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface.\n\n"; @tenGigabitNetworkList = ($networkSoapResult->result, $networkSoapResult->paramsout); if ($#tenGigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface was empty.\n"); } else { print "Ten Gigabit Network Ports:\n"; foreach my $tenGigabitNetworkPort (@tenGigabitNetworkList) { my $slot = $tenGigabitNetworkPort->{'slot'}; print "slot: ", $slot, "\n"; my $port = $tenGigabitNetworkPort->{'port'}; print "port: ", $port, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_ten_gigabit_interface_configuration #------------------------------------------------------------------------------- print "Calling the \"get_ten_gigabit_interface_configuration\" method of the ARX Network interface.\n\n"; if ($#tenGigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface was empty.\n"); } else { my @soapTenGigabitNetworkList = ConvertNetworkPortToSoapData(\@tenGigabitNetworkList); # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_ten_gigabit_interface_configuration(SOAP::Data->name('ports')->value(@soapTenGigabitNetworkList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ten_gigabit_interface_configuration\" method of the ARX Network interface.\n\n"; my @tenGigabitInterfaceConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $tenGigabitInterfaceConfig (@tenGigabitInterfaceConfigs) { if (exists $tenGigabitInterfaceConfig->{'port'}) { my $tenGigabitInterfacePort = $tenGigabitInterfaceConfig->{'port'}; my $slot = $tenGigabitInterfacePort->{'slot'}; my $port = $tenGigabitInterfacePort->{'port'}; print "----------------------------------------------\n"; print "Ten Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $description = $tenGigabitInterfaceConfig->{'description'}; print "description: ", $description, "\n"; my $flow_control_receive = $tenGigabitInterfaceConfig->{'flow_control_receive'}; print "flow_control_receive: ", $flow_control_receive, "\n"; my $flow_control_send = $tenGigabitInterfaceConfig->{'flow_control_send'}; print "flow_control_send: ", $flow_control_send, "\n"; my $redundancy_protocol = $tenGigabitInterfaceConfig->{'redundancy_protocol'}; print "redundancy_protocol: ", $redundancy_protocol, "\n"; my $enable = $tenGigabitInterfaceConfig->{'enable'}; print "enable: ", $enable, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_ten_gigabit_interface_status #------------------------------------------------------------------------------- print "Calling the \"get_ten_gigabit_interface_status\" method of the ARX Network interface.\n\n"; if ($#tenGigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface was empty.\n"); } else { my @soapTenGigabitNetworkList = ConvertNetworkPortToSoapData(\@tenGigabitNetworkList); # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_ten_gigabit_interface_status(SOAP::Data->name('ports')->value(@soapTenGigabitNetworkList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ten_gigabit_interface_status\" method of the ARX Network interface.\n\n"; my @tenGigabitInterfaceStatuses = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $tenGigabitInterfaceStatus (@tenGigabitInterfaceStatuses) { if (exists $tenGigabitInterfaceStatus->{'port'}) { my $tenGigabitInterfacePort = $tenGigabitInterfaceStatus->{'port'}; my $slot = $tenGigabitInterfacePort->{'slot'}; my $port = $tenGigabitInterfacePort->{'port'}; print "----------------------------------------------\n"; print "Ten Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $type = $tenGigabitInterfaceStatus->{'type'}; print "type: ", $type, "\n"; my $mode = $tenGigabitInterfaceStatus->{'mode'}; print "mode: ", $mode, "\n"; my $enabled = $tenGigabitInterfaceStatus->{'enabled'}; print "enabled: ", $enabled, "\n"; my $link_status = $tenGigabitInterfaceStatus->{'link_status'}; print "link_status: ", $link_status, "\n"; my $speed = $tenGigabitInterfaceStatus->{'speed'}; print "speed: ", $speed, "\n"; my $mac = $tenGigabitInterfaceStatus->{'mac'}; print "mac: ", $mac, "\n"; my $accept_all_frame = $tenGigabitInterfaceStatus->{'accept_all_frame'}; print "accept_all_frame: ", $accept_all_frame, "\n"; my $mtu_size = $tenGigabitInterfaceStatus->{'mtu_size'}; print "mtu_size: ", $mtu_size, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_interface_spanning_tree_configuration #------------------------------------------------------------------------------- print "Calling the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n"; if ($#gigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface was empty.\n"); } else { my @soapGigabitNetworkList = ConvertNetworkPortToSoapData(\@gigabitNetworkList); # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_interface_spanning_tree_configuration(SOAP::Data->name('ports')->value(@soapGigabitNetworkList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n"; my @networkIfSpanningTreeConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $networkIfSpanningTreeConfig (@networkIfSpanningTreeConfigs) { if (exists $networkIfSpanningTreeConfig->{'port'}) { my $networkIfSpanningTreePort = $networkIfSpanningTreeConfig->{'port'}; my $slot = $networkIfSpanningTreePort->{'slot'}; my $port = $networkIfSpanningTreePort->{'port'}; print "----------------------------------------------\n"; print "Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $spanning_tree_cost = $networkIfSpanningTreeConfig->{'spanning_tree_cost'}; print "spanning_tree_cost: ", $spanning_tree_cost, "\n"; my $spanning_tree_priority = $networkIfSpanningTreeConfig->{'spanning_tree_priority'}; print "spanning_tree_priority: ", $spanning_tree_priority, "\n"; my $spanning_tree_edgeport = $networkIfSpanningTreeConfig->{'spanning_tree_edgeport'}; print "spanning_tree_edgeport: ", $spanning_tree_edgeport, "\n"; my $spanning_tree_force_migration = $networkIfSpanningTreeConfig->{'spanning_tree_force_migration'}; print "spanning_tree_force_migration: ", $spanning_tree_force_migration, "\n"; my $spanning_tree_enable = $networkIfSpanningTreeConfig->{'spanning_tree_enable'}; print "spanning_tree_enable: ", $spanning_tree_enable, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_interface_spanning_tree_configuration #------------------------------------------------------------------------------- print "Calling the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n"; if ($#tenGigabitNetworkList < 0) { print("The list of networks returned from the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface was empty.\n"); } else { my @soapTenGigabitNetworkList = ConvertNetworkPortToSoapData(\@tenGigabitNetworkList); # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_interface_spanning_tree_configuration(SOAP::Data->name('ports')->value(@soapTenGigabitNetworkList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n"; my @networkIfSpanningTreeConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $networkIfSpanningTreeConfig (@networkIfSpanningTreeConfigs) { if (exists $networkIfSpanningTreeConfig->{'port'}) { my $networkIfSpanningTreePort = $networkIfSpanningTreeConfig->{'port'}; my $slot = $networkIfSpanningTreePort->{'slot'}; my $port = $networkIfSpanningTreePort->{'port'}; print "----------------------------------------------\n"; print "Ten Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $spanning_tree_cost = $networkIfSpanningTreeConfig->{'spanning_tree_cost'}; print "spanning_tree_cost: ", $spanning_tree_cost, "\n"; my $spanning_tree_priority = $networkIfSpanningTreeConfig->{'spanning_tree_priority'}; print "spanning_tree_priority: ", $spanning_tree_priority, "\n"; my $spanning_tree_edgeport = $networkIfSpanningTreeConfig->{'spanning_tree_edgeport'}; print "spanning_tree_edgeport: ", $spanning_tree_edgeport, "\n"; my $spanning_tree_force_migration = $networkIfSpanningTreeConfig->{'spanning_tree_force_migration'}; print "spanning_tree_force_migration: ", $spanning_tree_force_migration, "\n"; my $spanning_tree_enable = $networkIfSpanningTreeConfig->{'spanning_tree_enable'}; print "spanning_tree_enable: ", $spanning_tree_enable, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_mgmt_interface_configuration #------------------------------------------------------------------------------- print "Calling the \"get_mgmt_interface_configuration\" method of the ARX Network interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_mgmt_interface_configuration($securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_mgmt_interface_configuration\" method of the ARX Network interface.\n\n"; my $mgmtIfConfig = $networkSoapResult->result; if (exists $mgmtIfConfig->{'port'}) { my $mgmtIfPort = $mgmtIfConfig->{'port'}; my $slot = $mgmtIfPort->{'slot'}; my $port = $mgmtIfPort->{'port'}; print "----------------------------------------------\n"; print "Management Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $description = $mgmtIfConfig->{'description'}; print "description: ", $description, "\n"; my $ip_address = $mgmtIfConfig->{'ip_address'}; print "ip_address: ", $ip_address, "\n"; my $ip_mask = $mgmtIfConfig->{'ip_mask'}; print "ip_mask: ", $ip_mask, "\n"; my $speed = $mgmtIfConfig->{'speed'}; print "speed: ", $speed, "\n"; my $enable = $mgmtIfConfig->{'enable'}; print "enable: ", $enable, "\n"; print "\n"; } #------------------------------------------------------------------------------- # get_mgmt_interface_status #------------------------------------------------------------------------------- print "Calling the \"get_mgmt_interface_status\" method of the ARX Network interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_mgmt_interface_status($securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_mgmt_interface_status\" method of the ARX Network interface.\n\n"; my $mgmtIfStatus = $networkSoapResult->result; if (exists $mgmtIfStatus->{'port'}) { my $mgmtIfPort = $mgmtIfStatus->{'port'}; my $slot = $mgmtIfPort->{'slot'}; my $port = $mgmtIfPort->{'port'}; print "----------------------------------------------\n"; print "Management Interface: slot: ", $slot, ", port: ", $port, "\n"; print "----------------------------------------------\n\n"; print "port:\n"; print " slot: ", $slot, "\n"; print " port: ", $port, "\n"; } my $type = $mgmtIfStatus->{'type'}; print "type: ", $type, "\n"; my $mode = $mgmtIfStatus->{'mode'}; print "mode: ", $mode, "\n"; my $enabled = $mgmtIfStatus->{'enabled'}; print "enabled: ", $enabled, "\n"; my $link_status = $mgmtIfStatus->{'link_status'}; print "link_status: ", $link_status, "\n"; my $speed = $mgmtIfStatus->{'speed'}; print "speed: ", $speed, "\n"; my $mac = $mgmtIfStatus->{'mac'}; print "mac: ", $mac, "\n"; my $accept_all_frame = $mgmtIfStatus->{'accept_all_frame'}; print "accept_all_frame: ", $accept_all_frame, "\n"; my $mtu_size = $mgmtIfStatus->{'mtu_size'}; print "mtu_size: ", $mtu_size, "\n"; print "\n"; } #------------------------------------------------------------------------------- # get_vlan_interface_list #------------------------------------------------------------------------------- my @vlanList = (); print "Calling the \"get_vlan_interface_list\" method of the ARX Network interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_vlan_interface_list($securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_vlan_interface_list\" method of the ARX Network interface.\n\n"; @vlanList = ($networkSoapResult->result, $networkSoapResult->paramsout); if ($#vlanList < 0) { print("The list of VLAN interfaces returned from the call to the \"get_vlan_interface_list\" method of the ARX Network interface was empty.\n"); } else { print "VLAN Interfaces:\n"; foreach my $vlan (@vlanList) { print "$vlan\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_vlan_interface_configuration #------------------------------------------------------------------------------- print "Calling the \"get_vlan_interface_configuration\" method of the ARX Network interface.\n\n"; if ($#vlanList < 0) { print("The list of VLAN interfaces returned from the call to the \"get_vlan_interface_list\" method of the ARX Network interface was empty.\n"); } else { # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_vlan_interface_configuration(SOAP::Data->name('ids')->value(@vlanList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_vlan_interface_configuration\" method of the ARX Network interface.\n\n"; my @vlanConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $vlanConfig (@vlanConfigs) { my $id = $vlanConfig->{'id'}; print "----------------------------------------------\n"; print "VLAN Interface: ", $id, "\n"; print "----------------------------------------------\n\n"; print "id: ", $id, "\n"; my $description = $vlanConfig->{'description'}; print "description: ", $description, "\n"; my $ip_address = $vlanConfig->{'ip_address'}; print "ip_address: ", $ip_address, "\n"; my $ip_mask = $vlanConfig->{'ip_mask'}; print "ip_mask: ", $ip_mask, "\n"; my $redundancy = $vlanConfig->{'redundancy'}; print "redundancy: ", $redundancy, "\n"; my $enable = $vlanConfig->{'enable'}; print "enable: ", $enable, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_ip_proxy_list #------------------------------------------------------------------------------- my @ipProxyList = (); print "Calling the \"get_ip_proxy_list\" method of the ARX Network interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_ip_proxy_list($securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ip_proxy_list\" method of the ARX Network interface.\n\n"; @ipProxyList = ($networkSoapResult->result, $networkSoapResult->paramsout); if ($#ipProxyList < 0) { print("The list of IP Proxies returned from the call to the \"get_ip_proxy_list\" method of the ARX Network interface was empty.\n"); } else { print "IP Proxies:\n"; foreach my $ipProxy (@ipProxyList) { print "$ipProxy\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_ip_proxy_configuration #------------------------------------------------------------------------------- print "Calling the \"get_ip_proxy_configuration\" method of the ARX Network interface.\n\n"; if ($#ipProxyList < 0) { print("The list of IP Proxies returned from the call to the \"get_ip_proxy_list\" method of the ARX Network interface was empty.\n"); } else { # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_ip_proxy_configuration(SOAP::Data->name('ip_address')->value(@ipProxyList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ip_proxy_configuration\" method of the ARX Network interface.\n\n"; my @ipProxyConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $ipProxyConfig (@ipProxyConfigs) { my $proxy_address = $ipProxyConfig->{'proxy_address'}; print "----------------------------------------------\n"; print "IP Proxy Address: ", $proxy_address, "\n"; print "----------------------------------------------\n\n"; print "proxy_address: ", $proxy_address, "\n"; my $mask = $ipProxyConfig->{'mask'}; print "mask: ", $mask, "\n"; my $mac = $ipProxyConfig->{'mac'}; print "mac: ", $mac, "\n"; if (exists $ipProxyConfig->{'processor'}) { my $ipProxyProc = $ipProxyConfig->{'processor'}; print "processor:\n"; my $slot = $ipProxyProc->{'slot'}; print " slot: ", $slot, "\n"; my $processor = $ipProxyProc->{'processor'}; print " processor: ", $processor, "\n"; print "\n"; } my $vlan = $ipProxyConfig->{'vlan'}; print "vlan: ", $vlan, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_ip_proxy_status #------------------------------------------------------------------------------- print "Calling the \"get_ip_proxy_status\" method of the ARX Network interface.\n\n"; if ($#ipProxyList < 0) { print("The list of IP Proxies returned from the call to the \"get_ip_proxy_list\" method of the ARX Network interface was empty.\n"); } else { # Build a security header $securityHeader = getSecurityHeader($user, $pass); $networkSoapResult = $networkSoap->get_ip_proxy_status(SOAP::Data->name('ip_address')->value(@ipProxyList), $securityHeader); if (defined $networkSoapResult->fault && $networkSoapResult->fault) { confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ip_proxy_status\" method of the ARX Network interface.\n\n"; my @ipProxyStatuses = ($networkSoapResult->result, $networkSoapResult->paramsout); foreach my $ipProxyStatus (@ipProxyStatuses) { my $proxy_address = $ipProxyStatus->{'proxy_address'}; print "proxy_address: ", $proxy_address, "\n"; my $mac = $ipProxyStatus->{'mac'}; print "mac: ", $mac, "\n"; my $owner = $ipProxyStatus->{'owner'}; print "owner: ", $owner, "\n"; my $in_use_by = $ipProxyStatus->{'in_use_by'}; print "in_use_by: ", $in_use_by, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXNetworkExample.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; } sub ConvertNetworkPortToSoapData { my ($portListRef) = @_; my @dataArray; foreach my $port (@$portListRef) { my $sport = SOAP::Data->name("ports")->value(\SOAP::Data->value( SOAP::Data->name("slot")->value($port->{'slot'}), SOAP::Data->name("port")->value($port->{'port'}))); push(@dataArray, $sport); } return @dataArray; }347Views0likes0CommentsARX Volume Info
Problem this snippet solves: This example shows how to retrieve all volumes and their configuration on an ARX. 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. How to use this snippet: ARXVolumeInfo.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system configured with at least one configured namespace. Management access on the ARX must be permitted for HTTP-API and/or HTTPS-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-2010 # 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: ARXVolumeInfo.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 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 Namespace 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); # Get a list of namespaces configured on the ARX. my $namespaceSoapResult = $namespaceSoap->get_list(getSecurityHeader($user, $pass)); # 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 ($namespaceSoapResult->fault) { printf(STDERR "SOAP fault encountered:\n"); printf(STDERR "%s\n", $namespaceSoapResult->faultstring); exit(1); } # The get_list() call did not fail, so we build a list of namespace # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. my @namespaceList = ($namespaceSoapResult->result, $namespaceSoapResult->paramsout); if ($#namespaceList < 0) { print("No namespaces.\n"); exit(0); } # We can now look into each namespace for volumes for (my $i = 0; $namespaceList[$i]; $i++) { print "Namespace: $namespaceList[$i]\n"; # Get a list of volumes configured on the ARX. my $volumeSoapResult = $volumeSoap->get_list(SOAP::Data->name('namespace') ->value($namespaceList[$i]), getSecurityHeader($user, $pass)); # 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 ($volumeSoapResult->fault) { printf(STDERR " SOAP fault encountered:\n"); printf(STDERR " %s\n", $volumeSoapResult->faultstring); next; } # The get_list() call did not fail, so we build a list of namespace # 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 volume list is not empty, we can use that list to retrieve configuration # and status information for all of the volumes using the same list by calling # get_definition(). if ($#volumeList < 0) { printf(" No volumes.\n"); next; } $volumeSoapResult = $volumeSoap->get_definition(SOAP::Data->name('namespace') ->value($namespaceList[$i]), SOAP::Data->name('volumes') ->value(@volumeList), getSecurityHeader($user, $pass)); # As we did for the get_list() call, we need to check for any # errors. if ($volumeSoapResult->fault) { printf(STDERR "SOAP fault encountered:\n"); printf(STDERR "%s\n", $volumeSoapResult->faultstring); exit(1); } # If there weren't any errors, then we can print the # definitions for each configured namespace. my @volumeDefinitions = ($volumeSoapResult->result, $volumeSoapResult->paramsout); for (my $i = 0; $volumeDefinitions[$i]; $i++) { printf(" Volume: %s\n", $volumeDefinitions[$i]->{name}); printf(" description : %s\n", $volumeDefinitions[$i]->{description}); printf(" status : %s\n", $volumeDefinitions[$i]->{status}); printf(" vpu : %d\n", $volumeDefinitions[$i]->{vpu}); printf(" failure domain : %s\n", $volumeDefinitions[$i]->{failure_domain}); } } print "\n\n"; #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXVolumeInfo.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; }352Views0likes0CommentsPerl ARX Chassis
Problem this snippet solves: This script is an example of how to use the iControl interfaces provided by an ARX to retrieve chassis configuration, status and statistics on an ARX. How to use this snippet: ARXChassisExample.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system. 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 chassis configuration, status and statistics on an ARX. # # Usage: ARXChassisExample.pl --url --user --pass # # Prerequisites: # # This script requires the following: # # * SOAP::Lite perl module # * An F5 ARX system running release V6.02.000 or later. # * Management access on the ARX must be permitted for HTTPs-API or HTTP-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 $chassisServiceUrl = $url . "/api/services/Chassis"; # 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 Chassis interface and we're # interested in using the WSDL 1.1 version. # my $chassisWsdlUrl = $chassisServiceUrl . "?wsdl"; # Now we build our SOAP::Lite object using the service and WSDL # URLs my $chassisSoap = SOAP::Lite->new(proxy => $chassisServiceUrl, service => $chassisWsdlUrl); #------------------------------------------------------------------------------- # get_ha_peer #------------------------------------------------------------------------------- print "Calling the \"get_ha_peer\" method of the ARX Chassis interface.\n\n"; # Build a security header our $securityHeader = getSecurityHeader($user, $pass); my $chassisSoapResult = $chassisSoap->get_ha_peer($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { print("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ha_peer\" method of the ARX Chassis interface.\n\n"; print "HA Peer Status:\n"; my $chassisHaPeerStatus = $chassisSoapResult->result; my $peerIp = $chassisHaPeerStatus->{'ip'}; print "ip: ", $peerIp, "\n"; my $peerName = $chassisHaPeerStatus->{'name'}; print "name: ", $peerName, "\n"; my $peerRole = $chassisHaPeerStatus->{'role'}; print "role: ", $peerRole, "\n"; my $peerStatus = $chassisHaPeerStatus->{'status'}; print "status: ", $peerStatus, "\n"; print "\n"; } #------------------------------------------------------------------------------- # get_ha_status #------------------------------------------------------------------------------- print "Calling the \"get_ha_status\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_ha_status($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_ha_status\" method of the ARX Chassis interface.\n\n"; print "HA Status:\n"; my $chassisHaStatus = $chassisSoapResult->result; my $haStatusName = $chassisHaStatus->{'name'}; print "name: ", $haStatusName, "\n"; my $ip = $chassisHaStatus->{'ip'}; print "ip: ", $ip, "\n"; my $role = $chassisHaStatus->{'role'}; print "role: ", $role, "\n"; my $status = $chassisHaStatus->{'status'}; print "status: ", $status, "\n"; print "\n"; } #------------------------------------------------------------------------------- # get_health #------------------------------------------------------------------------------- print "Calling the \"get_health\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_health($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_health\" method of the ARX Chassis interface.\n\n"; my @chassisHealths = ($chassisSoapResult->result, $chassisSoapResult->paramsout); foreach my $chassisHealth (@chassisHealths) { my $date = $chassisHealth->{'date'}; print "date: ", $date, "\n"; my $description = $chassisHealth->{'description'}; print "description: ", $description, "\n"; my $event = $chassisHealth->{'event'}; print "event: ", $event, "\n"; my $id = $chassisHealth->{'id'}; print "id: ", $id, "\n"; print "\n"; } print "\n"; } #------------------------------------------------------------------------------- # get_hostname #------------------------------------------------------------------------------- print "Calling the \"get_hostname\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_hostname($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_hostname\" method of the ARX Chassis interface.\n\n"; my $hostname = $chassisSoapResult->result; print "Hostname: $hostname\n\n"; } #------------------------------------------------------------------------------- # get_hw_version #------------------------------------------------------------------------------- print "Calling the \"get_hw_version\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_hw_version($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_hw_version\" method of the ARX Chassis interface.\n\n"; my $hwVersion = $chassisSoapResult->result; print "HW Version: $hwVersion\n\n"; } #------------------------------------------------------------------------------- # get_model #------------------------------------------------------------------------------- print "Calling the \"get_model\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_model($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_model\" method of the ARX Chassis interface.\n\n"; my $model = $chassisSoapResult->result; print "Model: $model\n\n"; } #------------------------------------------------------------------------------- # get_processor_list #------------------------------------------------------------------------------- my @processorList = (); print "Calling the \"get_processor_list\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_processor_list($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_processor_list\" method of the ARX Chassis interface.\n\n"; @processorList = ($chassisSoapResult->result, $chassisSoapResult->paramsout); foreach my $processor (@processorList) { my $slot = $processor->{'slot'}; print "slot: ", $slot, "\n"; my $proc = $processor->{'processor'}; print "processor: ", $proc, "\n"; print "\n"; } print "\n"; } #------------------------------------------------------------------------------- # get_processor_stats #------------------------------------------------------------------------------- print "Calling the \"get_processor_stats\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_processor_stats($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_processor_stats\" method of the ARX Chassis interface.\n\n"; my @processorStats = ($chassisSoapResult->result, $chassisSoapResult->paramsout); foreach my $processorStat (@processorStats) { my $processor = $processorStat->{'processor'}; print "processor: ", $processor, "\n"; my $cpu1min = $processorStat->{'cpu1min'}; print "cpu1min: ", $cpu1min, "\n"; my $cpu5min = $processorStat->{'cpu5min'}; print "cpu5min: ", $cpu5min, "\n"; my $freemem = $processorStat->{'freemem'}; print "freemem: ", $freemem, "\n"; my $module_type = $processorStat->{'module_type'}; print "module_type: ", $module_type, "\n"; my $status = $processorStat->{'status'}; print "status: ", $status, "\n"; my $totalmem = $processorStat->{'totalmem'}; print "totalmem: ", $totalmem, "\n"; my $uptime = $processorStat->{'uptime'}; print "uptime: ", $uptime, "\n"; print "\n"; } print "\n"; } #------------------------------------------------------------------------------- # get_processor_status #------------------------------------------------------------------------------- print "Calling the \"get_processor_status\" method of the ARX Chassis interface.\n\n"; if ($#processorList < 0) { print("The list of processors returned from the call to the \"get_list\" method of the ARX Chassis interface was empty.\n"); } else { my @soapProcessorList = ConvertProcessorIdsToSoapData(\@processorList); # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_processor_status(SOAP::Data->name('processors')->value(@soapProcessorList), $securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_processor_status\" method of the ARX Chassis interface.\n\n"; my @processorStatuses = ($chassisSoapResult->result, $chassisSoapResult->paramsout); foreach my $processorStatus (@processorStatuses) { if (exists $processorStatus->{'processor'}) { my $processorStatusProc = $processorStatus->{'processor'}; print "processor:\n"; my $slot = $processorStatusProc->{'slot'}; print " slot: ", $slot, "\n"; my $processor = $processorStatusProc->{'processor'}; print " processor: ", $processor, "\n"; print "\n"; } my $role = $processorStatus->{'role'}; print "role: ", $role, "\n"; my $state = $processorStatus->{'state'}; print "state: ", $state, "\n"; my $uptime = $processorStatus->{'uptime'}; print "uptime: ", $uptime, "\n"; my $free_memory = $processorStatus->{'free_memory'}; print "free_memory: ", $free_memory, "\n"; my $total_memory = $processorStatus->{'total_memory'}; print "total_memory: ", $total_memory, "\n"; my $free_swap = $processorStatus->{'free_swap'}; print "free_swap: ", $free_swap, "\n"; my $total_swap = $processorStatus->{'total_swap'}; print "total_swap: ", $total_swap, "\n"; my $cpu1min = $processorStatus->{'cpu1min'}; print "cpu1min: ", $cpu1min, "\n"; my $cpu5min = $processorStatus->{'cpu5min'}; print "cpu5min: ", $cpu5min, "\n"; print "\n"; } print "\n"; } } #------------------------------------------------------------------------------- # get_serial #------------------------------------------------------------------------------- print "Calling the \"get_serial\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_serial($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_serial\" method of the ARX Chassis interface.\n\n"; my $serial = $chassisSoapResult->result; print "Serial: $serial\n\n"; } #------------------------------------------------------------------------------- # get_storage_status #------------------------------------------------------------------------------- print "Calling the \"get_storage_status\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_storage_status($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_storage_status\" method of the ARX Chassis interface.\n\n"; my @storageStatuses = ($chassisSoapResult->result, $chassisSoapResult->paramsout); foreach my $storageStatus (@storageStatuses) { my $storageName = $storageStatus->{'name'}; print "name: ", $storageName, "\n"; my $free_space = $storageStatus->{'free_space'}; print "free_space: ", $free_space, "\n"; my $total_space = $storageStatus->{'total_space'}; print "total_space: ", $total_space, "\n"; my $used_space = $storageStatus->{'used_space'}; print "used_space: ", $used_space, "\n"; print "\n"; } print "\n"; } #------------------------------------------------------------------------------- # get_sw_version #------------------------------------------------------------------------------- print "Calling the \"get_sw_version\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_sw_version($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_sw_version\" method of the ARX Chassis interface.\n\n"; my $swVersion = $chassisSoapResult->result; print "SW Version: $swVersion\n\n"; } #------------------------------------------------------------------------------- # get_type #------------------------------------------------------------------------------- print "Calling the \"get_type\" method of the ARX Chassis interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); $chassisSoapResult = $chassisSoap->get_type($securityHeader); if (defined $chassisSoapResult->fault && $chassisSoapResult->fault) { confess("SOAP request failed:\n" . objdump($chassisSoapResult->fault) . "\n"); } else { print "Printing the results of the call to the \"get_type\" method of the ARX Chassis interface.\n\n"; my $type = $chassisSoapResult->result; print "Type: $type\n\n"; } #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXChassisExample.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; } sub ConvertProcessorIdsToSoapData { my ($idListRef) = @_; my @dataArray; foreach my $id (@$idListRef) { my %idHash = %{$id}; my $sid = SOAP::Data->name("processors")->value(\SOAP::Data->value( SOAP::Data->name("slot")->value($idHash{'slot'}), SOAP::Data->name("processor")->value($idHash{'processor'}))); push(@dataArray, $sid); } return @dataArray; }315Views0likes0CommentsPerl ARX Export
Problem this snippet solves: This script is an example of how to use the iControl interfaces provided by an ARX to retrieve all exports and their configuration on an ARX. How to use this snippet: ARXExportExample.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later. 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 exports and their configuration on an ARX. # # Usage: ARXExportExample.pl --url --user --pass # # Prerequisites: # # This script requires the following: # # * SOAP::Lite perl module # * An F5 ARX system configured with at least one configured export. # * 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 $virtualServiceServiceUrl = $url . "/api/services/VirtualService"; my $exportServiceUrl = $url . "/api/services/Export"; # 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 Export interface and we're # interested in using the WSDL 1.1 version. # my $virtualServiceWsdlUrl = $virtualServiceServiceUrl . "?wsdl"; my $exportWsdlUrl = $exportServiceUrl . "?wsdl"; # Now we build our SOAP::Lite object using the service and WSDL # URLs my $virtualServiceSoap = SOAP::Lite->new(proxy => $virtualServiceServiceUrl, service => $virtualServiceWsdlUrl); my $exportSoap = SOAP::Lite->new(proxy => $exportServiceUrl, service => $exportWsdlUrl); # Build a security header our $securityHeader = getSecurityHeader($user, $pass); my $virtualServiceSoapResult = $virtualServiceSoap->get_list($securityHeader); if (defined $virtualServiceSoapResult->fault && $virtualServiceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($virtualServiceSoapResult->fault) . "\n"); } my @virtualServiceList = ($virtualServiceSoapResult->result, $virtualServiceSoapResult->paramsout); if ($#virtualServiceList < 0) { print("The list of virtual services returned from the call to the \"get_list\" method of the ARX VirtualService interface was empty.\n"); exit(0); } my @protocolTypeList = qw(ARX_PROTOCOL_CIFS ARX_PROTOCOL_NFS); foreach my $virtualService (@virtualServiceList) { foreach my $protocolType (@protocolTypeList) { print "##############################################\n"; print "Virtual Service: $virtualService\n"; print "Protocol: $protocolType\n"; print "##############################################\n\n"; print "Calling the \"get_list\" method of the ARX Export interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # Get a list of exports configured on the ARX. my $exportSoapResult = $exportSoap->get_list2(SOAP::Data->name('virtual_service')->value($virtualService), SOAP::Data->name('protocol')->value($protocolType), $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 $exportSoapResult->fault && $exportSoapResult->fault) { confess("SOAP request failed:\n" . objdump($exportSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_list\" method of the ARX Export interface.\n\n"; # The get_list() call did not fail, so we build a list of export # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. my @exportList = ($exportSoapResult->result, $exportSoapResult->paramsout); if ($#exportList < 0) { print("The list of exports returned from the call to the \"get_list\" method of the ARX Export interface was empty.\n"); exit(0); } # We can now print the list of exports print "Export list:\n"; foreach my $export (@exportList) { print " ", $export, "\n"; } print "\n"; print "Calling the \"get_configuration\" method of the ARX Export interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get export configuration from API # In addition to printing the list of exports, we can actually # use that list to retrieve configuration information # for all of the exports using the same list by calling # get_configuration(). $exportSoapResult = $exportSoap->get_configuration(SOAP::Data->name('virtual_service')->value($virtualService), SOAP::Data->name('protocol')->value($protocolType), SOAP::Data->name('exports')->value(@exportList), $securityHeader); if (defined $exportSoapResult->fault && $exportSoapResult->fault) { confess("SOAP request failed:\n" . objdump($exportSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_configuration\" method of the ARX Export interface.\n\n"; my @exportConfigs = ($exportSoapResult->result, $exportSoapResult->paramsout); foreach my $exportConfig (@exportConfigs) { my $name = $exportConfig->{'name'}; print "----------------------------------------------\n"; print "Export: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $description = $exportConfig->{'description'}; print "description: ", $description, "\n"; my $namespace = $exportConfig->{'namespace'}; print "namespace: ", $namespace, "\n"; my $path = $exportConfig->{'path'}; print "path: ", $path, "\n"; my $protocol = $exportConfig->{'protocol'}; print "protocol: ", $protocol, "\n"; my $file_server_subshare = $exportConfig->{'file_server_subshare'}; print "file_server_subshare: ", $file_server_subshare, "\n"; my $hidden = $exportConfig->{'hidden'}; print "hidden: ", $hidden, "\n"; my $access_list = $exportConfig->{'access_list'}; print "access_list: ", $access_list, "\n"; print "\n"; } print "Calling the \"get_status\" method of the ARX Export interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get export status from API # In addition to printing the list of exports, we can actually # use that list to retrieve status information for all of the exports # using the same list by calling get_status(). $exportSoapResult = $exportSoap->get_status(SOAP::Data->name('virtual_service')->value($virtualService), SOAP::Data->name('protocol')->value($protocolType), SOAP::Data->name('exports')->value(@exportList), $securityHeader); if (defined $exportSoapResult->fault && $exportSoapResult->fault) { confess("SOAP request failed:\n" . objdump($exportSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_status\" method of the ARX Export interface.\n\n"; my @exportStatuses = ($exportSoapResult->result, $exportSoapResult->paramsout); foreach my $exportStatus (@exportStatuses) { my $name = $exportStatus->{'name'}; print "----------------------------------------------\n"; print "Export: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $status = $exportStatus->{'status'}; print "status: ", $status, "\n"; my $nfs_offline_deny_access = $exportStatus->{'nfs_offline_deny_access'}; print "nfs_offline_deny_access: ", $nfs_offline_deny_access, "\n"; print "\n"; } } } #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXExportExample.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; }308Views0likes0CommentsPerl ARX FileServer
Problem this snippet solves: This script is an example of how to use the iControl interfaces provided by an ARX to retrieve filer servers and their configurations, statuses and statistics on an ARX. How to use this snippet: ARXFileServerExample.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later. 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 file servers and their configurations, statuses and # statistics on an ARX. # # Usage: ARXFileServerExample.pl --url --user --pass # # Prerequisites: # # This script requires the following: # # * SOAP::Lite perl module # * An F5 ARX system configured with at least one configured file server. # * 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 $fileServerServiceUrl = $url . "/api/services/FileServer"; # 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 FileServer interface and we're # interested in using the WSDL 1.1 version. # my $fileServerWsdlUrl = $fileServerServiceUrl . "?wsdl"; # Now we build our SOAP::Lite object using the service and WSDL # URLs my $fileServerSoap = SOAP::Lite->new(proxy => $fileServerServiceUrl, service => $fileServerWsdlUrl); print "Calling the \"get_list\" method of the ARX FileServer interface.\n\n"; # Build a security header our $securityHeader = getSecurityHeader($user, $pass); # Get a list of file servers configured on the ARX. my $fileServerSoapResult = $fileServerSoap->get_list($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 $fileServerSoapResult->fault && $fileServerSoapResult->fault) { confess("SOAP request failed:\n" . objdump($fileServerSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_list\" method of the ARX FileServer interface.\n\n"; # The get_list() call did not fail, so we build a list of file server # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. my @fileServerList = ($fileServerSoapResult->result, $fileServerSoapResult->paramsout); if ($#fileServerList < 0) { print("The list of file servers returned from the call to the \"get_list\" method of the ARX FileServer interface was empty.\n"); exit(0); } # We can now print the list of file servers print "File Servers list:\n"; foreach my $fileServer (@fileServerList) { print " ", $fileServer, "\n"; } print "\n"; print "Calling the \"get_configuration\" method of the ARX FileServer interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get file server configuration from API # In addition to printing the list of file servers, we can actually # use that list to retrieve configuration information # for all of the file servers using the same list by calling # get_configuration(). $fileServerSoapResult = $fileServerSoap->get_configuration(SOAP::Data->name('file_servers')->value(@fileServerList), $securityHeader); if (defined $fileServerSoapResult->fault && $fileServerSoapResult->fault) { confess("SOAP request failed:\n" . objdump($fileServerSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_configuration\" method of the ARX FileServer interface.\n\n"; my @fileServerConfigs = ($fileServerSoapResult->result, $fileServerSoapResult->paramsout); foreach my $fileServerConfig (@fileServerConfigs) { my $name = $fileServerConfig->{'name'}; print "----------------------------------------------\n"; print "File Server: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $description = $fileServerConfig->{'description'}; print "description: ", $description, "\n"; my $cifs_port = $fileServerConfig->{'cifs_port'}; print "cifs_port: ", $cifs_port, "\n"; my $cifs_connection_limit = $fileServerConfig->{'cifs_connection_limit'}; print "cifs_connection_limit: ", $cifs_connection_limit, "\n"; my $nfs_tcp_connections = $fileServerConfig->{'nfs_tcp_connections'}; print "nfs_tcp_connections: ", $nfs_tcp_connections, "\n"; my $ip_address = $fileServerConfig->{'ip_address'}; print "ip_address: ", $ip_address, "\n"; if (exists $fileServerConfig->{'ip_address_secondary'}) { print "ip_address_secondary:\n"; my @ip_address_secondary = (); if (ref($fileServerConfig->{'ip_address_secondary'}) eq "ARRAY") { @ip_address_secondary = @{$fileServerConfig->{'ip_address_secondary'}}; } else { @ip_address_secondary = $fileServerConfig->{'ip_address_secondary'}; } foreach my $ip_address (@ip_address_secondary) { print " ", $ip_address, "\n"; } print "\n"; } my $ip_address_management = $fileServerConfig->{'ip_address_management'}; print "ip_address_management: ", $ip_address_management, "\n"; my $proxy_user = $fileServerConfig->{'proxy_user'}; print "proxy_user: ", $proxy_user, "\n"; my $manage_snapshots = $fileServerConfig->{'manage_snapshots'}; print "manage_snapshots: ", $manage_snapshots, "\n"; my $spn = $fileServerConfig->{'spn'}; print "spn: ", $spn, "\n"; if (exists $fileServerConfig->{'ignore_names'}) { print "ignore_names:\n"; my @ignore_names = (); if (ref($fileServerConfig->{'ignore_names'}) eq "ARRAY") { @ignore_names = @{$fileServerConfig->{'ignore_names'}}; } else { @ignore_names = $fileServerConfig->{'ignore_names'}; } foreach my $ignore_name (@ignore_names) { print " ", $ignore_name, "\n"; } print "\n"; } if (exists $fileServerConfig->{'type'}) { print "type:\n"; my $fsType = $fileServerConfig->{'type'}; my $type = $fsType->{'type'}; print " type: ", $type, "\n"; my $protocol = $fsType->{'protocol'}; print " protocol: ", $protocol, "\n"; my $emc_nas_db_path = $fsType->{'emc_nas_db_path'}; print " emc_nas_db_path: ", $emc_nas_db_path, "\n"; my $winrm_port = $fsType->{'winrm_port'}; print " winrm_port: ", $winrm_port, "\n"; my $windows_cluster = $fsType->{'windows_cluster'}; print " windows_cluster: ", $windows_cluster, "\n"; } print "\n"; } print "Calling the \"get_status\" method of the ARX FileServer interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get file server configuration from API # In addition to printing the list of file servers, we can actually # use that list to retrieve status information for all of the file servers # using the same list by calling get_status(). $fileServerSoapResult = $fileServerSoap->get_status(SOAP::Data->name('file_servers')->value(@fileServerList), $securityHeader); if (defined $fileServerSoapResult->fault && $fileServerSoapResult->fault) { confess("SOAP request failed:\n" . objdump($fileServerSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_status\" method of the ARX FileServer interface.\n\n"; my @fileServerStatuses = ($fileServerSoapResult->result, $fileServerSoapResult->paramsout); foreach my $fileServerStatus (@fileServerStatuses) { my $name = $fileServerStatus->{'name'}; print "----------------------------------------------\n"; print "File Server: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $discovered_spn = $fileServerStatus->{'discovered_spn'}; print "discovered_spn: ", $discovered_spn, "\n"; print "\n"; } #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXFileServerExample.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; }323Views0likes0CommentsPerl ARX Namespace
Problem this snippet solves: This script is an example of how to use the iControl interfaces provided by an ARX to retrieve all namespaces and their configuration on an ARX. How to use this snippet: ARXNamespaceExample.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later and configured with at least one configured namespace 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 namespaces and their configuration on an ARX. # # Usage: ARXNamespaceExample.pl --url --user --pass # # Prerequisites: # # This script requires the following: # # * SOAP::Lite perl module # * An F5 ARX system configured with at least one configured namespace. # * 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"; # 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 Namespace interface and we're # interested in using the WSDL 1.1 version. # my $namespaceWsdlUrl = $namespaceServiceUrl . "?wsdl"; # Now we build our SOAP::Lite object using the service and WSDL # URLs my $namespaceSoap = SOAP::Lite->new(proxy => $namespaceServiceUrl, service => $namespaceWsdlUrl); print "Calling the \"get_list\" method of the ARX Namespace interface.\n\n"; # Get a list of namespaces configured on the ARX. # Build a security header our $securityHeader = getSecurityHeader($user, $pass); my $namespaceSoapResult = $namespaceSoap->get_list($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 $namespaceSoapResult->fault && $namespaceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($namespaceSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_list\" method of the ARX Namespace interface.\n\n"; # The get_list() call did not fail, so we build a list of namespace # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. 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); } # We can now print the list of namespaces print "Namespace list:\n"; foreach my $namespace (@namespaceList) { print " ", $namespace, "\n"; } print "\n"; print "Calling the \"get_configuration\" method of the ARX Namespace interface.\n\n"; # get namespace configuration from API # Build a security header $securityHeader = getSecurityHeader($user, $pass); # In addition to printing the list of namespaces, we can actually # use that list to retrieve configuration information # for all of the namespaces using the same list by calling # get_configuration(). $namespaceSoapResult = $namespaceSoap->get_configuration(SOAP::Data->name('namespaces')->value(@namespaceList), $securityHeader); if (defined $namespaceSoapResult->fault && $namespaceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($namespaceSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_configuration\" method of the ARX Namespace interface.\n\n"; my @namespaceConfigs = ($namespaceSoapResult->result, $namespaceSoapResult->paramsout); foreach my $namespaceConfig (@namespaceConfigs) { my $name = $namespaceConfig->{'name'}; print "----------------------------------------------\n"; print "Namespace: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $description = $namespaceConfig->{'description'}; print "description: ", $description, "\n"; # Each namespace is configured with support for file access protocols like # CIFS and NFS. For single protocol support, it's just a hash with the # type and version, but if there are multiple protocols supported, then # it's actually an array of hashes, so we need to unwrap it. if (exists $namespaceConfig->{'protocols'}) { print "protocols:\n"; my @protocols = (); if (ref($namespaceConfig->{'protocols'}) eq "ARRAY") { @protocols = @{$namespaceConfig->{'protocols'}}; } else { @protocols = $namespaceConfig->{'protocols'}; } foreach my $protocol (@protocols) { print " ", $protocol, "\n"; } print "\n"; } my $character_encoding_nfs = $namespaceConfig->{'character_encoding_nfs'}; print "character_encoding_nfs: ", $character_encoding_nfs, "\n"; my $cifs_anonymous_access = $namespaceConfig->{'cifs_anonymous_access'}; print "cifs_anonymous_access: ", $cifs_anonymous_access, "\n"; if (exists $namespaceConfig->{'cifs_authentications'}) { print "cifs_authentications:\n"; my @cifs_authentications = (); if (ref($namespaceConfig->{'cifs_authentications'}) eq "ARRAY") { @cifs_authentications = @{$namespaceConfig->{'cifs_authentications'}}; } else { @cifs_authentications = $namespaceConfig->{'cifs_authentications'}; } foreach my $cifs_authentication (@cifs_authentications) { print " ", $cifs_authentication, "\n"; } print "\n"; } my $cifs_filer_signatures = $namespaceConfig->{'cifs_filer_signatures'}; print "cifs_filer_signatures: ", $cifs_filer_signatures, "\n"; my $ntlm_auth_db = $namespaceConfig->{'ntlm_auth_db'}; print "ntlm_auth_db: ", $ntlm_auth_db, "\n"; if (exists $namespaceConfig->{'ntlm_auth_servers'}) { print "ntlm_auth_servers:\n"; my @ntlm_auth_servers = (); if (ref($namespaceConfig->{'ntlm_auth_servers'}) eq "ARRAY") { @ntlm_auth_servers = @{$namespaceConfig->{'ntlm_auth_servers'}}; } else { @ntlm_auth_servers = $namespaceConfig->{'ntlm_auth_servers'}; } foreach my $ntlm_auth_server (@ntlm_auth_servers) { print " ", $ntlm_auth_server, "\n"; } print "\n"; } my $policy_migration_attempts = $namespaceConfig->{'policy_migration_attempts'}; print "policy_migration_attempts: ", $policy_migration_attempts, "\n"; my $policy_migration_delay = $namespaceConfig->{'policy_migration_delay'}; print "policy_migration_delay: ", $policy_migration_delay, "\n"; my $policy_migration_retry_delay = $namespaceConfig->{'policy_migration_retry_delay'}; print "policy_migration_retry_delay: ", $policy_migration_retry_delay, "\n"; my $policy_treewalk_threads = $namespaceConfig->{'policy_treewalk_threads'}; print "policy_treewalk_threads: ", $policy_treewalk_threads, "\n"; my $proxy_user = $namespaceConfig->{'proxy_user'}; print "proxy_user: ", $proxy_user, "\n"; if (exists $namespaceConfig->{'sam_references'}) { print "sam_references:\n"; my @sam_references = (); if (ref($namespaceConfig->{'sam_references'}) eq "ARRAY") { @sam_references = @{$namespaceConfig->{'sam_references'}}; } else { @sam_references = $namespaceConfig->{'sam_references'}; } foreach my $sam_reference (@sam_references) { my $file_server = $sam_reference->{'file_server'}; print " file_server: ", $file_server, "\n"; my $cluster = $sam_reference->{'cluster'}; print " cluster: ", $cluster, "\n"; print "\n"; } } if (exists $namespaceConfig->{'windows_mgmt_auths'}) { print "windows_mgmt_auths:\n"; my @windows_mgmt_auths = (); if (ref($namespaceConfig->{'windows_mgmt_auths'}) eq "ARRAY") { @windows_mgmt_auths = @{$namespaceConfig->{'windows_mgmt_auths'}}; } else { @windows_mgmt_auths = $namespaceConfig->{'windows_mgmt_auths'}; } foreach my $windows_mgmt_auth (@windows_mgmt_auths) { print " ", $windows_mgmt_auth, "\n"; } print "\n"; } print "\n"; } #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXNamespaceExample.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; }322Views0likes0CommentsPerl ARX Schedule
Problem this snippet solves: This script is an example of how to use the iControl interfaces provided by an ARX to monitor and manage all schedules on an ARX. How to use this snippet: ARXScheduleExample.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later. 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 monitor and manage all schedules on an ARX. # # Usage: ARXScheduleExample.pl --url --user --pass --op # # Prerequisites: # # This script requires the following: # # * SOAP::Lite perl module # * An F5 ARX system running release V6.02.000 or later. # * 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 Time::Local; 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 $scheduleServiceUrl = $url . "/api/services/Schedule"; # 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 Schedule interface and we're # interested in using the WSDL 1.1 version. # my $scheduleWsdlUrl = $scheduleServiceUrl . "?wsdl"; # Now we build our SOAP::Lite object using the service and WSDL # URLs my $scheduleSoap = SOAP::Lite->new(proxy => $scheduleServiceUrl, service => $scheduleWsdlUrl); if ($op eq "get_list") { get_list(); } elsif ($op eq "get_configuration") { get_configuration(); } elsif ($op eq "get_status") { get_status(); } elsif ($op eq "create") { create(); } elsif ($op eq "set_description") { set_description(); } elsif ($op eq "set_duration") { set_duration(); } elsif ($op eq "set_interval") { set_interval(); } elsif ($op eq "set_start") { set_start(); } elsif ($op eq "set_stop") { set_stop(); } elsif ($op eq "create_and_configure") { create_and_configure(); } elsif ($op eq "remove") { remove(); } #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXScheduleExample.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 ARXSchedule API method that will be called:\n"; print "\n"; print " create\n"; print " create_and_configure\n"; print " set_description\n"; print " set_duration\n"; print " set_interval\n"; print " set_start\n"; print " set_stop\n"; print " get_list\n"; print " get_configuration\n"; print " get_status\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 { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Calling the \"create\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n\n"; # Build a security header my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->create(SOAP::Data->name('schedule')->value($schedule), $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 $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } } sub create_and_configure { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Please specify a description:\n\n"; chomp(my $description = <>); print "\n"; print "Please specify a duration:\n\n"; chomp(my $duration = <>); print "\n"; print "Please specify a start time (mm/dd/yyyy:hh:mm):\n\n"; chomp(my $time = <>); my $month = substr($time, 0, 2) - 1; my $day = substr($time, 3, 2); my $year = substr($time, 6, 4); my $hour = substr($time, 11, 2); my $minute = substr($time, 14, 2); my $start = timelocal(0, $minute, $hour, $day, $month, $year); print "\n"; print "Please specify a stop time (mm/dd/yyyy:hh:mm):\n\n"; chomp($time = <>); $month = substr($time, 0, 2) - 1; $day = substr($time, 3, 2); $year = substr($time, 6, 4); $hour = substr($time, 11, 2); $minute = substr($time, 14, 2); my $stop = timelocal(0, $minute, $hour, $day, $month, $year); print "\n"; print "Please specify either 'ARX_INTERVAL_UNKNOWN', 'ARX_INTERVAL_MINUTES', 'ARX_INTERVAL_HOURS', 'ARX_INTERVAL_DAYS', 'ARX_INTERVAL_WEEKS', 'ARX_INTERVAL_MONTHS', 'ARX_INTERVAL_QUARTERS', 'ARX_INTERVAL_YEARS', 'ARX_INTERVAL_FIRST_DAY', 'ARX_INTERVAL_LAST_DAY', 'ARX_INTERVAL_HOURS_OF_DAY', 'ARX_INTERVAL_DAYS_OF_WEEK', or 'ARX_INTERVAL_DAYS_OF_MONTH' for the 'interval_type':\n\n"; chomp(my $intervalType = <>); print "\n"; print "Please specify an 'interval':\n\n"; chomp(my $interval = <>); print "\n"; print "Calling the \"create_and_configure\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n"; print "description: $description\n"; print "duration: $duration\n"; print "start_time: $start\n"; print "stop_time: $stop\n"; print "interval_type: $intervalType\n"; print "interval: $interval\n\n"; my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->create_and_configure(SOAP::Data->name('configuration' => \SOAP::Data->value( SOAP::Data->name("name" => $schedule), SOAP::Data->name("description" => $description), SOAP::Data->name("duration" => $duration), SOAP::Data->name("start_time" => $start, SOAP::Data->name("stop_time" => $stop), SOAP::Data->name("interval_type" => $intervalType), SOAP::Data->name("interval" => $interval)) )), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } } sub set_description { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Please specify a description:\n\n"; chomp(my $description = <>); print "\n"; print "Calling the \"set_description\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n"; print "description: $description\n\n"; my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->set_description(SOAP::Data->name('schedule')->value($schedule), SOAP::Data->name('description')->value($description), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } } sub set_duration { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Please specify a duration:\n\n"; chomp(my $duration = <>); print "\n"; print "Calling the \"set_duration\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n"; print "duration: $duration\n\n"; my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->set_duration(SOAP::Data->name('schedule')->value($schedule), SOAP::Data->name('duration')->value($duration), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } } sub set_interval { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Please specify either 'ARX_INTERVAL_UNKNOWN', 'ARX_INTERVAL_MINUTES', 'ARX_INTERVAL_HOURS', 'ARX_INTERVAL_DAYS', 'ARX_INTERVAL_WEEKS', 'ARX_INTERVAL_MONTHS', 'ARX_INTERVAL_QUARTERS', 'ARX_INTERVAL_YEARS', 'ARX_INTERVAL_FIRST_DAY', 'ARX_INTERVAL_LAST_DAY', 'ARX_INTERVAL_HOURS_OF_DAY', 'ARX_INTERVAL_DAYS_OF_WEEK', or 'ARX_INTERVAL_DAYS_OF_MONTH' for the 'interval_type':\n\n"; chomp(my $intervalType = <>); print "\n"; print "Please specify an 'interval':\n\n"; chomp(my $interval = <>); print "\n"; print "Calling the \"set_interval\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n"; print "interval_type: $intervalType\n"; print "interval: $interval\n\n"; my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->set_interval(SOAP::Data->name('schedule')->value($schedule), SOAP::Data->name("interval_type" => $intervalType), SOAP::Data->name("interval" => $interval), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } } sub set_start { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Please specify a start time (mm/dd/yyyy:hh:mm):\n\n"; chomp(my $time = <>); my $month = substr($time, 0, 2) - 1; my $day = substr($time, 3, 2); my $year = substr($time, 6, 4); my $hour = substr($time, 11, 2); my $minute = substr($time, 14, 2); my $start = timelocal(0, $minute, $hour, $day, $month, $year); print "\n"; print "Calling the \"set_start\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n"; print "time: $start\n\n"; my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->set_start(SOAP::Data->name('schedule')->value($schedule), SOAP::Data->name('time')->value($start), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } } sub set_stop { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Please specify a stop time (mm/dd/yyyy:hh:mm):\n\n"; chomp(my $time = <>); my $month = substr($time, 0, 2) - 1; my $day = substr($time, 3, 2); my $year = substr($time, 6, 4); my $hour = substr($time, 11, 2); my $minute = substr($time, 14, 2); my $stop = timelocal(0, $minute, $hour, $day, $month, $year); print "\n"; print "Calling the \"set_stop\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n"; print "time: $stop\n\n"; my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->set_stop(SOAP::Data->name('schedule')->value($schedule), SOAP::Data->name('time')->value($stop), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } } sub get_list { # Get a list of schedules configured on the ARX. print "Calling the \"get_list\" method of the ARX Schedule interface.\n\n"; # Build a security header my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->get_list($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 $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_list\" method of the ARX Schedule interface.\n\n"; # The get_list() call did not fail, so we build a list of schedule # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. my @scheduleList = ($scheduleSoapResult->result, $scheduleSoapResult->paramsout); if ($#scheduleList < 0) { print("The list of schedules returned from the call to the \"get_list\" method of the ARX Schedule interface was empty.\n"); exit(0); } # We can now print the list of schedules print "Schedule list:\n"; foreach my $schedule (@scheduleList) { print " ", $schedule, "\n"; } print "\n"; } sub get_configuration { # Get a list of schedules configured on the ARX. print "Calling the \"get_list\" method of the ARX Schedule interface.\n\n"; # Build a security header my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->get_list($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 $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_list\" method of the ARX Schedule interface.\n\n"; # The get_list() call did not fail, so we build a list of schedule # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. my @scheduleList = ($scheduleSoapResult->result, $scheduleSoapResult->paramsout); if ($#scheduleList < 0) { print("The list of schedules returned from the call to the \"get_list\" method of the ARX Schedule interface was empty.\n"); exit(0); } # get schedule configuration from API print "Calling the \"get_configuration\" method of the ARX Schedule interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # In addition to printing the list of schedules, we can actually # use that list to retrieve configuration information # for all of the schedules using the same list by calling # get_configuration(). $scheduleSoapResult = $scheduleSoap->get_configuration(SOAP::Data->name('schedules')->value(@scheduleList), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_configuration\" method of the ARX Schedule interface.\n\n"; my @scheduleConfigs = ($scheduleSoapResult->result, $scheduleSoapResult->paramsout); foreach my $scheduleConfig (@scheduleConfigs) { my $name = $scheduleConfig->{'name'}; print "----------------------------------------------\n"; print "Schedule: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $description = $scheduleConfig->{'description'}; print "description: ", $description, "\n"; my $duration = $scheduleConfig->{'duration'}; print "duration: ", $duration, "\n"; my $start_time = $scheduleConfig->{'start_time'}; print "start_time: ", $start_time, "\n"; my $stop_time = $scheduleConfig->{'stop_time'}; print "stop_time: ", $stop_time, "\n"; my $interval_type = $scheduleConfig->{'interval_type'}; print "interval_type: ", $interval_type, "\n"; my $interval = $scheduleConfig->{'interval'}; print "interval: ", $interval, "\n"; print "\n"; } } sub get_status { # Get a list of schedules configured on the ARX. print "Calling the \"get_list\" method of the ARX Schedule interface.\n\n"; # Build a security header my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->get_list($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 $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_list\" method of the ARX Schedule interface.\n\n"; # The get_list() call did not fail, so we build a list of schedule # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. my @scheduleList = ($scheduleSoapResult->result, $scheduleSoapResult->paramsout); if ($#scheduleList < 0) { print("The list of schedules returned from the call to the \"get_list\" method of the ARX Schedule interface was empty.\n"); exit(0); } # get schedule status from API print "Calling the \"get_status\" method of the ARX Schedule 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(). $scheduleSoapResult = $scheduleSoap->get_status(SOAP::Data->name('schedules')->value(@scheduleList), $securityHeader); if (defined $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_status\" method of the ARX Schedule interface.\n\n"; my @scheduleStatuses = ($scheduleSoapResult->result, $scheduleSoapResult->paramsout); foreach my $scheduleStatus (@scheduleStatuses) { my $schedule = $scheduleStatus->{'schedule'}; print "----------------------------------------------\n"; print "Schedule: ", $schedule, "\n"; print "----------------------------------------------\n\n"; print "schedule: ", $schedule, "\n"; my $status = $scheduleStatus->{'status'}; print "status: ", $status, "\n"; if (exists $scheduleStatus->{'previous'}) { my $previous = $scheduleStatus->{'previous'}; print "previous:\n"; my $prevRunTime = $previous->{'run_time'}; print " run_time: ", $prevRunTime, "\n"; my $prevEndTime = $previous->{'end_time'}; print " end_time: ", $prevEndTime, "\n"; } if (exists $scheduleStatus->{'current'}) { my $current = $scheduleStatus->{'current'}; print "current:\n"; my $curRunTime = $current->{'run_time'}; print " run_time: ", $curRunTime, "\n"; my $curEndTime = $current->{'end_time'}; print " end_time: ", $curEndTime, "\n"; } if (exists $scheduleStatus->{'next'}) { my $next = $scheduleStatus->{'next'}; print "next:\n"; my $nextRunTime = $next->{'run_time'}; print " run_time: ", $nextRunTime, "\n"; my $nextEndTime = $next->{'end_time'}; print " end_time: ", $nextEndTime, "\n"; } print "\n"; } } sub remove { print "Please specify a schedule name:\n\n"; chomp(my $schedule = <>); print "\n"; print "Calling the \"remove\" method of the ARX Schedule interface with the following parameters:\n\n"; print "schedule: $schedule\n"; # Build a security header my $securityHeader = getSecurityHeader($user, $pass); my $scheduleSoapResult = $scheduleSoap->remove(SOAP::Data->name('schedule')->value($schedule), $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 $scheduleSoapResult->fault && $scheduleSoapResult->fault) { confess("SOAP request failed:\n" . objdump($scheduleSoapResult->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; }331Views0likes0CommentsPerl ARX Virtual Service
Problem this snippet solves: This script is an example of how to use the iControl interfaces provided by an ARX to retrieve all virtual services and their configurations, statuses and statistics on an ARX. How to use this snippet: ARXVirtualServiceExample.pl --url --user --pass Prerequisites SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later and configured with at least one configured virtual service. 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 virtual services and their configuration on an ARX. # # Usage: ARXVirtualServiceExample.pl --url --user --pass # # Prerequisites: # # This script requires the following: # # * SOAP::Lite perl module # * An F5 ARX system configured with at least one configured virtual service. # * 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 $virtualServiceServiceUrl = $url . "/api/services/VirtualService"; # 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 VirtualService interface and we're # interested in using the WSDL 1.1 version. # my $virtualServiceWsdlUrl = $virtualServiceServiceUrl . "?wsdl"; # Now we build our SOAP::Lite object using the service and WSDL # URLs my $virtualServiceSoap = SOAP::Lite->new(proxy => $virtualServiceServiceUrl, service => $virtualServiceWsdlUrl); print "Calling the \"get_list\" method of the ARX VirtualService interface.\n\n"; # Build a security header our $securityHeader = getSecurityHeader($user, $pass); # Get a list of virtual services configured on the ARX. my $virtualServiceSoapResult = $virtualServiceSoap->get_list($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 $virtualServiceSoapResult->fault && $virtualServiceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($virtualServiceSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_list\" method of the ARX VirtualService interface.\n\n"; # The get_list() call did not fail, so we build a list of virtual service # names from the result. Note that the full result is a # concatenation of the result and paramsout members of the SOAP # result object. my @virtualServiceList = ($virtualServiceSoapResult->result, $virtualServiceSoapResult->paramsout); if ($#virtualServiceList < 0) { print("The list of virtual services returned from the call to the \"get_list\" method of the ARX VirtualService interface was empty.\n"); exit(0); } # We can now print the list of virtual services print "Virtual Service list:\n"; foreach my $virtualService (@virtualServiceList) { print " ", $virtualService, "\n"; } print "\n"; print "Calling the \"get_configuration\" method of the ARX VirtualService interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get virtual service configuration from API # In addition to printing the list of virtual services, we can actually # use that list to retrieve configuration information # for all of the virtual services using the same list by calling # get_configuration(). $virtualServiceSoapResult = $virtualServiceSoap->get_configuration(SOAP::Data->name('virtual_services')->value(@virtualServiceList), $securityHeader); if (defined $virtualServiceSoapResult->fault && $virtualServiceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($virtualServiceSoapResult->fault) . "\n"); } my @cifsVirtualServices =(); print "Printing the results of the call to the \"get_configuration\" method of the ARX VirtualService interface.\n\n"; my @virtualServiceConfigs = ($virtualServiceSoapResult->result, $virtualServiceSoapResult->paramsout); foreach my $virtualServiceConfig (@virtualServiceConfigs) { my $name = $virtualServiceConfig->{'name'}; print "----------------------------------------------\n"; print "Virtual Service: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $description = $virtualServiceConfig->{'description'}; print "description: ", $description, "\n"; if (exists $virtualServiceConfig->{'servers'}) { print "servers:\n"; my @servers = (); if (ref($virtualServiceConfig->{'servers'}) eq "ARRAY") { @servers = @{$virtualServiceConfig->{'servers'}}; } else { @servers = $virtualServiceConfig->{'servers'}; } foreach my $server (@servers) { my $hostname = $server->{'hostname'}; print " hostname: ", $hostname, "\n"; my $vip = $server->{'vip'}; print " vip: ", $vip, "\n"; my $mask = $server->{'mask'}; print " mask: ", $mask, "\n"; my $vlan_id = $server->{'vlan_id'}; print " vlan_id: ", $vlan_id, "\n"; my $cluster = $server->{'cluster'}; print " cluster: ", $cluster, "\n"; my $serverEnable = $server->{'enable'}; print " enable: ", $serverEnable, "\n"; print "\n"; } } if (exists $virtualServiceConfig->{'cifs'}) { my $cifs = $virtualServiceConfig->{'cifs'}; print "cifs:\n"; my $cifsDescription = $cifs->{'description'}; print " description: ", $cifsDescription, "\n"; my $windows_domain = $cifs->{'windows_domain'}; print " windows_domain: ", $windows_domain, "\n"; my $pre_win2k_domain = $cifs->{'pre_win2k_domain'}; print " pre_win2k_domain: ", $pre_win2k_domain, "\n"; if (exists $cifs->{'ad_aliases'}) { print " ad_aliases:\n"; my @ad_aliases = (); if (ref($cifs->{'ad_aliases'}) eq "ARRAY") { @ad_aliases = @{$cifs->{'ad_aliases'}}; } else { @ad_aliases = $cifs->{'ad_aliases'}; } foreach my $ad_alias (@ad_aliases) { print " ", $ad_alias, "\n"; } print "\n"; } my $ad_proxy_user = $cifs->{'ad_proxy_user'}; print " ad_proxy_user: ", $ad_proxy_user, "\n"; my $wins = $cifs->{'wins'}; print " wins: ", $wins, "\n"; my $wins_name = $cifs->{'wins_name'}; print " wins_name: ", $wins_name, "\n"; if (exists $cifs->{'wins_aliases'}) { print " wins_aliases:\n"; my @wins_aliases = (); if (ref($cifs->{'wins_aliases'}) eq "ARRAY") { @wins_aliases = @{$cifs->{'wins_aliases'}}; } else { @wins_aliases = $cifs->{'wins_aliases'}; } foreach my $wins_alias (@wins_aliases) { print " ", $wins_alias, "\n"; } print "\n"; } my $wins_name_encoding = $cifs->{'wins_name_encoding'}; print " wins_name_encoding: ", $wins_name_encoding, "\n"; if (exists $cifs->{'browsing'}) { print " browsing:\n"; my @browsing = (); if (ref($cifs->{'browsing'}) eq "ARRAY") { @browsing = @{$cifs->{'browsing'}}; } else { @browsing = $cifs->{'browsing'}; } foreach my $browse (@browsing) { print " ", $browse, "\n"; } print "\n"; } if (exists $cifs->{'kerberos_creds'}) { my $kerberos_creds = $cifs->{'kerberos_creds'}; print " kerberos_creds:\n"; my $active_directory = $kerberos_creds->{'active_directory'}; print " active_directory: ", $active_directory, "\n"; my $encrypted_data = $kerberos_creds->{'encrypted_data'}; print " encrypted_data: ", $encrypted_data, "\n"; my $sam = $kerberos_creds->{'sam'}; print " sam: ", $sam, "\n"; my $spn = $kerberos_creds->{'spn'}; print " spn: ", $spn, "\n"; my $version = $kerberos_creds->{'version'}; print " version: ", $version, "\n"; my $delegation = $kerberos_creds->{'delegation'}; print " delegation: ", $delegation, "\n"; } if (exists $cifs->{'dynamic_dns'}) { print " dynamic_dns:\n"; my @dynamic_dns = (); if (ref($cifs->{'dynamic_dns'}) eq "ARRAY") { @dynamic_dns = @{$cifs->{'dynamic_dns'}}; } else { @dynamic_dns = $cifs->{'dynamic_dns'}; } foreach my $dns (@dynamic_dns) { print " ", $dns, "\n"; } print "\n"; } my $signatures = $cifs->{'signatures'}; print " signatures: ", $signatures, "\n"; my $cifsEnable = $cifs->{'enable'}; print " enable: ", $cifsEnable, "\n"; if ($cifsEnable eq "true") { push(@cifsVirtualServices, $name); } } if (exists $virtualServiceConfig->{'nfs'}) { my $nfs = $virtualServiceConfig->{'nfs'}; print "nfs:\n"; my $nfsDescription = $nfs->{'description'}; print " description: ", $nfsDescription, "\n"; my $nlm = $nfs->{'nlm'}; print " nlm: ", $nlm, "\n"; if (exists $nfs->{'offline_behaviors'}) { print " offline_behaviors:\n"; my @offline_behaviors = (); if (ref($nfs->{'offline_behaviors'}) eq "ARRAY") { @offline_behaviors = @{$nfs->{'offline_behaviors'}}; } else { @offline_behaviors = $nfs->{'offline_behaviors'}; } foreach my $offline_behavior (@offline_behaviors) { my $namespace = $offline_behavior->{'namespace'}; print " namespace: ", $namespace, "\n"; my $volume = $offline_behavior->{'volume'}; print " volume: ", $volume, "\n"; my $path = $offline_behavior->{'path'}; print " path: ", $path, "\n"; my $deny_access = $offline_behavior->{'deny_access'}; print " deny_access: ", $deny_access, "\n"; print "\n"; } } my $nfsEnable = $nfs->{'enable'}; print " enable: ", $nfsEnable, "\n"; } my $enable = $virtualServiceConfig->{'enable'}; print "enable: ", $enable, "\n"; print "\n"; } print "Calling the \"get_status\" method of the ARX VirtualService interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get virtual service configuration from API # In addition to printing the list of virtual services, we can actually # use that list to retrieve status information for all of the virtual services # using the same list by calling get_status(). $virtualServiceSoapResult = $virtualServiceSoap->get_status(SOAP::Data->name('virtual_services')->value(@virtualServiceList), $securityHeader); if (defined $virtualServiceSoapResult->fault && $virtualServiceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($virtualServiceSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_status\" method of the ARX VirtualService interface.\n\n"; my @virtualServiceStatuses = ($virtualServiceSoapResult->result, $virtualServiceSoapResult->paramsout); foreach my $virtualServiceStatus (@virtualServiceStatuses) { my $name = $virtualServiceStatus->{'name'}; print "----------------------------------------------\n"; print "Virtual Service: ", $name, "\n"; print "----------------------------------------------\n\n"; print "name: ", $name, "\n"; my $cifs_state = $virtualServiceStatus->{'cifs_state'}; print "cifs_state: ", $cifs_state, "\n"; my $nfs_state = $virtualServiceStatus->{'nfs_state'}; print "nfs_state: ", $nfs_state, "\n"; if (exists $virtualServiceStatus->{'spn_statuses'}) { print "spn_statuses:\n"; my @spn_statuses = (); if (ref($virtualServiceStatus->{'spn_statuses'}) eq "ARRAY") { @spn_statuses = @{$virtualServiceStatus->{'spn_statuses'}}; } else { @spn_statuses = $virtualServiceStatus->{'spn_statuses'}; } foreach my $spn_status (@spn_statuses) { my $spnName = $spn_status->{'name'}; print " name: ", $spnName, "\n"; my $cifs_state = $spn_status->{'cifs_state'}; print " cifs_state: ", $cifs_state, "\n"; my $host_state = $spn_status->{'host_state'}; print " host_state: ", $host_state, "\n"; print "\n"; } } print "\n"; } if ($#cifsVirtualServices < 0) { print("The list of virtual services returned from the call to the \"get_list\" method of the ARX VirtualService interface did not contain any virtual services with CIFS enabled. The methods \"get_cifs_open_files\" and \"get_cifs_user_sessions\" of the ARX VirtualService interface will not be called.\n"); exit(0); } print "Calling the \"get_cifs_open_files\" method of the ARX VirtualService interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get virtual service configuration from API $virtualServiceSoapResult = $virtualServiceSoap->get_cifs_open_files(SOAP::Data->name('virtual_services')->value(@cifsVirtualServices), $securityHeader); if (defined $virtualServiceSoapResult->fault && $virtualServiceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($virtualServiceSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_cifs_open_files\" method of the ARX VirtualService interface.\n\n"; my @virtualServiceCifsOpenFiles = ($virtualServiceSoapResult->result, $virtualServiceSoapResult->paramsout); foreach my $virtualServiceCifsOpenFile (@virtualServiceCifsOpenFiles) { my $virtual_service = $virtualServiceCifsOpenFile->{'virtual_service'}; print "----------------------------------------------\n"; print "Virtual Service: ", $virtual_service, "\n"; print "----------------------------------------------\n\n"; print "virtual_service: ", $virtual_service, "\n"; if (exists $virtualServiceCifsOpenFile->{'open_files'}) { print "open_files:\n"; my @open_files = (); if (ref($virtualServiceCifsOpenFile->{'open_files'}) eq "ARRAY") { @open_files = @{$virtualServiceCifsOpenFile->{'open_files'}}; } else { @open_files = $virtualServiceCifsOpenFile->{'open_files'}; } foreach my $open_file (@open_files) { if (exists $open_file->{'proc'}) { my $proc = $open_file->{'proc'}; print " proc:\n"; my $slot = $proc->{'slot'}; print " slot: ", $slot, "\n"; my $processor = $proc->{'processor'}; print " processor: ", $processor, "\n"; } my $user_ip_address = $open_file->{'user_ip_address'}; print " user_ip_address: ", $user_ip_address, "\n"; my $user_name = $open_file->{'user_name'}; print " user_name: ", $user_name, "\n"; my $namespace = $open_file->{'namespace'}; print " namespace: ", $namespace, "\n"; my $virtual_path = $open_file->{'virtual_path'}; print " virtual_path: ", $virtual_path, "\n"; my $path_on_file_server = $open_file->{'path_on_file_server'}; print " path_on_file_server: ", $path_on_file_server, "\n"; my $read = $open_file->{'read'}; print " read: ", $read, "\n"; my $write = $open_file->{'write'}; print " write: ", $write, "\n"; my $fid = $open_file->{'fid'}; print " fid: ", $fid, "\n"; my $locks = $open_file->{'locks'}; print " locks: ", $locks, "\n"; my $virtual_ip_address = $open_file->{'virtual_ip_address'}; print " virtual_ip_address: ", $virtual_ip_address, "\n"; my $file_server_ip_address = $open_file->{'file_server_ip_address'}; print " file_server_ip_address: ", $file_server_ip_address, "\n"; my $virtual_share = $open_file->{'virtual_share'}; print " virtual_share: ", $virtual_share, "\n"; my $file_server_share = $open_file->{'file_server_share'}; print " file_server_share: ", $file_server_share, "\n"; print "\n"; } } print "\n"; } print "Calling the \"get_cifs_user_sessions\" method of the ARX VirtualService interface.\n\n"; # Build a security header $securityHeader = getSecurityHeader($user, $pass); # get virtual service configuration from API $virtualServiceSoapResult = $virtualServiceSoap->get_cifs_user_sessions(SOAP::Data->name('virtual_services')->value(@cifsVirtualServices), $securityHeader); if (defined $virtualServiceSoapResult->fault && $virtualServiceSoapResult->fault) { confess("SOAP request failed:\n" . objdump($virtualServiceSoapResult->fault) . "\n"); } print "Printing the results of the call to the \"get_cifs_user_sessions\" method of the ARX VirtualService interface.\n\n"; my @virtualServiceCifsUserSessions = ($virtualServiceSoapResult->result, $virtualServiceSoapResult->paramsout); foreach my $virtualServiceCifsUserSession (@virtualServiceCifsUserSessions) { my $virtual_service = $virtualServiceCifsUserSession->{'virtual_service'}; print "----------------------------------------------\n"; print "Virtual Service: ", $virtual_service, "\n"; print "----------------------------------------------\n\n"; print "virtual_service: ", $virtual_service, "\n"; if (exists $virtualServiceCifsUserSession->{'user_sessions'}) { print "user_sessions:\n"; my @user_sessions = (); if (ref($virtualServiceCifsUserSession->{'user_sessions'}) eq "ARRAY") { @user_sessions = @{$virtualServiceCifsUserSession->{'user_sessions'}}; } else { @user_sessions = $virtualServiceCifsUserSession->{'user_sessions'}; } foreach my $user_session (@user_sessions) { if (exists $user_session->{'proc'}) { my $proc = $user_session->{'proc'}; print " proc:\n"; my $slot = $proc->{'slot'}; print " slot: ", $slot, "\n"; my $processor = $proc->{'processor'}; print " processor: ", $processor, "\n"; } my $ip_address = $user_session->{'ip_address'}; print " ip_address: ", $ip_address, "\n"; my $auth = $user_session->{'auth'}; print " auth: ", $auth, "\n"; my $sign = $user_session->{'sign'}; print " sign: ", $sign, "\n"; my $age = $user_session->{'age'}; print " age: ", $age, "\n"; my $user_name = $user_session->{'user_name'}; print " user_name: ", $user_name, "\n"; print "\n"; } } print "\n"; } #------------------------------------------------------------------------------- # End of main program logic #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # sub usage #------------------------------------------------------------------------------- sub usage { print "\nUsage: ARXVirtualServiceExample.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; }325Views0likes0CommentsPerl 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 SOAP::Lite perl module An F5 ARX system running release V6.02.000 or later and configured with at least one volume. 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; }332Views0likes0Comments