diff --git a/py/f5-sdk/datagroup-edit.py b/py/f5-sdk/datagroup-edit.py new file mode 100644 index 0000000..59041b4 --- /dev/null +++ b/py/f5-sdk/datagroup-edit.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +from f5.bigip import ManagementRoot +# Connect to the BigIP +session = ManagementRoot("10.11.232.247", "username", "password") + +datagroup = session.tm.ltm.data_group.internals.internal.load(name='domain1-WHITELIST', partition='Common') +# Print current record +print(datagroup.records) + +# Update record +# datagroup.records = [{'name': '203.60.15.113/32', 'data': ''}, {'name': '222.186.30.174/32', 'data': ''},{'name': '120.136.32.106/32', 'data': ''}] +datagroup.records = [{'name': '203.60.15.113/32', 'data': ''}, {'name': '222.186.30.174/32', 'data': ''}] +datagroup.update() + +# Print latest record +print(datagroup.records) + diff --git a/py/f5-sdk/datagroup-list.py b/py/f5-sdk/datagroup-list.py new file mode 100644 index 0000000..001e173 --- /dev/null +++ b/py/f5-sdk/datagroup-list.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +from f5.bigip import ManagementRoot +# Connect to the BigIP +mgmt = ManagementRoot("10.11.232.247", "username", "password") + +# Get a list of all pools on the BigIP and print their names and their +# members' names +pools = mgmt.tm.ltm.pools.get_collection() +for pool in pools: + print(pool.name) + for member in pool.members_s.get_collection(): + print(member.name) + +def showDatagroups() : + print("\n\n**** Showing Datagroups") + dgs = mgmt.tm.ltm.data_group.internals.get_collection() + for idx, dg in enumerate(dgs): + if "WHITELIST" in dg.name: + # print("\n{}: {}".format(idx, dg.raw)) + print("\n{}: {}".format(idx, dg.name)) + if hasattr(dg, 'records'): + print("\n{}: {}".format(idx, dg.records)) + #for record in dg.records: + # print("\nrec: {}".format(record)) + else: + print("\nObject {} has no records".format(dg.name)) + +def showDatagroupFiles(): + print("\n\n**** Showing DatagroupFiles") + dgFiles = mgmt.tm.sys.file.data_groups.get_collection() + for idx, f in enumerate(dgFiles): + print('\n{}: {}'.format(idx, f.raw)) + +if __name__ == "__main__": + showDatagroups() +