Forum Discussion

JRahm's avatar
JRahm
Icon for Admin rankAdmin
Jan 27, 2011

Object not displaying all fields

I'm using a proc from the wiki that prints fields:


proc print_fields { objVar } {
    upvar $objVar obj
    set fdx 0
    set fields [tmsh::get_field_names value $obj]
    set field_count [llength $fields]
    while { $fdx < $field_count } {
        set field [lindex $fields $fdx]
        puts "$field [tmsh::get_field_value $obj $field]"
        incr fdx
    }
}
proc script::run {} {
    foreach vip [tmsh::get_config /ltm virtual] {
            puts [tmsh::get_name $vip]
            print_fields vip
            puts "\n"
    }
}

When I run the script, I notice that not all my fields are present. For example, this vip when listed in tmsh:


root@golgotha(Active)(tmos) list ltm virtual cacti-vip
ltm virtual cacti-vip {
    connection-limit 1500
    destination 10.10.20.50:http
    ip-protocol tcp
    mask 255.255.255.255
    pool testpooln
    profiles {
        http { }
        tcp { }
    }
    rules {
        table_mgmt
        hashtest_distribution
    }
    snat automap
    translate-port disabled
}

Shows all the fields except the profiles:


root@golgotha(Active)(tmos) run cli script parttest.tcl
cacti-vip
connection-limit 1500
destination 10.10.20.50:http
ip-protocol tcp
mask 255.255.255.255
pool testpooln
rules table_mgmt hashtest_distribution
snat automap
translate-port disabled

Is there another process I need to follow for the profiles? Each of those objects looks to have its own {}, is that maybe throwing it off?

  • Mark_Crosland_2's avatar
    Mark_Crosland_2
    Historic F5 Account
    In the man page, help cli script, it talks about value fields and nested fields. Value fields are simple values or lists. A nested field (the missing profile list) can be used to retrieve nested objects. Nested objects also have fields, in this case the virtual/profile objects have a context field (clientside or serverside). Depending on the type of configuration, a nested object may also contain nested objects.

     

     

    proc script::run {} {

     

     

    tmsh::stateless enabled

     

    tmsh::create ltm virtual foo profiles replace-all-with "{ tcp http }"

     

     

    foreach vip [tmsh::get_config /ltm virtual foo all-properties] {

     

    foreach fld [tmsh::get_field_names value $vip] {

     

    puts "value field: $fld"

     

    }

     

    foreach fld [tmsh::get_field_names nested $vip] {

     

    puts "nested field: $fld"

     

    }

     

    foreach profile [tmsh::get_field_value $vip profiles] {

     

    puts "profile: [tmsh::get_name $profile]"

     

    foreach fld [tmsh::get_field_names value $profile] {

     

    puts " profile field: $fld: [tmsh::get_field_value $profile $fld]"

     

    }

     

    }

     

    }

     

    }

     

  • yeah, uh, RTFM has never been my strong suit. Sigh. Thanks Mark!
  • Mark_Crosland_2's avatar
    Mark_Crosland_2
    Historic F5 Account
    As a general rule, a man page can also be used to figure out which fields contain/represent nested objects in the scripting interface. Any field that is a list (i.e., has operations like add, delete, replace-all-with, none, ....) and has properties is a nested object. Using "help ltm virtual" as an example, the profiles field is a list of profiles that also has a context property, so profiles are presented as nested objects in the scripting interface. Whereas the the vlans setting is a list of vlan names, but there are no configurable properties, so it is a simple list, and not a nested object.
  • That's really useful info Mark. I was struggling through this last week. Thanks for the tips.

     

     

    Aaron
  • Very good information, helped me a request this morning putting wideIP info into csv format:

    
    proc script::run {} {
        foreach wip [tmsh::get_config \gtm wideip] {
            append csvline "[tmsh::get_name $wip],"
            foreach pl [tmsh::get_field_value $wip pools] {
                append csvline "[tmsh::get_name $pl],"
                foreach pm [tmsh::get_config \gtm pool] {
                    if { [tmsh::get_name $pl] == [tmsh::get_name $pm] } {
                        foreach fld [tmsh::get_field_value $pm members] {
                            append csvline "[tmsh::get_name $fld],"
                        }
                    }
                }
            }
            puts "$csvline"
            unset csvline
        }
    }
    

    Output:

    root@6400-1(Active)(tmos) run cli script getwips.tcl

    testwip1.test,testpool1,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,testpool2,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,testpool3,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,

    testwip2.test,testpool1,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,testpool2,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,testpool3,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,

    testwip3.test,testpool1,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,testpool2,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,testpool3,1.1.1.1:http,1.1.1.2:http,1.1.1.3:http,