For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

How to add iRule and http profile to a virtual server

Problem this snippet solves:

  1. First do a Simple Post to create a Virtual Server
  2. Then attach the iRule and Http profile to the virtual server

How to use this snippet:

We need to create a Separate json file for Step 1. For step 2 make sure you have the iRule already present in the BIG-IP, else you need to create one.

Code :

curl -k --user admin:admin -H "Accept: application/json" -H "Content-Type:application/json" -X POST -d@ServiceRouting_forHTTP.json https://173.36.215.237/mgmt/tm/ltm/virtual/ | python -m json.tool


Payload file below ServiceRouting_forHTTP.json

{
    "addressStatus": "yes",
    "autoLasthop": "default",
    "cmpEnabled": "yes",
    "connectionLimit": 0,
    "destination": "/Common/192.168.32.11:80",
    "enabled": true,
    "fullPath": "ServiceRouting_forHTTP",
    "generation": 37093,
    "gtmScore": 0,
    "ipProtocol": "tcp",
    "kind": "tm:ltm:virtual:virtualstate",
    "mask": "255.255.255.255",
    "mirror": "disabled",
    "mobileAppTunnel": "disabled",
    "name": "ServiceRouting_forHTTP",
    "nat64": "disabled",
    "policiesReference": {
        "isSubcollection": true,
        "link": "https://localhost/mgmt/tm/ltm/virtual/~Common~ServiceRouting_forHTTP/policies?ver=11.5.3"
    },
    "pool": "/Common/S4HPool",
    "profilesReference": {
        "isSubcollection": true,
        "link": "https://localhost/mgmt/tm/ltm/virtual/~Common~ServiceRouting_forHTTP/profiles?ver=11.5.3"
    },
    "rateLimit": "disabled",
    "rateLimitDstMask": 0,
    "rateLimitMode": "object",
    "rateLimitSrcMask": 0,
    "selfLink": "https://localhost/mgmt/tm/ltm/virtual/ServiceRouting_forHTTP?ver=11.5.3",
    "source": "0.0.0.0/0",
    "sourceAddressTranslation": {
        "type": "automap"
    },
    "sourcePort": "preserve",
    "synCookieStatus": "not-activated",
    "translateAddress": "enabled",
    "translatePort": "enabled",
    "vlansDisabled": true,
    "vsIndex": 32
}

  Then make a PUT so that we add the HTTP Profile and also the iRule

curl -s -k -u admin:admin -H 'Content-Type: application/json' -X PUT https://173.36.215.237/mgmt/tm/ltm/virtual/ServiceRouting_forHTTP -d '{"profiles":[{"name":"http"},{"name":"tcp"}], "rules": ["/Common/Testing_class"]}' |python -m json.tool

Tested this on version:

11.5
Published Jun 26, 2016
Version 1.0
No CommentsBe the first to comment