Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

Payload content to apply a rule

What is the payload content to apply a rule from the REST interface?

I am currently using PHP to interface with the REST API and I can connect and list all the rules, but now I need to apply one of the rules and later on I need to remove it, but not delete it.

Connecting to REST interface: https://devcentral.f5.com/codeshare/using-php-to-connect-to-icontrol-rest-interface-1172

Thank you,

Emil

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

You can also use my PHP class in Codeshare:

https://devcentral.f5.com/codeshare/php-and-icontrol-rest

include("iCR_class.php");
$r = new iCR ("172.24.9.129");
# Retrieve the iRule
$rule = $r->get("/ltm/rule/iRuleTest");
print_r($rule);
# Modify the iRule
$description = array('description' => 'This is a modified iRule');
print_r($r->modify("/ltm/rule/iRuleTest",$description));

Feel free to PM me with details if you want any help with this.

0
Comments on this Answer
Comment made 15-Oct-2018 by emilorol 6

Hi Pete,

Thank you for your answer, for some odd reason I was not able to login last week.

Just to make sure you understand my question let me break it on steps:

Step 1: Push existing iRule (created on F5) into virtual server that already contain other iRules.

Step 2: Pull that first added iRule from the virtual server and leaving the others intact

Note: I don't want to modify the iRule, just push it in and pull it out without affecting the other iRules on the virtual server.

0
Comment made 17-Oct-2018 by Pete White

Aha, I see. That makes sense. See below.

include("iCR_class.php");
$r = new iCR ("172.24.9.129");
# Add rule to the VS
# Retrieve the virtual server details
$vs = $r->get("/ltm/virtual/virtualTest");
# Create an array of the rules
$rules = array_push($vs['rules'], "/Common/iruleTest");
# Set the update array including the rules array as value
$mod = array('rules' => $rules);
$update = $r->modify("/ltm/virtual/virtualTest",$mod);

# Remove iRule from VS
# Retrieve the virtual server details
$vs = $r->get("/ltm/virtual/virtualTest");
# Create a new array without the iruleTest included
if (($key = array_search("iruleTest", $vs['rules'])) !== false) {
    unset($vs['rules'][$key]);
} 
$mod = array('rules' => $vs['rules']);
$update = $r->modify("/ltm/virtual/virtualTest",$mod);

I haven't tested this so it may need some debugging but maybe you can try it out and let me know how you get on

0
Comment made 22-Oct-2018 by emilorol 6

Thank you a lot for the help.

I do have one more question. Is there a way to list all existing virtual servers without knowing their name?

Once again, thank you.

0