Forum Discussion
Joe
Thanks for looking into this. It may have to do with how I add the irule.
I admit I wasn't able to work it out from the API (sorry I'm new to both icontrol and python) but I found
some code on devcentral and it worked so I figured I needed to do it this way. I have to read up on the type factory stuff
as it seems this is how a lot of calls have to be made now.
Here is the code:
def convert_rule(lb,ruleName,priority):
ruleSequence = lb.LocalLB.VirtualServer.typefactory.create('LocalLB.VirtualServer.VirtualServerRuleSequence')
ruleSet = lb.LocalLB.VirtualServer.typefactory.create('LocalLB.VirtualServer.VirtualServerRule')
ruleSet.rule_name = ruleName
ruleSet.priority = priority
ruleSequence.item = [ruleSet]
return [ruleSequence]
try:
lb.LocalLB.VirtualServer.add_rule(virtual_servers = [virtual_server], rules = [convert_rule(lb, maintenance_irule_name, 1)])
print "Successfully added iRule '%s' to virtual server '%s'\n" % (maintenance_irule_name,virtual_server)
except Exception, e:
print e
sys.exit()
The maintenance_irule I create on the fly like this :
lines = [" This iRule redirects to the standard maintenance page with the highest priority.\n",
" Generated by pycontrol. Manual edits will be undone.\n",
"priority 1\n",
"when HTTP_REQUEST {\n",
" HTTP::redirect http://mymaintenance_site.html\n",
"}"]
maintenance_irule = ''.join(lines)
I first went with the python version of a HERE doc using triple ' but it left the irule with an ugly, undesired indentation that I found no way of removing
so I went with joining list members into string. Seems to work from what I can tell.
I have 2 more questions :
1. Why do I have to pass the priority explicitly when I add the rule when it's already coded into the rules itself ? Maybe this redundancy is causing the problem ?
Where do you recommend I set the priority ? I prefer the irule itself so I can see the priority when looking at the rule in the gui.
2. As per my examples the 2 pre-existing irules had pri 10 and 800 so even if I didn't pass the pri for the 3rd rule it should default to 500 right ?
Still no reason to complain correct ?