Forum Discussion
Adding a iRule to a Virtual Server
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 name: rule_name'. Any help would be appreciated.
Below is the script:
!/usr/bin/env python
import sys
import pycontrol.pycontrol as pc
b = pc.BIGIP(
hostname = "F5l",
username = "username",
password = "Password",
fromurl = True,
wsdls = ['LocalLB.VirtualServer'])
c = b.LocalLB.VirtualServer
def convert_rule(z,rule):
rule_seq = z.LocalLB.VirtualServer.typefactory.create('LocalLB.VirtualServer.VirtualServerRuleSequence')
rule_set = z.LocalLB.VirtualServer.typefactory.create('LocalLB.VirtualServer.VirtualServerRule')
rule_set.rule_name = rule
rule_set.priority = 500
rule_seq = [rule_set]
return rule_seq
c.add_rule(['VIP'],convert_rule(b,'iRule'))
- L4L7_53191NimbostratusThe add_rule() method expects to have a keyword argument called 'rules' - Suds does a decent job of figuring out unambiguous keyword arguments, but for anything with embedded objects it'll have problems.
c.add_rule(['VIP'], rules = convert_rule(b, 'iRule'))
- MYLKNimbostratusHello,
- Thomas_WeisshaaNimbostratusHi Jomar,
!/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
- L4L7_53191NimbostratusGuys I will pull together an example of how to do this. It'll be Wednesday before I can get to it though...
- Thomas_WeisshaaNimbostratus
Hi again,
thanks to Matt's hint I figured it out - it's a serialization issue:
Your convert_rule() should look like this:
ruleSequence = bigip.LocalLB.VirtualServer.typefactory.create('LocalLB.VirtualServer.VirtualServerRuleSequence')
ruleSet = bigip.LocalLB.VirtualServer.typefactory.create('LocalLB.VirtualServer.VirtualServerRule')
ruleSet.rule_name = ruleName
ruleSet.priority = priority
ruleSequence.item = [ruleSet]
return [ruleSequence]
And then execute it like:
bigip.LocalLB.VirtualServer.add_rule(virtual_servers = ['/Common/VS'], rules = [convert_rule(bigip, '/Common/test', '')])
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