Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

97 Commits

Repository files navigation

Python F5

A library to make manipulating F5 loadbalancers easy

Overview

  • Supports F5 BIG-IP V11
  • Manage nodes, pools and poolmembers, irules and virtualservers

Requires

Usage

python setup.py install

Examples

Loadbalancers

importf5lb=f5.Lb('f5.example.com', 'admin', 'admin')
# Get the failover statelb.failover_state# Disable versioncheck if you know betterlb=f5.Lb('f5.example.com', 'admin', 'admin', versioncheck=False)
# Get all intranet poolspools=lb.pools_get(pattern='.*intranet.*')
# I only need the names - go faster!# (This will skip populating all the object attributes, useful if you just want a listing)pools=lb.pools_get(pattern='.*intranet.*', minimal=True)
# Get the members in those poolspms=lb.pms_get(pools=pools)
# I just wanted the ones in dc3pms=lb.pms_get(pools=pools, pattern='.*dc3')
# Just give me ALL poolmembers in dc3pms=lb.pms_get(pattern='.*dc3.*')
# Give me *ALL* poolmemberspms=lb.pms_get()
# Nodes are similarnodes=lb.nodes_get()
# Poolspools=lb.pools_get()
# Change the active folderiflb.active_folder!='/Common':
lb.active_folder='/Common'# Enable recursive queryinglb.recursive_query=True# Perform transactionsnode=lb.node_get('/Common/node-01')
pm=lb.get_pm('/Common/node-01'):
lb.transaction=Truedo_stuff()
ifhappy():
# submitlb.submit_transaction()
else:
# or rollbacklb.transaction=False

Nodes

importf5lb=f5.Lb('f5.example.com', 'admin', 'admin')
# Basic createnode=f5.Node(name='/Common/node-01', address='1.1.1.1', connection_limit=0, lb=lb)
node.save()
# We can check if this node existsifnode.exists():
print'Oh, it was already there'else:
importnukeicbm=nuke.Icbm()
icbm.launch(target='Juliano')
# this works toonode=f5.Node(name='/Common/node-01')
node.lb=lbnode._name=namenode._address=addressnode._connection_limit=connection_limitnode._description=descriptionnode._dynamic_ratio=dynamic_rationode._enabled=enablednode._rate_limit=rate_limitnode._ratio=rationode.save()
# Get the attributes synchronously (directly from the lb)print'node connection_limit: %s'% (node.connection_limit)
print'node description: %s'% (node.description)
print'node dynamic_ratio: %s'% (node.dynamic_ratio)
print'node status: %s'% (node.enabled)
print'node rate_limit: %s'% (node.rate_limit)
print'node rate_limit: %s'% (node.ratio)
# Often local copies are enough and we don't want to call the lbprint'node connection_limit: %s'% (node._connection_limit)
print'node description: %s'% (node._description)
print'node dynamic_ratio: %s'% (node._dynamic_ratio)
print'node status: %s'% (node._enabled)
print'node rate_limit: %s'% (node._rate_limit)
print'node rate_limit: %s'% (node._ratio)
# It's under 9000!node.ratio=8999# This node is broken, disable itnode.enabled=False# We can also do transactionslb.transaction=Truenode.connection_limit=100node.ratio=10lb.submit_transaction()
# we can set attributes asynchronously, but remember to save()node._connection_limit=100node._ratio=10# save() is transactional. (But it won't submit if there's already one running)node.save()
# We can re-fetch all attributes from the lb easilynode.refresh()
# Or work with a list for convenience:nodelist=f5.NodeList(lb, pattern='.*webapp.dc02.*')
# Update attributes on all the nodes in the listnodelist.connection_limit='9001'# or asynchronous (and transactional):nodelist._set_nodeattr('_connection_limit', 9001)
nodelist._set_nodeattr('_description', 'It'sover9000!')
nodelist.sync()
# to dictionarynodelist.dictionary# Or from local copies (no requests to the lb, so faster)nodelist._dictionary# Load from dictionary:nodelist.dictionary=dictionary

Pools

importf5lb=f5.Lb('f5.example.com', 'admin', 'admin')
# Basic createpool=f5.Pool(name='/Common/pool-01', lbmethod='ratio_member', members=[], lb=lb)
pool.save()
# This time with a membernode=lb.node_get('/Common/node-01')
# TODO: need some more logic here. pool parameter is redundant when new object is meant to become a memberpm=f5.PoolMember(node=node, port=80, pool=pool)
pool=f5.Pool(name='/Common/pool-01', lbmethod='ratio_member', members=[pm], lb=lb)
# Get existing poolpool=lb.pool_get('/Common/pool-01)
# Get pool memberspoolmembers=pool.members# You can directly reference member attributespoolmembers[0].connection_limitpoolmembers[0].ratio=10# Set some attributes synchronouslypool.lbmethod='round_robin'pool.description='This is an example pool'# or asynchronously (remember to save!)pool._lbmethod='round_robin'pool._description='This is an example pool'pool.save()
# We can easily copy members between pools# Here we copy members in dc3 from 'some_other_pool' to our pool.pms=lb.pms_get(pools=['some_other_pool'], pattern='.*dc3.*')
pool.members=pms

Poolmembers

importf5lb=f5.Lb('f5.example.com', 'admin', 'admin')
# Basic createnode=lb.node_get('/Common/node-01')
pool=lb.pool_get('/Common/pool-01)
pm=f5.PoolMember(node=node, port=80, pool=pool, lb=lb)
# We don't *have to* use objects, string are also fine.pm=f5.PoolMember(node='/Common/node-01', port=80, pool='/Common/pool-01', lb=lb)
# Save it to the lb before using setters (or receive an error)pm.save()
# Set some attributes synchronouslypm.description='This is my poolmember, there are many like it, but this one is mine'pm.ratio=10pm.lb=lb# or asynchronously (remember to save!)pm._ratio=10pm._lb=lbpm.save()
# We can defer setting the lb until the very end and still use the setters to make changes# asynchronously. If lb isn't set, the setters will just update the local copies.pm=f5.PoolMember(node=node, port=80, pool=pool)
pm.connection_limit=9000pm.description='Whos poolmember is this?'pm.ratio=10pm.lb=lbpm.save()
# You can also directly reference the linked node object's attributespm.node.connection_limitpm.node.ratio=10

About

A library to make manipulating F5 loadbalancers easy

Resources

Stars

15 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages