Forum Discussion

craigvphillips_'s avatar
craigvphillips_
Icon for Nimbostratus rankNimbostratus
Jun 06, 2017

Adding an irule via put

Trying to add an irule to a few thousand virtuals and it does't work.

 

I can PATCH

 

{"rules": [
        "awesomerule"
        ]
}

and it works, but it replaces the irule list with the single irule... I don't want to do this, i want to update.

 

If i try and PUT the above json, i get:

 

{
  "code": 400,
  "message": "0107028c:3: The source (::) and destination (10.10.10.10) addresses for virtual server (/Common/coolserver) must be be the same type (IPv4 or IPv6).",
  "errorStack": [],
  "apiError": 3
}

1 Reply

  • Use

    POST
    to create an iRule and
    PATCH
    to modify the content (script). e.g.,

    Creating an iRule "test" (under /Common):

    curl -sku admin:secret -X POST -H "Content-Type: application/json" \
      -d '{"name": "test" }' \
      https://mgmtPort/mgmt/tm/ltm/rule
    

    Output:

    {"kind":"tm:ltm:rule:rulestate","name":"test","partition":"Common","fullPath":"/Common/test","generation":1745,"selfLink":"https://localhost/mgmt/tm/ltm/rule/~Common~test?ver=12.1.2"}
    

    Add the script to the rule "test":

    curl -sku admin:secret -X PATCH -H "Content-Type: application/json" \
      -d '{"apiAnonymous":"when CLIENT_ACCEPTED {log local0. \"hello world\"}" }' \ 
      https://mgmtPort/mgmt/tm/ltm/rule/test
    

    Output:

    {"kind":"tm:ltm:rule:rulestate","name":"test","fullPath":"test","generation":1746,"selfLink":"https://localhost/mgmt/tm/ltm/rule/test?ver=12.1.2","apiAnonymous":"when CLIENT_ACCEPTED {log local0. \"hello world\"}"}
    

    Verify on the LTM:

     tmsh list ltm rule test
    ltm rule test {
        when CLIENT_ACCEPTED {log local0. "hello world"}
    }
    

    This overrides the existing content:

    curl -sku admin:secret -X PATCH -H "Content-Type: application/json" \
      -d '{"apiAnonymous":"when HTTP_REQUEST {log local0. \"Bonjour monde\"}" }' \ 
      https://mgmtPort/mgm/tm/ltm/rule/test
    

    Verify:

     tmsh list ltm rule test
    ltm rule test {
        when HTTP_REQUEST {log local0. "Bonjour monde"}
    }