GithubHelp home page GithubHelp logo

f5-rahm / bigrest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leonardobdes/bigrest

2.0 2.0 0.0 6.01 MB

BIGREST - Python SDK for F5 iControl REST API

License: MIT License

Python 100.00%

bigrest's People

Contributors

jasonrahm avatar leonardobdes avatar rahveetufts avatar shell2 avatar

Stargazers

 avatar

bigrest's Issues

After successful device.task_start, we get an exception.

Same code as issue with the timeout addition #3

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)

# 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"
}
}

While using BIG-IQ.task_start, timeout is caught

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 "/

//py39/lib64/python3.9/site-packages/urllib3/connectionpool.py", line 537, in _make_request
response = conn.getresponse()
File "///py39/lib64/python3.9/site-packages/urllib3/connection.py", line 466, in getresponse
httplib_response = super().getresponse()
File "/usr/lib64/python3.9/http/client.py", line 1377, in getresponse
response.begin()
File "/usr/lib64/python3.9/http/client.py", line 320, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.9/http/client.py", line 281, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib64/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
File "/usr/lib64/python3.9/ssl.py", line 1275, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib64/python3.9/ssl.py", line 1133, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/

//py39/lib64/python3.9/site-packages/requests/adapters.py", line 486, in send
resp = conn.urlopen(
File "///py39/lib64/python3.9/site-packages/urllib3/connectionpool.py", line 847, in urlopen
retries = retries.increment(
File "///py39/lib64/python3.9/site-packages/urllib3/util/retry.py", line 470, in increment
raise reraise(type(error), error, _stacktrace)
File "///py39/lib64/python3.9/site-packages/urllib3/util/util.py", line 39, in reraise
raise value
File "///py39/lib64/python3.9/site-packages/urllib3/connectionpool.py", line 793, in urlopen
response = self._make_request(
File "///py39/lib64/python3.9/site-packages/urllib3/connectionpool.py", line 539, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "///py39/lib64/python3.9/site-packages/urllib3/connectionpool.py", line 370, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='', port=443): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/

//big-iq-migrate.py", line 278, in
main()
File "///big-iq-migrate.py", line 270, 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 "///big-iq-migrate.py", line 150, in process_bigiq_config
task = device_az2.task_start("/mgmt/shared/appsvcs/declare",json.dumps(data_element.properties["body"]))
File "///py39/lib64/python3.9/site-packages/bigrest/bigiq.py", line 56, in task_start
response = self.session.post(url, json=data, timeout=self.timeout)
File "///py39/lib64/python3.9/site-packages/requests/sessions.py", line 637, in post
return self.request("POST", url, data=data, json=json, **kwargs)
File "///py39/lib64/python3.9/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "///py39/lib64/python3.9/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "///py39/lib64/python3.9/site-packages/requests/adapters.py", line 532, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='', port=443): Read timed out. (read timeout=10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.