Forum Discussion

j0m_39562's avatar
j0m_39562
Icon for Nimbostratus rankNimbostratus
Nov 13, 2013

Possible to create irules via icontrol REST API?

Hi, With the icontrol REST API it seems like there's finally a sane way to manage configuration. Thanks F5! Most things seem to work satisfactory. Obviously I ran into to the irule/vip bug. Another issue I couldn't figure out is how to create irules. I can create placeholders but I can't upload content. I assume "apiAnonymous" isn't a good name for the content. So, is there a way to upload irules with the current release or will this issue be fixed soon?

{
  "kind": "tm:ltm:rule:rulestate", 
  "apiAnonymous": "when HTTP_REQUEST...", 
  "name": "foobar", 
  "partition": "/Common/", 
  "selfLink": "https://localhost/mgmt/tm/ltm/rule/foobar"
}

3 Replies

  • I have been playing with some python code with this. This creates an irule, lists it, then deletes it.

     

    Main:

     

    if __name__ == "__main__":
        import requests, time, json
    
        b = requests.session()
        b.auth = ('admin', 'admin')
        b.verify = False
        b.headers.update({'Content-Type' : 'application/json'})
    
        b_url_base = 'https://192.168.6.5/mgmt/tm'
    
        mycode = 'priority 100\nwhen CLIENT_ACCEPTED {\n\tlog local0. \"test\"\n}'
        create_rule(b, 'testme2', mycode)
    
        rule = get_rule(b, 'testme2')
        print rule.text
    
        delete_rule(b, 'testme2')

    Functions:

     

    def get_ruleset(bigip):
        rules = bigip.get('%s/ltm/rule/' % b_url_base)
        return rules
    
    def get_rule(bigip, name):
        rule = bigip.get('%s/ltm/rule/%s' % (b_url_base, name))
        return rule
    
    def delete_rule(bigip, name):
        bigip.delete('%s/ltm/rule/%s' % (b_url_base, name))
    
    def create_rule(bigip, name, code):
        payload = {}
        payload['kind'] = 'tm:ltm:rule:rulestate'
        payload['name'] = name
        payload['fullPath'] = name
        payload['apiAnonymous'] = code
    
        bigip.post('%s/ltm/rule/' % b_url_base, data=json.dumps(payload))
        print 'Rule %s created...' % name
  • James, according to the release notes it was fixed in 11.5. I assume Jason's code is talking to that version. I haven't had the time to try it myself yet, but will soon in one of our clusters.

     

    We're now managing all configurations using the REST API (even though I had to manually upload irules I could still download and diff them) and everything is safe in a version control system. No more mystery changes from someone doing something stupid in the GUI. :-)