python
51 TopicsF5 Python SDK: How to get virtual server availability?
Due to my limited Python and SDK experience I am finding it difficult to easily obtain the availability state of a virtual server. Given a 'virtual' object, what is the best/easiest way to return the value of that VS' 'Availability' state (offline, available, unknown, etc)? I can do the following: my_virtual = mgmt.tm.ltm.virtuals.virtual.load(name='some_virtual') stats = my_virtual.stats.load() Printing the stats.raw shows that there is a nested dictionary entry keyed 'status.availibityState' that appears to hold the value I'm looking for. Forgive my inexperience, but what is the easiest way to get the availability state of a virtual using the SDK? Perhaps a method I'm missing that retrieves the value above, or the value is easily obtained elsewhere. Appreciate any assitance!2KViews0likes27CommentsPython script to request SSL-certificate at Sectigo and configure on F5
Hey everyone, I am trying to write a python script (using SDK: f5-common-python) that will generate a CSR, request an SSL Certificate by Sectigo and that will be automatically renewed through F5 when it expires. However, I have read the documentation (https://pythonhosted.org/f5-sdk/index.html) and can't quite find out how this can be achieved. Can anyone help?1.4KViews0likes3CommentsGetting GTM Pool and Wideips with Python f5-sdk
I am having trouble getting all the pools and wideips from the GTM with this (version 12). I was lucky enough to find an example of how to get the 'a' pools and wideips but nothing else: pools_a = mgmt.tm.gtm.pools.a_s.get_collection() wideips_a = mgmt.tm.gtm.wideips.a_s.get_collection() I am unsure as to the use of a_s. This seems very unintuitive. Anyone know how I can grab cname/aaaa?Solved1.4KViews0likes3CommentsUploading ISOs via legacy f5-sdk
I'm working on porting our legacy Bash-based BIG-IP upgrade script to Python, and running into an issue when trying to upload the new image via the (apparently legacy) SDK. Here's the relevant code snippet I'm using: print("Uploading " + firmwareIsoPath + " to " + t + "...") try: firmwareUpload = apiClient.cm.autodeploy.software_image_uploads.upload_file(firmwareIsoPath) except Exception as e: print("ERROR: could not upload firmware to " + t) print(e) continue Every time it tries to run though, it throws the following exception: Traceback (most recent call last): File "autonet.py", line 632, in <module> upgradeF5Appliances(username,password,inventory) File "/mnt/c/Code/Autonet/src/api_f5_upgrade.py", line 112, in upgradeF5Appliances firmwareUpload = apiClient.cm.autodeploy.software_image_uploads.upload_file(firmwareIsoPath) File "/home/cshepard/.local/lib/python3.8/site-packages/f5/bigip/mixins.py", line 95, in __getattr__ raise LazyAttributesRequired(error_message) f5.sdk_exception.LazyAttributesRequired: ('"allowed_lazy_attributes" not in', 'container._meta_data for class Software_Image_Uploads') I haven't been able to figure out why this is happening based on the SDK documentation, any advice? I'm not sure what a "lazy attribute" is in this context, so I'm not sure where to start... Ideally I'd like to use the same session as the rest of my API calls, so we don't have to go through our MFA process multiple times for one device.Solved1.2KViews0likes3CommentsF5 Python SDK - How to Get Profiles on a Virtual
I am using the F5 python SDK. It is awesome. Very useful. I am not, however, able to figure out how to access the subcollection of monitors attached to a virtual object. Any one have any idea how to do this? So far, I've gathered that you can see a link to the profiles via something like this: virtuals = srcf5.tm.ltm.virtuals.get_collection() for v in virtuals: profiles = v.profilesReference From there I was hoping I could do .get_collection(), but it does not have that method. I suppose I could go back to manually calling rest and parsing json for this one portion, but I feel like there is a way to do it in the SDK. Thanks!1.2KViews0likes4CommentsGetting active pool member connections using Python
If I want to see all of the client connections connecting to a pool member from the CLI I can do something like a "show sys connection ss-server-addr 1.2.3.4". I can also do this using Postman mapping to ";, but I cannot figure out how to do this via Python. Using Python if I try to connect to "bigip.sys.raw" I do not see a module called "connection" or anything similar. Does anyone know how, or have some sample code on how to accomplish this? Thanks!1.2KViews0likes10CommentsiControl REST Python Requests module
While iControl REST is great and pretty robust given how much we use it. But I come to the forum today to see if anyone has any experience with the Python requests module and the underlying urllib3 module. When I do have problems with iControl its often with things like the following: Here I've increased the timeout to 5.0 seconds but still get read timeouts. HTTPSConnectionPool(host='redacted', port=443): Read timed out. (read timeout=5.0) I also often see this message and, no I don't have a proxy in front of the F5. However, I know the the F5 proxies the REST call (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 503 Service Unavailable', Thanks!1.2KViews0likes1CommentPython F5SDK - Is Modify Supported?
I've been tasked with automating our code deployments and thus need to disable (or force offline) our pool members to allow that. I am logging in with an operator account and am using token authentication. While I can change make these changes in the webapp, I am unable to make the same changes via the SDK. I'm hoping someone may help me find the detail or error in my approach/syntax/logic. I'm using the code below. It executes fine, but when I look at the patch curl call from debug, it does not include the changes. I have searched far and wide to find a modify example of python code with little luck. I have found plenty of calls using update however, an operator role doesn't have ability to change the node description and thus an update call fails at current privilege level. Python SDK Version: f5-icontrol-rest==1.3.13 f5-sdk==3.0.21 Here's what the curl command looks like from debug. It doesn't capture any data to push to the patch request. curl -k -X PATCH https://<myIPHere>:443/mgmt/tm/ltm/pool/~Common~<pool name>/members/~Common~<node name>/ -H 'User-Agent: python-requests/2.21.0 f5-icontrol-rest-python/1.3.13' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'Content-Length: 2' -H 'X-F5-Auth-Token: <my TOKEN>' -d '{}' If I try to manually edit and execute the curl patch command and insert '{"session":"user-disabled"}' for the data, it says I have improperly formatted JSON. Any help is appreciated if someone has gone down this route. If anyone has a working modify() example, that may be what i need to get over the hump. All examples I see are people logging in as admin and using update, which will work...I just don't want to use an admin account or manager role to handle this automation if I don't have to. from f5.bigip import ManagementRoot from f5.utils.responses.handlers import Stats import json mgmt = ManagementRoot(hostname=<myIPHere>, username=<myusername>, password=<mypassword>, token=True, debug=True); myPool = mgmt.tm.ltm.pools.pool.load(partition='Common', name='<pool name>') myPoolMembers = myPool.members_s.get_collection() for poolMember in myPoolMembers: print(poolMember.raw) poolMember.session = 'user-disabled' poolMember.modify() # Here only to get curl commands for debug purposes for x in mgmt.debug_output: print() print(x)Solved1.1KViews0likes2CommentsHow to install a cert and a key through Python SDK
I am trying to install a cert and a key through Python SDK. BIG-IP Version: 12.1.2 First.. I had no problem with uploading certs and keys to F5's /var/config/rest/downloads/ folder. Now when I tried the following python code to install cert and key, I didn't see any error. key = bitip.tm.sys.file.ssl_keys.ssl_key.create(name='test', partition='Common', sourcePath='file:/var/config/rest/downloads/test.key') cert = bitip.tm.sys.file.ssl_certs.ssl_cert.create(name='test', partition='Common', sourcePath='file:/var/config/rest/downloads/test.crt') However when I logged on BIG-IP device and clicked a cert or key to see their actual content, I couldn't see any content. "No certificate" under certificate tab and an error message of "An error has occurred while trying to process your request." under Key tab. Does any one know what is causing this problem? Or is there any way I can troubleshoot this issue? Thank you.998Views1like4CommentsGetting started with a script to delete user APM session(s)
I have a request to create a script to delete the APM session(s) of a user ID. I can easily do this via the GUI and have found the commands to do it manually, however scripting is totally new to me (though I've programmed in the past). So, I have a few questions to help get an idea of how to approach this: Questions: Is there anything that needs to be imported/enabled on the F5 in order to allow scripting? Would Pythion be the best choice for the script? From where would such a script typically be run (specific server, desktop, etc)? My initial plan would be to base the script off of the sequence below: 1.) List the sessions IDs associated with a user ID: sessiondump -allkeys | grep -i <username> 2.) (pull the session IDs, if any) 3.) Delete the session ID(s): sessiondump --delete <SessionID> Any advice to get started tackling this would be appreciated. We have a vender who I can probably reach out to for assistance, but I want to do some initial research first. Thanks!Solved972Views0likes2Comments