Forum Discussion

DevBabu_174449's avatar
Jan 30, 2015

How can i now get the value of pool member and port (iApps)

Presentation Section (Pool Member in Table)

presentation { include "/Common/f5.apl_common" section virtual_servers { row ip_port { string virtual_ip validator "IpAddress" string virtual_port validator "PortNumber" }

            }
            section pool_members {
                table pool_members_list {
                    string pool_ip validator "IpAddress"
                    string pool_port validator "PortNumber"
                }

            }
            text {
                virtual_servers "Virtual Server"
                virtual_servers.ip_port "Enter Destination and Port"
                virtual_servers.ip_port.virtual_ip "Destination IP address:"
                virtual_servers.ip_port.virtual_port "Port:"
                pool_members "Pool Members"
                pool_members.pool_members_list "Enter Pool Members:"
                pool_members.pool_members_list.pool_ip "IP address:"
                pool_members.pool_members_list.pool_port "Port:"

            }
        }

Implementation Section

        implementation {
            tmsh::log_dest file
            tmsh::log_level crit
            puts " "
            puts " "
            puts "Starting First template creation of virtual servers"
            set virtual_ip $::virtual_servers__ip_port__virtual_ip
            set virtual_port $::virtual_servers__ip_port__virtual_port
            puts $virtual_ip
            puts $virtual_port
            set pool $::pool_members__pool_members_list
            puts $pool

        }

puts $pool gives me output as:

{{ pool_ip 10.10.1.2 pool_port 443 }} {{ pool_ip 10.10.1.3 pool_port 443 }} {{ pool_ip 10.10.1.4 pool_port 443 }}

Now how can i loop to get the individual pool_ip and pool_port. is $pool a list. Please help. I am new and learning iApp and tcl.

5 Replies

  • This is what I use for managing pools:

    Presentation

    choice pool display "xxlarge" default "/create_new" tcl {
        package require iapp 1.1.0
        return "Create a new pool\t/create_new\n[iapp::get_items ltm pool]"
    }
    optional ( pool == "/create_new" ) {
         Build a table of pool members
        choice lb_method default "least-connections-member" display "xxlarge"
        choice monitor display "xxlarge" default "/create_new" tcl {
            package require iapp 1.1.0
            set choices "Create a new health monitor\t/create_new\n[iapp::get_items ltm monitor http]\n[iapp::get_items ltm monitor https]\n[iapp::get_items -filter NAME != "external" ltm monitor external]"
            return $choices
        }
        optional ( monitor == "/create_new" ) {
        string uri default "/"
        choice http_version display "xxlarge" default "http11"
        optional ( http_version == "http11" ) {
            string host required display "large" validator "FQDN"
        }
        string response display "xxlarge" default "200 OK"
        }
        table pool_members {
        editchoice addr display "large" tcl {
            package require iapp 1.1.0
            return [iapp::get_items ltm node]
        }
        string port display "small" required default "80" validator "PortNumber"
        }
    }
    

    Implementation

    set poolmembers ""
    if { $::global_config__pool == $::CREATE_NEW_ANSWER } {
         Monitor
        set new_monitor   [iapp::is ::global_config__monitor $::CREATE_NEW_ANSWER]
        set http10     [expr {[iapp::is ::global_config__http_version http10]}]
         array keys: $new_monitor,$http10
        array set monitor_arr {
        0,1 { $::global_config__monitor }
        0,0 { $::global_config__monitor }
        1,1 { [iapp::conf create ltm monitor http ${app}_monitor_http defaults-from http send 'GET $::global_config__uri HTTP/1.0\\r\\nConnection: Close\\r\\n\\r\\n' recv '$global_config__response' ] }
        1,0 { [iapp::conf create ltm monitor http ${app}_monitor_http defaults-from http send 'GET $::global_config__uri HTTP/1.1\\r\\nHost: $::global_config__host\\r\\nConnection: Close\\r\\n\\r\\n' recv '$global_config__response' ] }
        *     { }
        }
        set monitor [iapp::substa monitor_arr($new_monitor,$http10)]
        set poolmembers [iapp::pool_members $::global_config__pool_members]
        set pool [iapp::conf create ltm pool ${app}_pool monitor $monitor load-balancing-mode $::global_config__lb_method [iapp::pool_members $::global_config__pool_members] ]
    } else {
        set pool $::global_config__pool
    }
    

    To answer your question more specifically, you can use foreach to loop through the answers ( though that's the old way of doing iApps)

    foreach row $::pool_members__pool_members_list {
        array set columns [lindex $row 0]
        set ip $columns(pool_ip)
        set port $columns(pool_port)
    }
    
  • Fred_Slater_856's avatar
    Fred_Slater_856
    Historic F5 Account

    DebBabu- Pete's answer is great. Just for education, here is an example in pure Tcl without using the iapp package. Keep this reference handy: http://tmml.sourceforge.net/doc/tcl.

    [root@big84:Active:Standalone] ~  more example.tcl
    
    set myTable "{{ pool_ip 10.10.1.2 pool_port 443 }} {{ pool_ip 10.10.1.3 pool_port 443 }} {{ pool_ip 10.10.1.4 pool_port 443 }}"
    set myIpTag "pool_ip"
    set myPortTag "pool_port"
    
    foreach outerGroup $myTable {
        foreach innerGroup $outerGroup {
            array set x $innerGroup
            puts "IP $x($myIpTag) PORT $x($myPortTag)"
        }
    }
    [root@big84:Active:Standalone] ~  tclsh example.tcl
    IP 10.10.1.2 PORT 443
    IP 10.10.1.3 PORT 443
    IP 10.10.1.4 PORT 443
    [root@big84:Active:Standalone] ~