Forum Discussion
Python SDK Assign iRules to a virtual server
Hi,
I am able to create a virtual using the F5 python SDK including the assignment of HTTP, OneConnect, Client SSL Profiles, and Server SSL profiles. However, I have not been able to figure out how to assign iRules to the virtual server. Does anyone have an example they can share?
9 Replies
- JG
Cumulonimbus
See this one: https://devcentral.f5.com/questions/assign-irule-to-virtual-server-via-icontrol-rest and you might have better lucks there.
- JRahm
Admin
Hi Kurt, The rules are a list, so you would do it this way:
>>> vip = b.tm.ltm.virtuals.virtual.load(name='testvip') >>>vip.rules [u'/Common/tcptest'] >>> vip.rules = ['/Common/tcptest', '/Common/platform_info'] >>> vip.update() >>vip.rules [u'/Common/tcptest', u'/Common/platform_info']I did an absolute update on the rules attribute, but I could have also just appended with:
vip.rules.append('/Common/platform_info') - Kurt_Kite_11866
Nimbostratus
Hi Jason, Thanks very much! This worked for me. I assume that it is not possible to define the rules list as a parameter in the bigip.ltm.virtuals.virtual.create method.
Best Regards, Kurt
- JRahm
Admin
sure, you can do that as well:
x = b.tm.ltm.virtuals.virtual.create( name='testvip5', partition='Common', rules=['/Common/tcptest'], profiles=['/Common/http']) - IRONMAN_183357
Nimbostratus
Hi Jason,
I am getting below error
Traceback (most recent call last): File "C:\Users\krissara\Desktop\F5 SDK\Stage5\VIP add.py", line 6, in x = b.tm.ltm.virtuals.virtual.create( NameError: name 'b' is not defined
- JRahm
Admin
did you instantiate your BIG-IP to b or a different variable first?
from f5.bigip import ManagementRoot b = ManagementRoot('x.x.x.x', 'admin', 'admin') x = b.tm.ltm.virtuals.virtual.create( name='testvip5', partition='Common', rules=['/Common/tcptest'], profiles=['/Common/http'])
- Chanan_Berler_3
Nimbostratus
thanks a lot guys. Its working for me. @Naim :)
- IRONMAN
Cirrostratus
Hi All,
When i try to make connection with F5 box via python, i am getting below error. I am not good in python, please tell me how to proceed this commands with API to create objects in F5
from import ManagementRoot bigip = ManagementRoot('35.154.69.72', 'admin', 'admin')
Warning (from warnings module): File "C:\Users\krissara\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 858 InsecureRequestWarning)InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.htmlssl-warnings
I decided to add urllib3 to avoid cert errors, but not working
urllib3.disable_warnings() Traceback (most recent call last): File "", line 1, in urllib3.disable_warnings() NameError: name 'urllib3' is not defined import urllib3 bigip = ManagementRoot('35.154.69.72', 'admin', 'admin')
Warning (from warnings module): File "C:\Users\krissara\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 858 InsecureRequestWarning) InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.htmlssl-warnings
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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