Forum Discussion
Twirrim_94896
Mar 29, 2011Nimbostratus
struggling to create irules
I'm using python 2.6.6 and pycontrol 2.0.1 to connect to our load balancer and configure it. I'm trying to make a rough start at creating a standard provisioning script for any new subdomains that ar...
L4L7_53191
Mar 29, 2011Nimbostratus
Nicely done. If you've not gone through it up until now, you may want to go through the typefactory screencast that I did a while back to help get folks up to speed on how pycontrol/suds handles types. You've discovered, as have a couple of other folks, that Suds will take a normal python data structure and try to do the right thing with it. IIRC, this isn't completely consistent though, especially with nested types. So I always use the typefactory, which is much more explicit...
Anyhow, here's an example that may be useful for you (done via an iPython interactive shell session). It may save you a few lines of code.
In [18]: r.create.params
Out[18]: [(rules, u'LocalLB.Rule.RuleDefinitionSequence')] This is the data structure we need to pass into the create call. Let's create the LocalLB.RuleDefinition object...
In [19]: r_def = r.typefactory.create('LocalLB.Rule.RuleDefinition')
In [20]: print r_def
(LocalLB.Rule.RuleDefinition){
rule_name = None
rule_definition = None
} This shows us what attributes we need to tickle to pass in the call. Let's do that now...
In [21]: r_def.rule_name = 'YOYO_pyControl' The name of the rule. Now we'll actually add the iRule code.
In [22]: raw_code = '''
....: when HTTP_REQUEST {
....: log local0. "Python - I can fly!!"
....: }''' Now we'll add this to our object's rule_definition attribute...
In [23]: r_def.rule_definition = raw_code Now we'll add it to BigIP...
In [24]: r.create(rules = [r_def]) Notice to create a 'sequence' I just treat it like a list. Let's see if it saved!
In [25]: r.get_list()
Out[25]:
[ _sys_APM_activesync,
_sys_auth_ssl_cc_ldap,
_sys_auth_krbdelegate,
_sys_https_redirect, YOYO_pyControl,
_sys_auth_ssl_crldp,
_sys_auth_ssl_ocsp,
nextgen-test,
connection-limit,
nextgen-dg-acl]
Thanks for the post and I look forward to hearing more about your project!
-Matt Cauthorn
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