Forum Discussion

dotsonpaper_280's avatar
dotsonpaper_280
Icon for Nimbostratus rankNimbostratus
Oct 14, 2017

How To Delete An irule using Rest API with CURL

Hello,

I am a bit stumped. I know I can add an irule using the rest api running the following command:

curl -sku ':' -H "Content-Type: application/json" -X PATCH https://bigip1/mgmt/tm/ltm/virtual/virtual-server -d '{"rules": ["/Common/cool-irule"] }'

but for the life of me I can not figure out the payload to remove an irule. I am 2 hours into testing and research and I am stumped. Any ideas would be appreciated.

5 Replies

  • Hygor's avatar
    Hygor
    Icon for Nimbostratus rankNimbostratus

    Hi, You can do that using python sdk:

    import requests
    from f5.bigip import ManagementRoot
    requests.packages.urllib3.disable_warnings()
    
    connect to your F5
    b = ManagementRoot('your_f5_mgmt_ip', 'user', 'pass')
    
    load the rule
    rule1 = b.tm.ltm.rules.rule.load(name='irule_delete', partition='Common')
    
    Delete the Rule
    rule1.delete()
    

    Regards,

    Hygor

  • This works for 12.1.0

    curl -ku 'user:pass' -X DELETE https://bigip1/mgmt/tm/ltm/rule/cool-irule
    
  • Hygor,

     

    Thank you for the response. We are trying to keep these as API calls back to the F5. Also, the proposed solution would work to delete an irule but it would not work to remove an assigned irule from a VIP.

     

    Regards,

     

    Javier

     

  • Hygor's avatar
    Hygor
    Icon for Nimbostratus rankNimbostratus

    Ok, you want to remove the irule from the virtual server. Here is how you can do that:

    import requests
    from f5.bigip import ManagementRoot
    requests.packages.urllib3.disable_warnings()
    
    connect to your F5
    b = ManagementRoot('your_f5_mgmt_ip', 'user', 'pass')
    
    load the virtual server
    vip = b.tm.ltm.virtuals.virtual.load(name='vs_name')
    
    list irules in vs
    vip.rules
    [u'/Common/irule1', u'/Common/irule2']
    
    In this case we'll remove the irule2. The irule1 will remain in the virtual server
    vip.rules = ['/Common/irule1']
    
    update the configuration
    vip.update()
    

    Hope that it helps you. Regards,

    Hygor