Skip to content

API Examples

Za Wilgustus edited this page Dec 21, 2015 · 24 revisions

This page will document how to use the BigIP API:

Simple example of CRUD calls

Each of the following example builds on the previous. We use an "ltm_app" "nat_manager" object for these examples.

CREATE

Creation of a NAT creates a new resource, and corresponding URI, on the device. Prior to creation no such uri exists, so the creation operation must be carried out against a different "manager" resource.

In this example, the "nat_manager" is an attribute of the "ltm_app" object.

In general operations that are not cleanly supported by the resource itself are handled by the corresponding "manager" resource.

In specific, resource creation (FOO_manager.create), and listing groups (FOO_manager.get_list) of resources are handled by "managers".

from f5.bigip import BigIP
bigip = BigIP("HOSTNAME", "USERNAME", "PASSWORD")
nat_obj_1 = bigip.ltm_app.nat_manager.create(partition='TestPartition', name='Nat1', translationAddress='1.2.3.4', originatingAddress='1.2.3.5')

READ

nat_obj_1.read()

UPDATE

nat_obj_1.update({KEY_TO_UPDATE1: NEW_VALUE1, KEY_TO_UPDATE2:NEW_VALUE2, ...})

DELETE

nat_obj_1.delete()

Other functions "managers" support

Individual NAT objects have no references to eachother, so operations on groups are implemented in the nat_manager.

list_of_nat_objects = bigip.ltm_app.nat_manager.get_list()

Example Operations on a different LTM functionality, "pool"

pool_obj = bigip.ltm_app.pool_manager.create(${CONSTRUCTOR_REQUIRED_ARGS})
pool_objs_list = bigip.ltm_app.pool_manager.get_list()

print pool_obj.name;          # Print an attribute that we set
print nat_obj.trafficGroup;   # Print an attribute that BIGIP set by default

READ

# Refresh the nat object with the current settings on the BIGIP
nat_obj.read()

# We can also get a filtered list of the nats on the device
list_of_nat_objs_in_SpecificPartition = bigip.ltm_app.nat_manager.get_list(partition='SpecificPartition')
for n in list_of_nat_objs_in_SpecificPartition:
    print n.name

UPDATE

# Set an attribute and update it
nat_obj.trafficGroup = "Common/newgroup"
nat_obj.update()

# Update using key/value pairs
nat_obj.update(trafficGroup='Common/anothernewgroup')

# Update attribute and override with update (key/value pairs always override current settings)
nat_obj.arp = 'Enabled'
nat_obj.update(arp='Disabled')

DELETE

nat_obj.delete()

# This should raise an exception
print nat_obj.name