Forum Discussion

fxt_31120's avatar
fxt_31120
Icon for Nimbostratus rankNimbostratus
Jul 04, 2012

How to find a Virtual server by ip+port

Hi everybody, I'm looking for a Icontrol cmdlet or a tips for search if my @ip+port is already used by a Virtual server. Right now I use a combo of 2 functions but it's not efficient at all (8 to 10 min): $exist_address=$false $list_virtual_server=$ic.LocalLBVirtualServer.get_list() for ($i=0 ; $i -lt $list_virtual_server.length; $i++) { $virtual_server_spec=$ic.LocalLBVirtualServer.get_destination($list_virtual_server[$i]) $virtual_server_address=$virtual_server_spec[0].address $virtual_server_port=$virtual_server_spec[0].port if (($virtual_server_address -eq $ServerAddress) -and ($virtual_server_port -eq $ServerPort)) { $exist_address=$true return $exist_address } } return $exist_address I know it's possible to be more efficient because the web interface provide this in 3-4 seconds in "Local Traffic" > "Network Map" > "Search" Any help ? :) Ps: Sorry for my english
  • Hi FXT,

     

     

    Everything is pretty much based on the Virtual Server Name, so you can call to get a list of Virtual Servers:

     

     

    iControl Virtual Server:

     

     

    string[] virtualServerList = f5Interface.LocalLBVirtualServer.get_list();

     

     

    You will need to iterate through the list providing the Virtual Server Names to get the destination information.

     

     

    iControl Virtual Server - Get Destination

     

     

    CommonIPPortDefinition[] getVirtualServerInfo = _f5Interface.LocalLBVirtualServer.get_destination(new[] {virtualServer});

     

     

    The CommonIPPortDefinition contains the the IP Address and the Port that you can compare against, so you can get both of the pieces of information that you are wanting with two queries (Virtual Server List and then Virtual Server Destination Information.

     

     

    iControl Common IP Port Definition.

     

     

    Hope this helps.
  • Something like this (python):

     
    def f5_virtual_server_exists(b, ip, port):
        log.debug("Entering f5_virtual_server_exists()...")
        log.debug("ip = %s" % ip)
        log.debug("port = %s" % port)
        vs_list = b.LocalLB.VirtualServer.get_list()
        for vs in vs_list:
            vs_dest = b.LocalLB.VirtualServer.get_destination([vs])[0]
            if (str(vs_dest.address) == ip) and (str(vs_dest.port) == port):
                log.debug("Returning True...")
                log.debug("Exiting f5_virtual_server_exists()...")
                return(True)
        log.debug("Returning False...")
        log.debug("Exiting f5_virtual_server_exists()...")
        return(False)