Forum Discussion
robertoq_79472
Nimbostratus
Sep 02, 2009Get ALL virtual server names?
Hi There,
Fairly new to using iControl. I've been going through the API reference and I don't seem to find a way to get a list of ALL the virtual servers currently on my LTM. I want to be able to get the full list and then the pool-names followed by their respective members and IPs.
Has anyone done this already?
14 Replies
- L4L7_53191
Nimbostratus
You'll want to use the get_list() method from the LocalLB.VirtualServer wsdl.
-Matt - L4L7_53191
Nimbostratus
Here's a specific sequence that may help.
1) Load LocalLB.VirtualServer and LocalLB.Pool classes/wsdls
2) build a list of virtual servers via get_list()
3) Get the default pools associated with them via get_default_pool_name(virtual_servers = your_virtual-server_list_here)
4) Get the pool members via LocalLB.Pool via get_member(pool_names = your_pool_list)
Good luck!
-Matt - rquezada, which language will you be using? Let me know and we can get you some sample code to help you out.
-Joe - In PowerShell, the code would look something like this:
$vs_list = (Get-F5.iControl).LocalLBVirtualServer.get_list() $pool_list = (Get-F5.iControl).LocalLBVirtualServer.get_default_pool_name($vs_list); $pool_members = (Get-F5.iControl).LocalLBPool.get_member($pool_list);
The logic will be similar in perl, .net, java, or python. - JRahm
Admin
In python shell, very similar:>>> import pycontrol.pyControl as pc >>> b = pc.BIGIP( ... hostname = 'x.x.x.x', ... username = 'admin', ... password = 'admin', ... wsdl_files = ['LocalLB.VirtualServer', 'LocalLB.Pool'] ... ) Loading WSDL: LocalLB.VirtualServer.wsdl Loading WSDL: LocalLB.Pool.wsdl >>> v = b.LocalLB_VirtualServer >>> p = b.LocalLB_Pool >>> vs_list = v.get_list()['return'] >>> pool_list = v.get_default_pool_name(virtual_servers = vs_list)['return'] >>> pool_members = p.get_member(pool_names = pool_list)['return'] - robertoq_79472
Nimbostratus
I was looking for a perl script example - jethro_106302
Nimbostratus
hey guys,
I ran into problems while using the Codeshare example you just mentionned.
Basically, this perl script will build a list of all VS declared (be them "standard" VS, Forwarding (L2 or IP) VS, etc..). These VS might not have a default pool assigned, and in such cases the perl script will end when receiving an error from iControl. You get the error as soon as you try to get_default_pool_name with an empty pool name.
To work around this issue, I rewrote most of this script to take that VS type problem into account. (see attachment to the post, but bear in mind that it's still Work In Progress, and I'm a very casual dev :p).
Now I still have two problems: 1/running this script against a redundant system with over 180 VS takes more than 3 minutes to complete. 2/ On systems with partitions, I only get to see infos from the Common Partition.
I'm still struggling with 2, get_partition_list doesn't seem to return the "All (read-only)" option that I have when using the Web UI. I hope this doesn't get off topic but if one of you has ideas on how I could mimic this "All (read-only)" feature with iControl, I'm interested.
Same thing for ideas on how to make this script run faster !
tia,
jethro - L4L7_53191
Nimbostratus
Jethro: You're taking a massive performance hit by looping through each VS and making discrete iControl calls for each piece of information you're after (e.g. get_enabled_state).
Instead, try and pass the entire VS list into the respective methods you're calling. This will make a huge difference performance wise. The return structure should be an ordered list of results that correspond to the VS list you passed in.
-Matt - jethro_106302
Nimbostratus
I agree making discrete iControl calls for each vs, pool, or pool member has an impact on performance.
get_enabled_state, get_destination, get_type, these could be called with the vs list as argument for sure.
I don't see how I can avoid doing this for the other calls without triggering the iControl error when calling pool related methods with an empty pool name (ie: for a forwarding VS).
How would you do that? (you don't have to give code examples, only the logic). - jethro_106302
Nimbostratus
I managed to make the script run in ~4s with this modification:get a list of all VS configured on the appliance my $soapResponse = $VirtualServer->get_list(); &checkResponse($soapResponse); my @bla = @{$soapResponse->result}; $soapResponse = $VirtualServer->get_type ( SOAP::Data->name(virtual_servers => [@bla]) ); my @vs_type = @{$soapResponse->result}; my @vs_list; for $i (0 .. scalar(@bla) -1) { switch ($vs_type[$i]) { case "RESOURCE_TYPE_POOL" { push @vs_list, $bla[$i]; } } }
now there is only my partition problem left, will keep you posted if I find a solution.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects