cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1132
Views
0
Helpful
4
Replies

Post and Delete static routes to APIC with postman

DuaBell
Level 1
Level 1

Hi Everyone,

I am busy testing a postman script to configure and remove static routes on the APIC(physical lab. version 4.2(7f)).

Below is the json script in postman and I use a runner to reference a .csv for a list of ip addresses:

        {
            "ipRouteP": {
                "attributes": {
                    "descr": "{{descr}}",
                    "dn": "uni/tn-AF-Prod-TnT/out-AF-L3out-Config/lnodep-AF-L3out-Config_nodeProfile/rsnodeL3OutAtt-[topology/pod-1/node-101]/rt-[{{SUBNETS}}]",
                    "ip": "{{SUBNETS}}",
                    "name": "",
                    "nameAlias": "",
                    "pref": "1",
                    "rtCtrl": ""
                },
                "children": [
                    {
                        "ipNexthopP": {
                            "attributes": {
                                "descr": "",
                                "name": "",
                                "nameAlias": "",
                                "nhAddr": "{{ipNexthopP}}",
                                "pref": "1",
                                "type": "prefix"
                            }
                        }
                    }
                ]
            }
        }
    ]
}
This works well for importing the list of static routes. However, when deleting the static routes I noticed that the "node" under "Configured Nodes" gets deleted and I have to create and a associate a new node. See attached images for the before and after.
 
Has anyone experienced the same issue? 
2 Accepted Solutions

Accepted Solutions

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi @DuaBell 

As far as I see, not the full json body is listed. Can you share it all?

Also, how do you perform the "creation" and "deletion" action? Do you send a POST for "creation" and a DELETE for "deletion"?

Or you always send a POST and change the "status" attribute from "created" to "deleted"?

My guess is that you use a "DELETE" method against the "l3extRsNodeL3OutAtt" object, which if this is the case, then it's expected what you see. The correct way should be to always use POST method and  use "status" attribute.

Example:

Create static route:

Method: POST
URL: https://{{apic_ip}}/api/mo/uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}.json
Body:

{
  "ipRouteP": {
    "attributes": {
      "aggregate": "no",
      "annotation": "",
      "descr": "{{route_description}}",
      "dn": "uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}/rsnodeL3OutAtt-[topology/pod-1/node-{{node_id}}]/rt-[{{prefix}}]",
      "fromPfxLen": "0",
      "ip": "{{prefix}}",
      "name": "",
      "nameAlias": "",
      "pref": "1",
      "rtCtrl": "",
      "toPfxLen": "0",
      "status":"created"
    },
    "children": [
      {
        "ipNexthopP": {
          "attributes": {
            "annotation": "",
            "descr": "{{nh_description}}",
            "name": "",
            "nameAlias": "",
            "nhAddr": "{{next_hop}}",
            "pref": "unspecified",
            "type": "prefix"
          }
        }
      }
    ]
  }
}

Delete static route:

Method: POST
URL: https://{{apic_ip}}/api/mo/uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}.json
Body:

{
  "ipRouteP": {
    "attributes": {
      "aggregate": "no",
      "annotation": "",
      "descr": "{{route_description}}",
      "dn": "uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}/rsnodeL3OutAtt-[topology/pod-1/node-{{node_id}}]/rt-[{{prefix}}]",
      "fromPfxLen": "0",
      "ip": "{{prefix}}",
      "name": "",
      "nameAlias": "",
      "pref": "1",
      "rtCtrl": "",
      "toPfxLen": "0",
      "status":"deleted"
    },
    "children": [
      {
        "ipNexthopP": {
          "attributes": {
            "annotation": "",
            "descr": "{{nh_description}}",
            "name": "",
            "nameAlias": "",
            "nhAddr": "{{next_hop}}",
            "pref": "unspecified",
            "type": "prefix"
          }
        }
      }
    ]
  }
}

 

Take care,

Sergiu

View solution in original post

You don't have to send all attributes. Just the mandatory ones (same as in GUI).

Also, if the route (or any other MO you want to change via API) is already configured, and you want to change any attributes, you must use the following status:

                  "status":"created,modified"

 

Take care,

Sergiu

View solution in original post

4 Replies 4

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi @DuaBell 

As far as I see, not the full json body is listed. Can you share it all?

Also, how do you perform the "creation" and "deletion" action? Do you send a POST for "creation" and a DELETE for "deletion"?

Or you always send a POST and change the "status" attribute from "created" to "deleted"?

My guess is that you use a "DELETE" method against the "l3extRsNodeL3OutAtt" object, which if this is the case, then it's expected what you see. The correct way should be to always use POST method and  use "status" attribute.

Example:

Create static route:

Method: POST
URL: https://{{apic_ip}}/api/mo/uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}.json
Body:

{
  "ipRouteP": {
    "attributes": {
      "aggregate": "no",
      "annotation": "",
      "descr": "{{route_description}}",
      "dn": "uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}/rsnodeL3OutAtt-[topology/pod-1/node-{{node_id}}]/rt-[{{prefix}}]",
      "fromPfxLen": "0",
      "ip": "{{prefix}}",
      "name": "",
      "nameAlias": "",
      "pref": "1",
      "rtCtrl": "",
      "toPfxLen": "0",
      "status":"created"
    },
    "children": [
      {
        "ipNexthopP": {
          "attributes": {
            "annotation": "",
            "descr": "{{nh_description}}",
            "name": "",
            "nameAlias": "",
            "nhAddr": "{{next_hop}}",
            "pref": "unspecified",
            "type": "prefix"
          }
        }
      }
    ]
  }
}

Delete static route:

Method: POST
URL: https://{{apic_ip}}/api/mo/uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}.json
Body:

{
  "ipRouteP": {
    "attributes": {
      "aggregate": "no",
      "annotation": "",
      "descr": "{{route_description}}",
      "dn": "uni/tn-{{tn_name}}/out-{{l3out_name}}/lnodep-{{nodeProfile_name}}/rsnodeL3OutAtt-[topology/pod-1/node-{{node_id}}]/rt-[{{prefix}}]",
      "fromPfxLen": "0",
      "ip": "{{prefix}}",
      "name": "",
      "nameAlias": "",
      "pref": "1",
      "rtCtrl": "",
      "toPfxLen": "0",
      "status":"deleted"
    },
    "children": [
      {
        "ipNexthopP": {
          "attributes": {
            "annotation": "",
            "descr": "{{nh_description}}",
            "name": "",
            "nameAlias": "",
            "nhAddr": "{{next_hop}}",
            "pref": "unspecified",
            "type": "prefix"
          }
        }
      }
    ]
  }
}

 

Take care,

Sergiu

Hi Sergiu,

Thanks for your prompt and valuable response.

I was sending a POST for creation and a DELETE for deletion of static routes. I see where i made my mistake and i did not send a POST to change the STATUS attribute (which makes sense). I will adjust the script and test again....

One more question, when creating the json script do I have to add all the attributes or can I only add those attributes that I want to change?

You don't have to send all attributes. Just the mandatory ones (same as in GUI).

Also, if the route (or any other MO you want to change via API) is already configured, and you want to change any attributes, you must use the following status:

                  "status":"created,modified"

 

Take care,

Sergiu

thanks, I will add that to my test.

Save 25% on Day-2 Operations Add-On License