Forum Discussion

Gesquiere_12886's avatar
Gesquiere_12886
Icon for Nimbostratus rankNimbostratus
Jul 30, 2018

How to apply a ltm policy to a virtual with icontrolRest on BigIp F5

Hello,

 

BigIp F5 Version 11.5.4. I've created a ltm policy with IcontrolRest : POST https:///mgmt/tm/ltm/policy/ + Json Now I try to apply this policy to a virtual server. I've tried a lot of uri and json bodies, and in all the cases reception of http code 400.

 

 

For example (found on a forum) : Uri : /mgmt/tm/ltm/virtual/~~ -> POST Body : { "policies:"//" } -> "code":400,"message":"Missing name."

 

 

Other Test :

 

Uri : /mgmt/tm/ltm/virtual/~~/policies -> POST Body : { "kind": "tm:ltm:virtual:policies:policiescollectionstate", "selfLink": "~~/policies?ver=11.5.4", "policiesReference": { "link": "~~/policies?ver=11.5.4", "isSubcollection": true, "items": [ { "kind": "tm:ltm:virtual:policies:policiesstate", "name": "", "partition": "", "fullPath": "//", "generation": 135087, "selfLink": "~~/policies/~~?ver=11.5.4" } ] } }

 

 

-> "code":400,"message":"Missing name."

 

An Idea ?

 

Thanks

 

Dominique

 

1 Reply

  • "Missing name" sounds like the request didn't have the name of the policy.

    Take a look at the JSON object you get when you query (GET) the virtual. e.g.,

     curl -sku admin: https:///mgmt/tm/ltm/virtual/vs\?\$select=policiesReference\&expandSubcollections=true
    

    where vs is the virtual. An example output as below:

    {
        "policiesReference": {
            "isSubcollection": true,
            "items": [
                {
                    "fullPath": "/Common/TestPolicy",
                    "generation": 20,
                    "kind": "tm:ltm:virtual:policies:policiesstate",
                    "name": "TestPolicy",
                    "nameReference": {
                        "link": "https://localhost/mgmt/tm/ltm/policy/~Common~TestPolicy?ver=13.1.0.3"
                    },
                    "partition": "Common",
                    "selfLink": "https://localhost/mgmt/tm/ltm/virtual/~Common~vs/policies/~Common~TestPolicy?ver=13.1.0.3"
                }
            ],
            "link": "https://localhost/mgmt/tm/ltm/virtual/~Common~vs/policies?ver=13.1.0.3"
        }
    }
    

    The

    policiesReference
    contains the
    items
    , and the items is an array (list) of the multiple policy objects. In each policy object, there is a
    name
    field. Specify the policy you want to attach. For example,

     curl -sku admin: https:///mgmt/tm/ltm/virtual/vs \
     -H "Content-type: application/json" -X PATCH \
     -d '{"policiesReference":{ "items":[ {"name":"TestPolicy"} ] } }'
    

    Be careful with the closing ] and } as the data is heavily nested.