Build GTM Configuration
Problem this snippet solves:
Here's a way to create GTM configuration using a custom tmsh script. Note that this is a demonstration script and severely lacks error checking and thoroughness.
Code :
cli script test1.tcl { proc getFeedback { question } { puts -nonewline $question flush stdout return [gets stdin] } proc script::run {} { # Enable stateless so existing objects can be overwritten tmsh::stateless enabled #Build Datacenters set dc_count [getFeedback "How many datacenters do you wish to create? "] for {set x 0} {$x<$dc_count} {incr x} { lappend dc_names [getFeedback "Datacenter [expr {$x +1}] name? "] } tmsh::create /gtm datacenter $dc_names puts "\nDatacenters created...\n\n" #Build Servers set srv_count [getFeedback "How many servers are you adding? "] for {set x 0} {$x<$srv_count} {incr x} { set srv_name [getFeedback "Server [expr {$x +1}] Name? "] set srv_ip [getFeedback "Server [expr {$x +1}] IP? "] set srv_dc_loc [getFeedback "Datacenter server belongs to (tmsh::get_config /gtm datacenter)? "] set v_count [getFeedback "How mnay virtuals for $srv_name? "] for {set y 0} {$y<$v_count} {incr y} { lappend vmembers($srv_name) [getFeedback "Virtual Server [expr $y +1] IP:Port? "] } tmsh::create /gtm server $srv_name addresses add \{ \ $srv_ip \} monitor bigip datacenter $srv_dc_loc \ virtual-servers add \{ $vmembers($srv_name) \} } puts "\nServers created...\n\n" #Build Pools set pl_count [getFeedback "How many pools are you adding? "] for {set x 0} {$x<$pl_count} {incr x} { set pl_name [getFeedback "Pool [expr {$x +1}] name? "] set pm_count [getFeedback "How many pool members? "] for {set y 0} {$y<$pm_count} {incr y} { set pm_raw [getFeedback "Pool member [expr $y +1] IP:Port and ratio (Ex. 1.1.1.1:80 1)? "] set pm_value "[lindex [split $pm_raw " "] 0] \{ ratio [lindex [split $pm_raw " "] 1] \}" lappend pmembers($pl_name) $pm_value } foreach z $pmembers($pl_name) { append pmmod "$z " } tmsh::create /gtm pool $pl_name members add \{ $pmmod \} \ load-balancing-mode ratio verify-member-availability disabled } puts "\nPools created...\n\n" #Build WideIP set wip_name [getFeedback "WideIP Name? "] set wip_pl_count [getFeedback "How many pools? "] for {set x 0} {$x<$wip_pl_count} {incr x} { set pl_raw [getFeedback "Pool [expr {$x +1}] name a ratio (Ex. pool1 1)? "] set pl_value "[lindex [split $pl_raw " "] 0] \{ ratio [lindex [split $pl_raw " "] 1] \}" lappend wip_pools($wip_name) $pl_value } foreach z $wip_pools($wip_name) { append wipplmod "$z " } tmsh::create /gtm wideip $wip_name pool-lb-mode ratio pools add \{ $wipplmod \} \ persistence enabled ttl-persistence 300 rules add \{ testwip-rule \} puts "\nWideIP created, configuration is complete.\n\n" } }
Published Mar 10, 2015
Version 1.0CodeCentral_194
Cirrus
Joined May 05, 2019
CodeCentral_194
Cirrus
Joined May 05, 2019
No CommentsBe the first to comment