f5-rahm / bigrest Goto Github PK
View Code? Open in Web Editor NEWThis project forked from leonardobdes/bigrest
BIGREST - Python SDK for F5 iControl REST API
License: MIT License
This project forked from leonardobdes/bigrest
BIGREST - Python SDK for F5 iControl REST API
License: MIT License
Get pytest added to the project and a few basic tests to start
reference: leonardobdes#2
Same code as issue with the timeout addition #3
Code
data = get_realtime_bigiq_data_partition(device, url)
for data_element in data:
data_element.properties["body"]["target"]["address"] = big_ip_new
# Print debug output for visual inspection
print(json.dumps(data_element.properties["body"], indent=4))
# Open connection to new BIG-IQ
device_az2, token_bigiq_az2, token_creation_az2 = connect_to_big_iq(bigiq_device_az2,username,password,login_provider, timeout)
# Start a task, with the AS3 data
task = device_az2.task_start("/mgmt/shared/appsvcs/declare",json.dumps(data_element.properties["body"]))
# Check if task is finished
device_az2.task_wait(task)
# If task completed print task info
if device_az2.task_completed(task):
print("Task "+ bigiq_partition + " completed.")
We are getting an exception on a successful POST/task_start:
Traceback (most recent call last):
File "//migrate-f5-scripts/big-iq-migrate.py", line 279, in
main()
File "//migrate-f5-scripts/big-iq-migrate.py", line 271, in main
process_bigiq_config(args.test, args.savedata,args.big_iq_partition,args.bigiq_address,args.bigiq_user,args.bigiq_password,args.action)
File "//migrate-f5-scripts/big-iq-migrate.py", line 151, in process_bigiq_config
task = device_az2.task_start("/mgmt/shared/appsvcs/declare",json.dumps(data_element.properties["body"]))
File "//migrate-f5-scripts/py39/lib64/python3.9/site-packages/bigrest/bigiq.py", line 58, in task_start
raise RESTAPIError(response, self.debug)
bigrest.common.exceptions.RESTAPIError:
Status:
200
Response Body:
{
"results": [
{
"message": "success",
"dryRun": false,
"host": "localhost",
"tenant": "TENANT",
"runTime": 15646,
"code": 200
}
],
"declaration": {
"VIP-NAME": {
"class": "Tenant",
"remark": "Managed by Self-Service",
"testapp-az2": {
"class": "Application",
"template": "generic",
"schemaOverlay": "default",
"pool-testapp-80": {
"class": "Pool",
"label": "Managed by Self-Service",
"remark": "Managed by Self-Service",
"members": [
{
"label": "Managed by Self-Service",
"ratio": 1,
"remark": "Managed by Self-Service",
"servers": [
{
"name": "test1",
"address": ""
}
],
"servicePort": 80
}
],
"monitors": [
{
"use": "/TENANT/testapp-az2/monitor-testapp-80"
}
],
"minimumMonitors": "all",
"loadBalancingMode": "round-robin"
},
"sa-": {
"class": "Service_Address",
"label": "Managed by Self-Service",
"remark": "Managed by Self-Service",
"icmpEcho": "enable",
"arpEnabled": true,
"trafficGroup": "/Common/tg-az2-1",
"virtualAddress": "",
"routeAdvertisement": "selective"
},
"monitor-testapp-80": {
"class": "Monitor",
"label": "Managed by Self-Service",
"remark": "Managed by Self-Service",
"monitorType": "tcp"
},
"clientssl-testapp-443": {
"class": "TLS_Server",
"label": "Managed by Self-Service",
"remark": "Managed by Self-Service",
"cipherGroup": {
"bigip": "/Common/ciphergroup-Approved"
},
"certificates": [
{
"certificate": "/TENANT/testapp-az2/cert_localhost.localdomain"
}
],
"namingScheme": "certificate",
"tls1_0Enabled": false,
"tls1_1Enabled": false,
"tls1_2Enabled": true,
"tls1_3Enabled": true,
"renegotiationEnabled": false
},
"snatpool-": {
"class": "SNAT_Pool",
"label": "Managed by Self-Service",
"remark": "Managed by Self-Service",
"snatAddresses": [
""
]
},
"cert_localhost.localdomain": {
"class": "Certificate",
"label": "Managed by Self-Service",
"remark": "Managed by Self-Service",
"chainCA": {
"bigip": "/Common/ca-bundle.crt"
},
"privateKey": {
"bigip": "/Common/localhost.localdomain"
},
"certificate": {
"bigip": "/Common/localhost.localdomain"
}
},
"vs-testapp-443-": {
"pool": {
"use": "/TENANT/testapp-az2/pool-testapp-80"
},
"snat": {
"use": "/TENANT/testapp-az2/snatpool-"
},
"class": "Service_TCP",
"label": "Managed by Self-Service",
"enable": true,
"iRules": [],
"remark": "Managed by Self-Service",
"serverTLS": "/TENANT/testapp-az2/clientssl-testapp-443",
"virtualPort": 443,
"policyEndpoint": [],
"virtualAddresses": [
{
"use": "/TENANT/testapp-az2/sa-"
}
],
"persistenceMethods": [
{
"bigip": "/Common/ssl_session"
}
]
}
}
},
"id": "autogen_8a6be3f1-2091-4c6e-ba28-2c424ae4b6a6",
"class": "ADC",
"target": {
"address": ""
},
"controls": {
"class": "Controls",
"userAgent": "BIG-IQ/8.2 Configured by API",
"archiveTimestamp": "2024-03-18T09:35:00.624Z"
},
"updateMode": "selective",
"schemaVersion": "3.36.0"
}
}
Jason, just found out you took over the BIGREST sdk, hope you can help me.
We need to migrate to a new BIG-IQ/BIG-IP environment, while the old system will keep up and running until actual migration. Wished we didn't need to, but F5 support said the only way to fix the issues we have is to rebuild a complete new BIG-IQ/BIG-IP setup. If you want to know the reason I can forward you the case number.
It's all done with AS3, some VIPS still manual created but will be recreated with AS3 if possible. As AS3 APPSVCS is still missing alot of needed functionality, even official RESTapi/ansible/terraform is missing nethsm support, only available via CLI/GUI.
I found an ansible script to replace a BIG-IP in a BIG-IQ setup, and trying to create with the ansible as an example a script so I can use it to populate an new BIG-IQ/IP enviroment Ansible script is only for replacing an BIG-IP using the same BIG-IQ.
It's all using BGP, and the new systems is prepended so it will not become active, and we should be able to force offline the old BIG-IP's and everything should run through the new enviroment. Should work but needs testing :P
But I have a small issue, the below code works, but when I start an task (BIG-IQ.task_start), I get a request.exceptions.ReadTimeout. Can understand that because it takes a while for BIG-IQ to process an AS3 script. But I would have thought this would be caught so I could use the BIG-IQ.task_wait and BIG-IQ.task_completed to check progress. Could be that I am using the wrong URL, and should use something else. I know BIG-IQ has some options, but couldn't find anything yet so task_start works. Examples are a bit simple most of the times.
At this time it works for a single AS3, but script stops when getting the timeout (10 seconds) not changeable.
Woud be nice if this could be solved in BIGREST, I will try to catch this exception and continue the program, so I can continue. But maybe in the future more people will hit this, as AS3 is getting some momentum. And if you have a good option for catching this, I would be gratefull.
This is my test script, need to extend stuff, so we can migrate a single vip to a complete partition to all partitions (Excluding Common)
Code:
# get data from old BIG-IQ
data = get_realtime_bigiq_data_partition(device, url)
# Itterate through data and replace the IP for target value "address" to the new BIG-IP IP address.
for data_element in data:
data_element.properties["body"]["target"]["address"] = big_ip_new
# Print debug output for visual inspection
print(json.dumps(data_element.properties["body"], indent=4))
# Open connection to new BIG-IQ
device_az2, token_bigiq_az2, token_creation_az2 = connect_to_big_iq(bigiq_device_az2,username,password,login_provider, timeout) <<== Added timeout value
# Start a task, with the AS3 data
task = device_az2.task_start("/mgmt/shared/appsvcs/declare",json.dumps(data_element.properties["body"]))
# Check if task is finished
device_az2.task_wait(task)
# If task completed print task info
if device_az2.task_completed(task):
print("Task "+ bigiq_partition + " completed.")
Error:
Traceback (most recent call last):
File "/
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.