Forum Discussion
Jomar_46001
Nov 19, 2010Nimbostratus
Adding a iRule to a Virtual Server
Hi, I was trying to write a script to allow me to add an existing iRule to an existing Virtual Server. I am receiving the following error when I run the script: 'Could not find element by n...
Thomas_Weisshaa
Sep 30, 2012Nimbostratus
Hi Jomar,
unfortunately I couldn't figure it out as well with pyControl2 yet.
Here is a solution based on SOAPpy:
!/usr/bin/env python
import SOAPpy
import sys
from optparse import OptionParser
def f5Conn(options):
iControlUrl = "https://%s:%s@%s/iControl/iControlPortal.cgi" %(options.bigipUsername,options.bigipPassword,options.bigipHost)
iControlVirtualServerNamespace = "urn:iControl:LocalLB/VirtualServer"
vsProxy = SOAPpy.SOAPProxy(iControlUrl, iControlVirtualServerNamespace)
return vsProxy
def addRuleToVirtualServer(vsProxy, rule, priority, vs):
ruleStructure = dict(rule_name=rule, priority=priority)
for item in vs:
try:
res = vsProxy.add_rule(
virtual_servers=[item],
rules = [[ruleStructure]]
)
except:
return sys.exc_info()[1]
def removeRuleFromVirtualServer(vsProxy, delRule, ruleList):
for ruleListItem in ruleList:
for (vserver,rules) in ruleListItem:
for (a,b) in rules:
if (delRule in a):
ruleStructure = dict(rule_name=a, priority=b)
try:
res = vsProxy.remove_rule(
virtual_servers=[vserver],
rules = [[ruleStructure]]
)
except:
return sys.exc_info()[1]
if __name__ == '__main__':
foo
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