# What is the proper way to redfine an iRule through iControl?

**URL:** <https://community.f5.com/t/what-is-the-proper-way-to-redfine-an-irule-through-icontrol/9825>\
**Category:** Technical Forums\
**Tags:** f5-icontrol, design, icontrol, irules, devops, ltm, application-delivery\
**Created:** [August 5, 2014, 1:43pm UTC](https://community.f5.com/t/what-is-the-proper-way-to-redfine-an-irule-through-icontrol/9825 "2014-08-05T13:43:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZHarvey\_164362](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@ZHarvey\_164362](https://community.f5.com/u/ZHarvey_164362)\
**Post date:** [August 5, 2014, 1:43pm UTC](https://community.f5.com/t/what-is-the-proper-way-to-redfine-an-irule-through-icontrol/9825/1 "2014-08-05T13:43:42Z")

</div>

I am looking for a way to dynamically redefine iRules via the iControl API. By “redefine”, I mean, rewriting the “Definition” (RuleDefinition).

I see that LocalLBRule::query\_rule can be passed the name of the rule and retrieve the definition of the given rule.

I also see a LocalLBRule::create and an LocalLBRule::delete method, but no LocalLBRule::update or LocalLBRule::save.

I was hoping to be able to: 1. LocalLBRule::query\_rule =\> to get the definition of a certain rule 2. Modify the rule in code 3. LocalLBRule::save or LocalLBRule::update =\> but no such method exists

So I ask: how can I do this?

---

<div class="post-metadata">

**Author:** ![dihris\_116090](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dihris\_116090](https://community.f5.com/u/dihris_116090)\
**Post date:** [February 23, 2015, 5:52am UTC](https://community.f5.com/t/what-is-the-proper-way-to-redfine-an-irule-through-icontrol/9825/2 "2015-02-23T05:52:10Z")

</div>

I’ve been looking for the same type if iControl script. Did anyone find a solution?

---

<div class="post-metadata">

**Author:** ![chub\_zh\_185747](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@chub\_zh\_185747](https://community.f5.com/u/chub_zh_185747)\
**Post date:** [February 23, 2015, 1:06pm UTC](https://community.f5.com/t/what-is-the-proper-way-to-redfine-an-irule-through-icontrol/9825/3 "2015-02-23T13:06:39Z")

</div>

// This is Groovy code; you may need to Java-ify it.

// Write the new definition of the iRule.

String newRule = “NEW\_IRUL\_DEF\_HERE”

// Instantiate a new rule def, make sure to give it the same name as the one you want to modify.

LocalLBRuleRuleDefinition ruleDef = new LocalLBRuleRuleDefinition(“NAME\_OF\_RULE”, newRule)

LocalLBRuleRuleDefinition[] ruleDefs = new LocalLBRuleRuleDefinition[1]

ruleDefs[0] = ruleDef

// Tell F5 you wish to modify the iRule. It will look up the existing “Name of rule” and overwrite it with ‘newRule’. f5Interface.getLocalLBRule().modify\_rule(ruleDefs)

// I _despise_ the iControl Java API and wish someone at F5 would provide a modern, non-mechanically generated, OO client access JAR for it.

---

<div class="post-metadata">

**Author:** ![dihris\_116090](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dihris\_116090](https://community.f5.com/u/dihris_116090)\
**Post date:** [February 24, 2015, 4:25am UTC](https://community.f5.com/t/what-is-the-proper-way-to-redfine-an-irule-through-icontrol/9825/4 "2015-02-24T04:25:00Z")

</div>

Not very familiar with Java so I used SOAP:

$iRDefine = { rule\_name =\> $iRName, rule\_definition =\> $iRdata};

$soapResponse = $LocalLBRule-\>modify\_rule(SOAP::Data-\>name(rules =\> [$iRDefine]

But getting the following error: primary\_error\_code: 16908390 (0x1020066) secondary\_error\_code: 0 error\_string: 01020066:3: The requested iRule (/Common/test\_iRule) already exists in partition Common.

Still battling to find what is the issue.

---

<div class="post-metadata">

**Author:** ![dihris\_116090](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dihris\_116090](https://community.f5.com/u/dihris_116090)\
**Post date:** [February 24, 2015, 5:02am UTC](https://community.f5.com/t/what-is-the-proper-way-to-redfine-an-irule-through-icontrol/9825/5 "2015-02-24T05:02:05Z")

</div>

Fixed myself. Had to append “/Common/” to the iRule name in the script. Now works fine.
