Forum Discussion
2 Replies
Sort By
- This code will create an IP Forwarding Virtual. You'll need to modify the code to change the virtual address, name, default_pool, and profiles.
!/usr/bin/perl ---------------------------------------------------------------------------- The contents of this file are subject to the iControl Public License Version 4.5 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.f5.com/. 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-2003 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. ---------------------------------------------------------------------------- use SOAP::Lite; ---------------------------------------------------------------------------- Validate Arguments ---------------------------------------------------------------------------- my $sHost = $ARGV[0]; my $sPort = $ARGV[1]; my $sUID = $ARGV[2]; my $sPWD = $ARGV[3]; my $sProtocol = "https"; if ( ("80" eq $sPort) or ("8080" eq $sPort) ) { $sProtocol = "http"; } sub usage() { die ("Usage: PoolMember.pl host port uid pwd ([pool] AND [enable|disable])\n"); } if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") ) { usage(); } ---------------------------------------------------------------------------- Transport Information ---------------------------------------------------------------------------- sub SOAP::Transport::HTTP::Client::get_basic_credentials { return "$sUID" => "$sPWD"; } $VirtualServer = SOAP::Lite -> uri('urn:iControl:LocalLB/VirtualServer') -> readable(1) -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi"); ---------------------------------------------------------------------------- Attempt to add auth headers to avoid dual-round trip ---------------------------------------------------------------------------- eval { $VirtualServer->transport->http_request->header ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '') ); }; ---------------------------------------------------------------------------- support for custom enum types ---------------------------------------------------------------------------- sub SOAP::Deserializer::typecast { my ($self, $value, $name, $attrs, $children, $type) = @_; my $retval = undef; if ( "{urn:iControl}Common.EnabledState" == $type ) { $retval = $value; } return $retval; } ---------------------------------------------------------------------------- Main logic ---------------------------------------------------------------------------- &createForwardingVirtual(); sub createForwardingVirtual() { $VirtualServerDefinition = { name => "my_forwarding_virtual", address => "90.90.90.90", port => "80", protocol => "PROTOCOL_TYPE_TCP" }; $wildmask = "255.255.255.255"; $VirtualServerResource = { type => "RESOURCE_TYPE_IP_FORWARDING", default_pool_name => "" }; $VirtualServerProfile = { profile_context => "PROFILE_CONTEXT_TYPE_ALL", profile_name => "" }; $soapResponse = $VirtualServer->create ( SOAP::Data->name(definitions => [$VirtualServerDefinition]), SOAP::Data->name(wildmasks => [$wildmask]), SOAP::Data->name(resources => [$VirtualServerResource]), SOAP::Data->name(profiles => [[$VirtualServerProfile]]) ); &checkResponse($soapResponse); print "Virtual Server Created!\n" } ---------------------------------------------------------------------------- checkResponse makes sure the error isn't a SOAP error ---------------------------------------------------------------------------- sub checkResponse() { my ($soapResponse) = (@_); if ( $soapResponse->fault ) { print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n"; exit(); } }
- Sorry to hear the code samples are hard to find, I'll have to try to do something about that. At least you like them when you find them B-).