Forum Discussion
Ken_R_
Apr 08, 2020Nimbostratus
BigIP iControl REST
I'm using the requests module (not the f5-sdk library) with Python to add LTM objects and am having an issue with POST. The following code works: def node(): body = """ { "name"...
- Apr 08, 2020
Hello Ken.
I recommend you to use the F5-SDK. You can install the module using pip:
REF - https://f5-sdk.readthedocs.io/en/latest/
To create a node is as simple as this:
from f5.bigip import ManagementRoot session = ManagementRoot("F5_mgmt_IP","username","password",token=True) node = session.tm.ltm.nodes.node.create(name='node_10.1.1.1', address='10.1.1.1', description='123abc', partition='Common')
KR,
Dario.
Ken_R_
Apr 09, 2020Nimbostratus
Thank you Dario. I agree with what you're saying, it just seems that REST using the requests module seems to match up a little better with the TMSH command structure than the sdk. Taking your advice, the following code worked well. Thank you for your input.
from f5.bigip import ManagementRoot
from getpass import getpass
PASSWORD = getpass()
session = ManagementRoot("lab-ltm", "admin", PASSWORD, token=True)
def node():
nodes = [
{"name": "node-test1", "address": "1.1.1.40"},
{"name": "node-test2", "address": "2.2.2.80"},
]
for node in nodes:
nodes = session.tm.ltm.nodes.node.create(
name=node["name"], address=node["address"], partition="Common"
)
pool()
def pool():
pool = session.tm.ltm.pools.pool.create(name="pool-test", monitor="tcp")
pool_load = session.tm.ltm.pools.pool.load(name="pool-test")
nodes = ["node-test1:80", "node-test2:80"]
for node in nodes:
member_load = pool_load.members_s.members.create(name=node, partition="Common")
virtual()
def virtual():
params = {
"name": "vs-test-virtual",
"destination": "200.200.200.200:8080",
"mask": "255.255.255.255",
"ipProtocol": "tcp",
"pool": "test_pool",
"profiles": [
"http",
"f5-tcp-wan",
{"name": "clientssl", "context": "clientside"},
],
"partition": "Common",
"sourceAddressTranslation": {"type": "automap"},
}
virtual = session.tm.ltm.virtuals.virtual.create(**params)
if __name__ == "__main__":
node()
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects