bigsuds
33 Topicspython bigsuds - Get Orphaned iRules
Problem this snippet solves: This python bigsuds script will get a list of all iRules that are not associated with a virtual server (orphaned). How to use this snippet: orphanedrules.py <hostname> <username> Script will prompt for password. Script orphanedrules.py Code : #!/usr/bin/env python __author__ = 'buzzsurfr' __version__ = '0.1' def get_orphaned_rules(obj, recursive = True): ''' Gets a list of orphaned rules. Prototype String [] get_orphaned_rules( BIGIP.bigip obj, bool recursive = True ); Parameters obj of type BIGIP.bigip contains the established connection. recursive of type boolean indicates whether to perform a recursive search throughout the entire configuration. Defaults to True. Return Type String [] containing the list of all orphaned rules. ''' # Get current values to override for search active_folder = obj.System.Session.get_active_folder() recursive_query_state = obj.System.Session.get_recursive_query_state() # Enable fully-recursive search if recursive: obj.System.Session.set_active_folder('/') obj.System.Session.set_recursive_query_state("STATE_ENABLED") # Get list of iRules rules = obj.LocalLB.Rule.get_list() # Create starting list of orphaned iRules. These will be removed from # list as they are found to be in use. orphaned_rules = rules # Get list of all iRules associated on virtual servers vs_rules = obj.LocalLB.VirtualServer.get_rule(obj.LocalLB.VirtualServer.get_list()) # Check each virtual server for iRules and remove from orphaned if exists for virtual_server in vs_rules: for rule in virtual_server: if rule['rule_name'] in rules: # If found, remove from orphaned_rules orphaned_rules.remove(rule['rule_name']) # Reset values overridden for search if recursive: obj.System.Session.set_active_folder(active_folder) obj.System.Session.set_recursive_query_state(recursive_query_state) return orphaned_rules # Instance Mode (Run as script) if __name__ == "__main__": # Standard Library import sys # Related Third-Party import getpass # Local Application/Library Specific import bigsuds if len(sys.argv) < 3: print "\n\n\tUsage: %s ip_address username" % sys.argv[0] sys.exit() # Get password from CLI userpass = getpass.getpass() # Connect to BIG-IP try: bigconn = bigsuds.BIGIP( hostname = sys.argv[1], username = sys.argv[2], password = userpass ) except Exception as e: print e orphans = get_orphaned_rules(bigconn) print "Orphaned iRules" for orphan in orphans: print "\t" + orphan Tested this on version: 11.5198Views0likes0Commentspython bigsuds - Reverse Lookup (Node -> Pool)
Problem this snippet solves: This python bigsuds script prints the list of pools using a specific node. How to use this snippet: rlookup-node.py <hostname> <username> <nodename> This will only search the Common partition. Code : #!/usr/bin/env python __author__ = 'buzzsurfr' __version__ = '0.1' # Standard Library import sys import re # Related Third-Party import getpass # Local Application/Library Specific import bigsuds if len(sys.argv) < 4: print "\n\n\tUsage: %s host user node" % sys.argv[0] sys.exit() # Get login password from CLI userpass = getpass.getpass() # Connect to BIG-IP b = bigsuds.BIGIP(sys.argv[1], sys.argv[2], userpass) # Get list of pools and pool members pools = b.LocalLB.Pool.get_list() pool_members = b.LocalLB.Pool.get_member_v2(pools) # Node to search for node = sys.argv[3] if len(node) < 8 or node[:8] != '/Common/': node = '/Common/'+node print "Pools using Node "+node # Iterate through pool member list (has a list of members per pool referenced) looking for node for i, pool in enumerate(pool_members): for member in pool: if node == member['address']: print "\t"+pools[i] Tested this on version: 11.5192Views0likes0Commentspython bigsuds - Reverse Lookup (Pool -> Virtual Server)
Problem this snippet solves: This python bigsuds script prints the list of virtual servers using a specific pool. How to use this snippet: rlookup-pool.py <hostname> <username> <poolname> This will only search the Common partition. This also does not check for policies or iRules that may change the value of pool. Code : #!/usr/bin/env python __author__ = 'buzzsurfr' __version__ = '0.1' # Standard Library import sys import re # Related Third-Party import getpass # Local Application/Library Specific import bigsuds if len(sys.argv) < 4: print "\n\n\tUsage: %s host user pool" % sys.argv[0] sys.exit() # Get login password from CLI userpass = getpass.getpass() # Connect to BIG-IP b = bigsuds.BIGIP(sys.argv[1], sys.argv[2], userpass) pool = sys.argv[3] if len(pool) < 8 or pool[:8] != '/Common/': pool = '/Common/'+pool print "Virtual Servers using Pool "+pool # Get list of pools and pool members virtual_servers = b.LocalLB.VirtualServer.get_list() vs_pools = b.LocalLB.VirtualServer.get_default_pool_name(virtual_servers) # Iterate through pool member list (has a list of members per pool referenced) looking for node for i, vs_pool in enumerate(vs_pools): if pool == vs_pool: print "\t"+virtual_servers[i] Tested this on version: 11.5231Views0likes0Commentspython bigsuds - Device Certificate Info
Problem this snippet solves: This python bigsuds script prints device certificate information from multiple devices specified as arguments. The script accepts multiple hostnames or IP addresses and can be passed from stdin. How to use this snippet: Single host cert-device.py <username> <hostname> Multiple hosts cert-device.py <username> <hostname1> <hostname2> Pass from File (Linux) cat bigip-hosts | xargs cert-device.py <username> Code : #!/usr/bin/env python __author__ = 'buzzsurfr' __version__ = '0.1' def get_device_certificate(api): ''' Gets device certificate information from multiple F5 BIG-IP devices. Prototype dict get_device_certificate( BIGIP.bigip api, ); Parameters api of type BIGIP.bigip contains the established connection. Return Type dict containing the certificate properties. ''' return api.Management.KeyCertificate.get_certificate_list_v2('MANAGEMENT_MODE_WEBSERVER')[0]['certificate'] # Standard Library import sys import re # Related Third-Party import getpass # Local Application/Library Specific import bigsuds if len(sys.argv) < 3: print "\n\n\tUsage: %s user host ..." % sys.argv[0] sys.exit() # Get login password from CLI userpass = getpass.getpass() # Store results in variables for all hosts as dict result = {} # Iterate over hosts for host in sys.argv[2:]: # Connect to BIG-IP api = bigsuds.BIGIP(host, sys.argv[1], userpass) api = api.with_session_id() result[host] = get_device_certificate(api) # Get console output column widths space = 2 columns = {} columns['host'] = max([len(host) for host in result]) columns['subject'] = max([len(cert['subject']['common_name']) for cert in result.values()]) columns['issuer'] = max([len(cert['issuer']['common_name']) for cert in result.values()]) columns['bit_length'] = 4 columns['expiration_string'] = max([len(cert['expiration_string']) for cert in result.values()]) print_string = "%-"+str(columns['host'])+"s"+(' '*space)+\ "%-"+str(columns['subject'])+"s"+(' '*space)+\ "%-"+str(columns['issuer'])+"s"+(' '*space)+\ "%"+str(columns['bit_length'])+"s"+(' '*space)+\ "%-"+str(columns['expiration_string'])+"s" # Output to console print print_string % ("Host", "Subject", "Issuer", "Bits", "Expiration Date") print print_string % ('='*columns['host'], '='*columns['subject'], '='*columns['issuer'], '====', '='*columns['expiration_string']) for host, certificate in result.iteritems(): print print_string % (host, certificate['subject']['common_name'], certificate['issuer']['common_name'], str(certificate['bit_length']), certificate['expiration_string']) Tested this on version: 11.5251Views0likes0Commentspython bigsuds - Profile Certificate Info
Problem this snippet solves: This python bigsuds script prints profile certificate information from multiple devices specified as arguments. The script accepts multiple hostnames or IP addresses and can be passed from stdin. How to use this snippet: Single host cert-profile.py <username> <hostname> Multiple hosts cert-profile.py <username> <hostname1> <hostname2> Pass from File (Linux) cat bigip-hosts | xargs cert-profile.py <username> Code : #!/usr/bin/env python __author__ = 'buzzsurfr' __version__ = '0.1' def get_profile_certificate(api): ''' Gets profile certificate information from multiple F5 BIG-IP devices. Prototype dict get_profile_certificate( BIGIP.bigip api, ); Parameters api of type BIGIP.bigip contains the established connection. Return Type dict containing the certificate properties. ''' return api.Management.KeyCertificate.get_certificate_list_v2('MANAGEMENT_MODE_DEFAULT') # Standard Library import sys import re # Related Third-Party import getpass # Local Application/Library Specific import bigsuds if len(sys.argv) < 3: print "\n\n\tUsage: %s user host ..." % sys.argv[0] sys.exit() # Get login password from CLI userpass = getpass.getpass() # Store results in variables for all hosts as dict result = [] # Iterate over hosts for host in sys.argv[2:]: # Connect to BIG-IP api = bigsuds.BIGIP(host, sys.argv[1], userpass) api = api.with_session_id() certs = get_profile_certificate(api) for cert in certs: cert['certificate']['host'] = host result.append(cert['certificate']) # Get console output column widths space = 2 columns = {} columns['host'] = max([len(cert['host']) for cert in result]) columns['id'] = max([len(cert['cert_info']['id']) for cert in result]) columns['subject'] = max([len(cert['subject']['common_name']) for cert in result if cert['subject']['common_name'] is not None]) columns['issuer'] = max([len(cert['issuer']['common_name']) for cert in result if cert['issuer']['common_name'] is not None]) columns['bit_length'] = 4 columns['expiration_string'] = max([len(cert['expiration_string']) for cert in result]) print_string = "%-"+str(columns['host'])+"s"+(' '*space)+\ "%-"+str(columns['id'])+"s"+(' '*space)+\ "%-"+str(columns['subject'])+"s"+(' '*space)+\ "%-"+str(columns['issuer'])+"s"+(' '*space)+\ "%"+str(columns['bit_length'])+"s"+(' '*space)+\ "%-"+str(columns['expiration_string'])+"s" # Output to console print print_string % ("Host", "ID", "Subject", "Issuer", "Bits", "Expiration Date") print print_string % ('='*columns['host'], '='*columns['id'], '='*columns['subject'], '='*columns['issuer'], '====', '='*columns['expiration_string']) for certificate in result: print print_string % (certificate['host'], certificate['cert_info']['id'], certificate['subject']['common_name'], certificate['issuer']['common_name'], str(certificate['bit_length']), certificate['expiration_string']) Tested this on version: 11.5256Views0likes0CommentsGet current connection of pool members
Hi, I tried write a script (python) to checking numeber current connection and when is 0 mark member 'disabled'. How can I get only value of current connection and then check is 0 ? member_stat = b.LocalLB.Pool.get_member_statistics( ['/Common/' + pool], [[{'address': member, 'port': port}]]) for statistic in member_stat: .... if ( 'STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS' == 0 ) : pl.set_member_session_enabled_state(['/Common/' + pool ], [[{'address': member, 'port': port}]], [['STATE_DISABLED']]) pl.set_member_monitor_state(['/Common/' + pool ], [[{'address': member, 'port': port}]], [['STATE_DISABLED']])382Views0likes2CommentsPython bigsuds for Bigip 4.x
I have some very old legacy devices running on version 4.5.13 and I need to pull some information via Icontrol. Firstly does 4.x support Icontrol ? Python is my language of choice and i use the bigsuds library mostly for my work.I did the following : >>> import bigsuds >>> b = bigsuds.BIGIP(hostname = 'x.x.x.x',username = 'root', password ='password') >>> vlans = b.Networking.Interfaces.get_list() Traceback (most recent call last): File "", line 1, in File "build/bdist.linux-x86_64/egg/bigsuds.py", line 313, in __getattr__ File "build/bdist.linux-x86_64/egg/bigsuds.py", line 139, in _create_client bigsuds.ParseError: :12:2: mismatched tag Failed to parse wsdl. Is "Networking.Interfaces" a valid namespace? What is the problem and how do i overcome it ?301Views0likes3CommentsiApp elements in iControl (bigsuds)
I have two LTM boxes running BigIP 11.5 on which I configured several iApps. Now I'd like to use iControl to check the pool/node status, statistics, enable and disable nodes, etc. However, I can't get a list of the iApps and pools configured. Here's what I tried using the (awesome!) bigsuds library: bs = bigsuds.BIGIP(hostname="my_ltm_box", username="my_username", password="some_pass") print bs.Management.ApplicationService.get_list() print bs.LocalLB.Pool.get_list() I would expect at least the first, but preferably also the second print out a list of items. But both commands return an empty list (I currently don't have any pools configured normally, only through iApps, though when I add one it gets listed). To make it even a bit more confusing, the listing of nodes works (both for normally configured nodes as for nodes configured in an iApp): print bs.LocalLB.NodeAddressV2.get_list() Am I missing something? How can I find out which iApps are configured and more importantly, how can I find the pools and possibly other elements related to these iApps, since they don't seem to be available through the regular API calls.Solved393Views0likes2CommentsBigsuds - save_configuration
I am new to python and iControl. I am trying to use bigsuds to save a UCS file on the box but I am getting a strange error - >>> b.System.ConfigSync.save_configuration(['/shared/tmp/test.ucs'],['SAVE_FULL']) Traceback (most recent call last): ......Output omitted ........ bigsuds.ArgumentError: "['SAVE_FULL']" is not a valid value for System.ConfigSync.SaveMode, expecting: SAVE_FULL, SAVE_HIGH_LEVEL_CONFIG, SAVE_BASE_LEVEL_CONFIG, SAVE_GTM_CONFIG_ONLY It shows an error with my agrument in the raw list format. If I make the second argument a string then I also get errors - >>> b.System.ConfigSync.save_configuration(['/shared/tmp/test.ucs'],'SAVE_FULL') Traceback (most recent call last): ......Output omitted ........ suds.TypeNotFound: Type not found: 'filename' I dont quite get what I am doing wrong.236Views0likes5Comments