icontrol ruby library
21 TopicsHow to get the applications Assigned to a Web Acceleration Profile? (Possible API Bug)
I am trying to work out the applications a specific web acceleration profile are connected to. I am using the soap interface (ruby gem) When I make a get_application request from Soap Documentation: interfaces['LocalLB.ProfileWebAcceleration'].get_application(["/MYPARTITION/my_app_cache_profile"]) I get an empty response object: [] I would expect this to contain "/MYPARTITION/my_app.app" Verification (Profile is connected) I can confirm that this profile is connected to an app (by looking for it from the app): system_session.get_active_folder "/MYPARTITION/my_app.app" interfaces['LocalLB.ProfileWebAcceleration'].get_list ["/MYPARTITION/my_app.app/my_app_cache_profile"] NB: This does not help me as if you apply a profile to an app after creation the path is "/MYPARTITION/my_app_cache_profile" so running get_list on the app path will return 0 results even though there is a caching profile assigned.278Views0likes1CommentRuby iControl throwing non-descript soap fault on NodeAddressV2.create
So I'm receiving a soap fault when I try and create a node. If anyone could help me out with a diagnosis I'd really appreciate it!! bigip = F5::IControl.new('*******', '*******', '*******', ['LocalLB.Pool', 'LocalLB.NodeAddressV2']) interfaces = bigip.get_interfaces interfaces['LocalLB.NodeAddressV2'].create ['test'], ['test.test.com'], [0] Throws the error: SOAP::FaultError: Exception caught in LocalLB::urn:iControl:LocalLB/NodeAddressV2::create() Common::InvalidArgument252Views0likes1CommentiControl EM Proxy Issues
Hi All, Trying to use the ruby f5-icontrol library to interact with Enterprise Manager's iControl proxy capability. So far I have had little luck. I have the following script, and it is functional in returning info from EM, except for when I attempt to run the get_context_id method. require 'f5-icontrol' require 'pp' wsdls = ['Management.EM'] b = F5::IControl.new('myem', 'admin', 'thepassword', wsdls).get_interfaces l = {} l['devices'] = b['Management.EM'].get_devices() l['context'] = b['Management.EM'].get_context_id() pp l This results in the following error: /usr/share/ruby/rexml/parsers/baseparser.rb:411:in `block in pull_event': Undefined prefix E found (REXML::UndefinedNamespaceException) from /usr/share/ruby/set.rb:232:in `each_key' from /usr/share/ruby/set.rb:232:in `each' from /usr/share/ruby/rexml/parsers/baseparser.rb:409:in `pull_event' from /usr/share/ruby/rexml/parsers/baseparser.rb:183:in `pull' from /usr/share/ruby/rexml/parsers/streamparser.rb:16:in `parse' from /usr/share/ruby/rexml/document.rb:243:in `parse_stream' from /usr/local/share/gems/gems/soap2r-1.5.8/lib/xsd/xmlparser/rexmlparser.rb:27:in `do_parse' from /usr/local/share/gems/gems/soap2r-1.5.8/lib/soap/parser.rb:102:in `parse' from /usr/local/share/gems/gems/soap2r-1.5.8/lib/soap/processor.rb:39:in `unmarshal' from /usr/local/share/gems/gems/soap2r-1.5.8/lib/soap/rpc/proxy.rb:291:in `unmarshal' from /usr/local/share/gems/gems/soap2r-1.5.8/lib/soap/rpc/proxy.rb:190:in `route' from /usr/local/share/gems/gems/soap2r-1.5.8/lib/soap/rpc/proxy.rb:149:in `call' from /usr/local/share/gems/gems/soap2r-1.5.8/lib/soap/rpc/driver.rb:151:in `call' from (eval):6:in `get_context_id' from em2.rb:11:in `' I'm running ruby 2.0.0p247, EM 3.1.1 (40.7), and have tried f5-icontrol gems for v11.3.0 and v11.4.1. Any ideas? Thanks.360Views0likes1CommentAPI Convetion confusions
Consider the following. ltm = F5::IControl.new(ltm_name, username, password, ["LocalLB.VirtualServer"]).get_interfaces["LocalLB.VirtualServer"] ltm.add_rule(["temp_vserver"], [[{:rule_name => "new_rule, :priority => 3}]]) The irule object/hash is imbedded in two arrays. The API is shown here. in LocalLB__VirtualServer__VirtualServerRule [] [] rules In referncing the API documentation how am I to know that the irule object should be imbedded in two arrays? It makes sense to me that the irule object is in a hash corresponding with the struct defined in the API. {:rule_name => "new_rule", :priority => 3} It also makes sense to me that this object is inside of an array, since you may want to add multiple rules at the same time. [{:rule_name => "new_rule", :priority => 3}, {:rule_name => "other_new_rule", :priority => 4}] What I don't get is why all of this is embedded in yet another array and I also don't see how I am supposed to tell this from the API. I figured this out by reading others code on the devcentral codeshare.393Views0likes6CommentsF5 LTM SOAP API - Ruby f5-icontrol Gem - Could not find element by name: pool_names
Hi there, Very much hoping there is someone that can help me with this problem. I am trying to gather some information about pool members from the F5 API (still on SOAP for a little while more). I am using the f5-icontrol Gem described here: http://www.rubydoc.info/gems/f5-icontrol/0.1.5 Specifically, I am trying to call the LocalLB.Pool.get_all_member_statistics method passing in a string of the pool name and receive the following error: /full/path/ruby-2.1.6/gems/savon-2.11.1/lib/savon/response.rb:85:in `raise_soap_and_http_errors!': (SOAP-ENV:Server) **Could not find element by name: pool_names** (Savon::SOAPFault) I am able to run a number of other methods and get back data, for example I can run api.LocalLB.Pool.get_list & api.Management.UserManagement.get_my_permission() and data is returned immediately. Also, the string I am passing in to get_all_member_statistics is the exact string returned by api.LocalLB.Pool.get_list. Note that I tried running as a normal user as well as an F5 admin. Here is my exact code: require 'f5-icontrol' F5::Icontrol.configure do |f| f.host = "big-ip-url.domain.com" f.username = "user" f.password = "pass" end api = F5::Icontrol::API.new get_list runs perfectly and returns all of the pool names in the format of "/Common/full_pool_name" for example response = api.LocalLB.Pool.get_list This successfully returns the permissions for the current user response = api.Management.UserManagement.get_my_permission() This is NOT working and returns the error above response = api.LocalLB.Pool.get_all_member_statistics("Common/full_pool_name_exactly_as_it_appears_in_the_UI") puts response.inspect481Views0likes4Commentsf5-icontrol-10.2.0.2 gem causing various warnings with ruby 1.9.3
Hi, Installed the gem, and get had to do the following workarounds... ruby /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/f5-icontrol-10.2.0.2/examples/get-version.rb 192.168.1.1 admin admin /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- soap/wsdlDriver (LoadError) from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/f5-icontrol-10.2.0.2/lib/f5-icontrol.rb:2:in `' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require' from /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/f5-icontrol-10.2.0.2/examples/get-version.rb:4:in `' To get round this, I did the following:- gem install soap4r Try again:- ruby /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/f5-icontrol-10.2.0.2/examples/get-version.rb 192.168.1.1 admin admin /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/xsd/charset.rb:13: warning: variable $KCODE is no longer effective /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': iconv will be deprecated in the future, use Stringencode instead. /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/xsd/xmlparser.rb:74:in `': XML processor module not found. (RuntimeError) from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/wsdl/parser.rb:12:in `' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/wsdlDriver.rb:9:in `' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require' from /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/f5-icontrol-10.2.0.2/lib/f5-icontrol.rb:2:in `' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require' from /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require' from /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/f5-icontrol-10.2.0.2/examples/get-version.rb:4:in `' To get round this error, I followed the code here:- http://railsforum.com/viewtopic.php?id=41231 Essentially, changed, line 66 in file /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/xsd/xmlparser.rb before: c.downcase == name After c.to_s.downcase == name This solves the above problem, but now I get all sorts of warnings..... ruby /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/f5-icontrol-10.2.0.2/examples/get-version.rb 192.168.1.1 admin admin /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/xsd/charset.rb:13: warning: variable $KCODE is no longer effective /home/elastic/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': iconv will be deprecated in the future, use Stringencode instead. /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/property.rb:68: warning: encoding option is ignored - u /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/property.rb:69: warning: encoding option is ignored - u /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/property.rb:70: warning: encoding option is ignored - u /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/rpc/element.rb:226: warning: Hashindex is deprecated; use Hashkey /home/elastic/.rvm/gems/ruby-1.9.3-p194/gems/soap4r-1.5.8/lib/soap/generator.rb:276: warning: encoding option is ignored - UTF8 BIG-IP_v11.1.0 Hei, it works, but would be nice id someone could update the gem to fix all of the above and release a new version? thanks Sc0tt....609Views0likes5CommentsAutomated Nagios monitoring for F5 BigIP devices
Problem this snippet solves: Complete Nagios solution for automated monitoring of F5 BigIP using API & SNMP in Ruby. Generates Nagios config automatically. How to use this snippet: Readme here: https://github.com/anordby/plugins/blob/master/nagios/f5/README.md Ideally I would have this code linked up as Ruby code sample on these pages: https://devcentral.f5.com/wiki/iControl.System__Session.ashx https://devcentral.f5.com/wiki/iControl.System__Failover__get_failover_state.ashx https://devcentral.f5.com/wiki/iControl.System__Session__get_active_folder.ashx https://devcentral.f5.com/wiki/iControl.System__Session__set_active_folder.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__Pool.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__Pool__get_list.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__Pool__get_object_status.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__Pool__get_member_v2.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__Pool__get_member_object_status.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__VirtualServer.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__VirtualServer__get_list.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__VirtualServer__get_object_status.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_list.ashx https://devcentral.f5.com/wiki/iControl.LocalLB__NodeAddressV2__get_object_status.ashx Code : https://github.com/anordby/plugins/tree/master/nagios/f5411Views0likes0CommentsNodeInitiator
Problem this snippet solves: This will add a member to a pool on a BIG-IP. This script was written for use in the F5-node-initiator cookbook for Opscode Chef. Automating-Web-App-Deployments-with-Opscode-Chef-and-iControl.aspx How to use this snippet: Requirements Ruby Ruby Gems F5 iControl for Ruby library (Getting-Started-With-Ruby-and-iControl.aspx) other dependencies will be installed with the iControl gem Installation Steps Install Ruby, Ruby Gems, and the Ruby iControl libraries Getting-Started-With-Ruby-and-iControl.aspx Copy this code to /usr/local/bin and chmod +x to make the script executable Run it! f5-node-initiator -b 192.168.1.245 -u admin -p admin -n my_test_pool -d 10.0.0.10:80 Code : #!/usr/bin/ruby # # == Synopsis # # f5-node-initiator - Quickly add nodes to pools # # == Usage # # f5-node-initiator [OPTIONS] # # -h, --help: # show help # # --bigip-address, -b [hostname]: # specify the destination BIG-IP for virtual and pool creation # # --bigip-user, -u [username]: # username for destination BIG-IP # # --bigip-pass, -p [password]: # password for destination BIG-IP # # --pool-name, -n [name]: # name of pool to add node to # # --node-definition, -d [ip address:port]: # definition for node being added to pool, example: 10.2.1.1:443 require 'rubygems' require 'f5-icontrol' require 'getoptlong' require 'rdoc/usage' options = GetoptLong.new( [ '--bigip-address', '-b', GetoptLong::REQUIRED_ARGUMENT ], [ '--bigip-user', '-u', GetoptLong::REQUIRED_ARGUMENT ], [ '--bigip-pass', '-p', GetoptLong::REQUIRED_ARGUMENT ], [ '--pool-name', '-n', GetoptLong::REQUIRED_ARGUMENT ], [ '--node-definition', '-d', GetoptLong::REQUIRED_ARGUMENT ], [ '--help', '-h', GetoptLong::NO_ARGUMENT ] ) bigip_address = '' bigip_user = '' bigip_pass = '' pool_name = '' node_address = '' node_port = 80 options.each do |option, arg| case option when '--bigip-address' bigip_address = arg when '--bigip-user' bigip_user = arg when '--bigip-pass' bigip_pass = arg when '--pool-name' pool_name = arg when '--node-definition' if arg =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+/ node_address = arg.split(':')[0] node_port = arg.split(':')[1] end when '--help' RDoc::usage end end RDoc::usage if bigip_address.empty? or bigip_user.empty? or bigip_pass.empty? or pool_name.empty? or node_address.empty? # Initiate SOAP RPC connection to BIG-IP bigip = F5::IControl.new(bigip_address, bigip_user, bigip_pass, ['LocalLB.Pool']).get_interfaces # Insure that target pool exists unless bigip['LocalLB.Pool'].get_list.include? pool_name puts 'ERROR: target pool "' + pool_name +'" does not exist' exit 1 end # collect list of existing pool member definitions pool_members = bigip['LocalLB.Pool'].get_member([ pool_name ])[0].collect do |pool_member| pool_member['address'] + ':' + pool_member['port'].to_s end # don't attempt to add member if it already exists unless pool_members.include?(node_address + ':' + node_port.to_s) bigip['LocalLB.Pool'].add_member([ pool_name ], [[{ 'address' => node_address, 'port' => node_port.to_i }]]) end236Views0likes0CommentsCreate Maintenance Page iRule
Problem this snippet solves: This is a script will generate an iRule that will display a maintenance page to users when attached to a virtual server. If the iRule already exists, it can be updated from the script. If a virtual server is specified, the iRule will be applied to it. As a result, the virtual will immediately be shunted to the maintenance page. How to use this snippet: Requirements Ruby Ruby Gems F5 iControl for Ruby library other dependencies will be installed with the iControl gem Installation Steps Install Ruby, Ruby's OpenSSL library, Ruby Gems, and the Ruby iControl libraries Copy this code to /usr/local/bin and chmod +x to make the script executable Run it! create-maintenace-page-irule.rb -b 192.168.1.245 -u admin -p admin -f www.mysite.com-maintenance.html -v mymaintenancevirtual Code : #!/usr/bin/ruby require "rubygems" require "f5-icontrol" require "getoptlong" options = GetoptLong.new( [ "--bigip-address", "-b", GetoptLong::REQUIRED_ARGUMENT ], [ "--bigip-user", "-u", GetoptLong::REQUIRED_ARGUMENT ], [ "--bigip-pass", "-p", GetoptLong::REQUIRED_ARGUMENT ], [ "--html-file", "-f", GetoptLong::REQUIRED_ARGUMENT ], [ "--maintenance-vs", "-v", GetoptLong::OPTIONAL_ARGUMENT ], [ "--irule-name", "-n", GetoptLong::OPTIONAL_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ] ) def usage puts $0 + " -b -u -f " puts " -b (--bigip-address) BIG-IP management-accessible address)" puts " -u (--bigip-user) BIG-IP username" puts " -p (--bigip-pass) BIG-IP password (will prompt if left blank" puts " -f (--html-file) source HTML file for maintenance page" puts " -v (--maintenance-vs) virtual server to apply maintenance page (will immediiately put virtual server in maintenance mode)" puts " -n (--irule-name) name of maintenance iRule (defaults to maintenance_page_)" puts " -h (--help) shows this help/usage dialog" exit end # initial parameter values bigip_address = '' bigip_user = '' bigip_pass = '' maintenance_html_file = '' maintenance_vs = '' maintenance_irule_name = '' options.each do |option, arg| case option when "--bigip-address" bigip_address = arg when "--bigip-user" bigip_user = arg when "--bigip-pass" bigip_pass = arg when "--html-file" maintenance_html_file = arg when "--maintenance-vs" maintenance_vs = arg when "--irule-name" maintenance_irule_name = arg when "--help" usage end end # at the very least, the user should provide be BIG-IP address and username usage if bigip_address.empty? or bigip_user.empty? or maintenance_html_file.empty? # make sure that the maintenance page source HTML file exists, if not display error and exit unless File.exists? maintenance_html_file puts "Error: #{maintenance_html_file} could not be located. Check the path and try again." exit 1 end # if no iRule name is specified, built the default if maintenance_irule_name.empty? maintenance_irule_name = "maintenance_page_#{File.basename(maintenance_html_file).gsub('.', '_')}" end # if no BIG-IP password is provided, prompt for it if bigip_pass.empty? puts "Please enter the BIG-IPs password..." print "Password: " system("stty", "-echo") bigip_pass = gets.chomp system("stty", "echo") end # create iControl interfaces bigip = F5::IControl.new(bigip_address, bigip_user, bigip_pass, ["LocalLB.VirtualServer", "LocalLB.Rule"]).get_interfaces puts "Connected to BIG-IP at #{bigip_address} with user '#{bigip_user}'..." puts # ensure that that virtual server exists before proceeding unless maintenance_vs.empty? unless bigip["LocalLB.VirtualServer"].get_list.include? maintenance_vs puts "Error: virtual server '#{maintenance_vs}' could not be located on BIG-IP" exit end end maintenance_irule = "priority 1\n\nwhen HTTP_REQUEST {\n HTTP::respond 200 content {#{File.read(maintenance_html_file)}}\n}" irule_definition = {"rule_name" => maintenance_irule_name, "rule_definition" => maintenance_irule} if bigip["LocalLB.Rule"].get_list.include? maintenance_irule_name puts "An iRule named '#{maintenance_irule_name}' already exists. Would you like to replace it? (yes/no)" answer = gets if answer == "yes\n" puts "Updating '#{maintenance_irule_name}' on BIG-IP..." bigip["LocalLB.Rule"].modify_rule([irule_definition]) else puts "Nothing to do. Exiting..." exit end else puts "Creating iRule '#{maintenance_irule_name}' on BIG-IP..." bigip["LocalLB.Rule"].create([irule_definition]) end # assemble a list of iRules already assigned to virtual server vs_irules = [] bigip["LocalLB.VirtualServer"].get_rule(maintenance_vs)[0].each { |irule| vs_irules << irule['rule_name'] } unless maintenance_vs.empty? unless maintenance_vs.empty? or vs_irules.include? maintenance_irule_name puts "Are you absolutely sure that you want to enable the maintenance iRule for virtual server '#{maintenance_vs}'? (yes/no)" answer = gets if answer == "yes\n" puts "Applying maintenance page iRule to virtual server '#{maintenance_vs}'..." bigip["LocalLB.VirtualServer"].add_rule([maintenance_vs], [[{"rule_name" => maintenance_irule_name, "priority" => 1}]]) end end puts "Done!"579Views0likes0Comments