perl
96 TopicsBIG-IP Configuration Conversion Scripts
Kirk Bauer, John Alam, and Pete White created a handful of perl and/or python scripts aimed at easing your migration from some of the “other guys” to BIG-IP.While they aren’t going to map every nook and cranny of the configurations to a BIG-IP feature, they will get you well along the way, taking out as much of the human error element as possible.Links to the codeshare articles below. Cisco ACE (perl) Cisco ACE via tmsh (perl) Cisco ACE (python) Cisco CSS (perl) Cisco CSS via tmsh (perl) Cisco CSM (perl) Citrix Netscaler (perl) Radware via tmsh (perl) Radware (python)1.7KViews1like13CommentsPerl 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; }347Views0likes0CommentsBIG-IQ Central Management API automation and programmability - BULK Discovery, Import and Re Import - Perl
Summary In conjunction with the announcement of BIG-IQ 5.0 we are excited to bring the field greater flexibility when centrally managing BIG-IP devices utilizing well defined workflows and the BIG-IQ iControl REST API. We understand that automation and programmability is becoming more the norm these days as the network is evolving into a software defined application aware environment. This article is an addendum to “BIG-IQ Central Management API automation and programmability – Python” and will demonstrate bulk device trust, discovery to populate resolver groups and import bigip configuration of many BIG-IP device as defined in a csv configuration file. This automation can be run as a standalone utilities that will run directly in the BIG-IQ shell for adding devices to inventory in a sequential yet automated fashion. API Reference Trust: https://'bigiq-ip'/mgmt/cm/global/tasks/device-trust Discovery: https://'bigiq-ip'/mgmt/cm/global/tasks/device-discovey Import: ADC - https://'bigiq-ip'/mgmt/cm/adc-core/tasks/declare-mgmt-authority Import: Firewall - https://'bigiq-ip'/mgmt/cm/firewall/tasks/declare-mgmt-authority Let’s get started – When using the BIG-IQ it is suggested to make a directory called scripts under /shared and securely copy this distribution into /shared/scripts/. Contents: ../config/bulk_discovery.csv ../src/perl/bulkDiscovery.pl ../src/perl/bulkReImport.pl Everything is predicated by a main loop which will invoke each task by calling supporting perl subroutines self-contained in the script. All rest calls, using curl (https://curl.haxx.se/), made are highlighted below. Establishment of device trust is completed in the main loop while the process of discovery and import configurations are completed in subroutine blocks within the script. #====================================================== # Main loop # Process trust, discovery, and imports #====================================================== for $bigip (@bigips) { my %postBodyHash = ("address"=>$bigiq, "userName"=>$user, "password"=>$pw,"clusterName"=>"", "useBigiqSync"=>"false", "name"=>"trust_$mip"); my $postBody = encode_json(\%postBodyHash); my $trustCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X POST -d \'$postBody\' https://localhost/mgmt/cm/global/tasks/device-trust"; if (discoverModules($bigiq, $machineId)) { if (importModules($bigiq)) { } } # upgrade the framework if nessasary if (handleFrameworkUpdade ($trustTask, $bigip)) { } } end of all devices #====================================================== # Discover specified modules. #====================================================== sub discoverModules { my %postBodyHash = ("moduleList" => \@moduleList, "status" => "STARTED"); # POST a new discovery task $postBodyHash{"deviceReference"}{"link"} = "cm/system/machineid-resolver/$machineId"; my $newDiscoverTaskCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X POST -d \'$postBodyJson\' \"https://localhost/mgmt/cm/global/tasks/device-discovery\""; } end of discoverModules #====================================================== # A subroutine for importing individual module. #====================================================== sub importModule { # POST a new import task $postBodyHash{"deviceReference"}{"link"} = "cm/system/machineid-resolver/$machineId"; my $postBody = encode_json(\%postBodyHash); my $newImportTaskCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X POST -d \'$postBodyJson\' \"$dmaUrl\""; # if we ecounter conflicts, we mark them to use BigIQ, patch the task back to started, and poll again if (($currentStep eq "PENDING_CONFLICTS") or ($currentStep eq "PENDING_CHILD_CONFLICTS")) if (resolveConflicts($mip, $module, $currentStep, $importSelfLink, @conflicts)) } # end of importModule #========================================================== # sub routine calling importModule to colocate all modules #========================================================== sub importModules { $ltmSuccess = importModule($mip, "ltm", "https://localhost/mgmt/cm/adc-core/tasks/declare-mgmt-authority", %postBodyHash); $asmSuccess = importModule($mip, "asm", "https://localhost/mgmt/cm/asm/tasks/declare-mgmt-authority", %postBodyHash); } And last but not least Re Import of BIGIP configuration objects for greater than one BIGIP device. This script can be run periodically based on Linux cron to ensure your device configurations managed by BIGIQ are up to date. On occasion other Element Management Systems could modify BIGIP object base and BIGIQ should be aware of these changes. If you refer to the below main loop, the discovery and import call's are the same. So two things actually happen that differs from inital bulk discovery and import. 1. Trust establishment is removed as it already contains mutaul certificate trust. 2. We test if the discovery and import tasks exists, if they do we can just PATCH discovery and import tasks to enforce a re import. That's about it. Refer to the code snippet below. #====================================================== # Main loop # Process Re Discovery, and Imports #====================================================== for $bigip (@bigips) { ## get the device properties my $deviceCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X GET https://localhost/mgmt/shared/resolver/device-groups/cm-bigip-allBigIpDevices/devices"; ## call disc routine using ip and machine id. if (discoverModules($bigiq, $machineId)) { ## call import routine using up and machine id. if (importModules($bigiq, $machineId)) } } } # end for devices Just to re iterate the above the discovery and import routines used for Re Import just PATCH the existing task created during inital discovery and import. Here are the PATCH requests. #====================================================== # Discover specified modules. #====================================================== sub discoverModules { ## get the discovery task based on the machineId my $findDiscoverTaskCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X GET \"https://localhost/mgmt/cm/global/tasks/device-discovery?\\\$filter=deviceReference/link+eq+\'*$machineId*\'+and+status+eq+\'FINISHED\'\""; ## If it exists PATCH the task if (defined $discoveryTask->{"items"}[0]) { # PATCH the existing discovery task my $discoveryTaskSelfLink = $discoveryTask->{"items"}[0]->{"selfLink"}; $postBodyJson = encode_json(\%postBodyHash); my $discoverCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X PATCH -d \'$postBodyJson\' $discoveryTaskSelfLink"; } #====================================================== # A subroutine for importing individual module. #====================================================== sub importModule { ## get import task based on the machineid my $findImportTaskCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X GET \"$dmaUrl?\\\$filter=deviceReference/link+eq+\'*$machineId*\'\""; ## If exists PATCH the task if (defined $findImportTask->{"items"}[0]) { # PATCH the existing import task $importTaskLink = $findImportTask->{"items"}[0]->{"selfLink"}; my $importCmd = "curl -s -k -u $bigiqCreds -H \"$contType\" -X PATCH -d \'$postBodyJson\' $importTaskLink"; } #======================================== # sub routine for calling importModule to collocate all modules. #======================================== sub importModules { $ltmSuccess = importModule($mip, $machineId, "ltm", "https://localhost/mgmt/cm/adc-core/tasks/declare-mgmt-authority", %postBodyHash); $asmSuccess = importModule($mip, machineId, "asm", "https://localhost/mgmt/cm/asm/tasks/declare-mgmt-authority", %postBodyHash); } If you are interested in this code for collaboration or solution, seach on key words "bigiq" "api" "python" or "perl" in code share section on dev central or here is the reference link: https://devcentral.f5.com/s/articles/big-iq-big-ip-rest-api-bulk-device-discovery-perl-972 We will also create a repository on github for easy accessability. Please visit us soon and often for periodic updates.1.3KViews0likes12CommentsARX 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; }331Views0likes0Comments