-
Notifications
You must be signed in to change notification settings - Fork 132
API Examples
Za Wilgustus edited this page Dec 21, 2015
·
24 revisions
Each of the following example builds on the previous. We use an "LTM" "NAT" object for these examples.
from f5.bigip import BigIP
bigip = BigIP("HOSTNAME", "USERNAME", "PASSWORD")
nat_obj_1 = bigip.ltm.nat_manager.create_nat(partition='TestPartition', name='Nat1', translationAddress='1.2.3.4', originatingAddress='1.2.3.5')
Notice: The Creation of an object is not called on the object itself, rather it is called on the relevant "manager", in this case "nat_manager
". The other CRUD operations (Read, Update, and Delete) are called on the NAT object itself.
nat_obj_1.read()
updated_version_nat_obj_1 = nat_obj_1.update({KEY_TO_UPDATE1: NEW_VALUE1, KEY_TO_UPDATE2:NEW_VALUE2, ...})
nat_obj_1.delete()
list_of_nat_objects = bigip.ltm.nat_manager.get_nats()
pool_obj = bigip.ltm.pool_manager.create_pool(${CONSTRUCTOR_REQUIRED_ARGS})
pool_objs_list = bigip.ltm.pool_manager.get_pools()
print pool_obj.name; # Print an attribute that we set
print nat_obj.trafficGroup; # Print an attribute that BIGIP set by default
# 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.nat_manager.get_nats(partition='SpecificPartition')
for n in list_of_nat_objs_in_SpecificPartition:
print n.name
# 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')
nat_obj.delete()
# This should raise an exception
print nat_obj.name