cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1247
Views
2
Helpful
1
Replies

Creating multiple objects with one api call

Doug Byrd
Contributor
Contributor

Hello,

     I am trying to right a script to configure a pair of leaves that will be used as a vpc pair.  I would like to be able to create the switch profiles in a single API call (L105, L106, L105-L106).  However, I can't seem to get it to configure all three.  It will only configure the first one listed.

Is there a way to do this or do I just need to iterate over the nodes to create the profiles.

Thanks!

Below is the payload I'm using

{

  "imdata": [

  {

    "infraNodeP": {

      "attributes": {

        "descr": "",

        "dn": "uni/infra/nprof-L105",

        "name": "L105",

        "nameAlias": "",

        "ownerKey": "",

        "ownerTag": ""

      },

      "children": [{

        "infraRsAccPortP": {

          "attributes": {

            "tDn": "uni/infra/accportprof-IP-L105"

          }

        }

      },

      {

        "infraLeafS": {

          "attributes": {

            "descr": "",

            "name": "Leaf105",

            "nameAlias": "",

            "ownerKey": "",

            "ownerTag": "",

            "type": "range"

          },

          "children": [{

            "infraNodeBlk": {

              "attributes": {

                "descr": "",

                "from_": "105",

                "name": "Node105",

                "nameAlias": "",

                "to_": "105"

              }

            }

          }]

        }

      }]

    }

  },

  {

    "infraNodeP": {

      "attributes": {

        "descr": "",

        "dn": "uni/infra/nprof-L106",

        "name": "L106",

        "nameAlias": "",

        "ownerKey": "",

        "ownerTag": ""

      },

      "children": [{

        "infraRsAccPortP": {

          "attributes": {

            "tDn": "uni/infra/accportprof-IP-L106"

          }

        }

      },

      {

        "infraLeafS": {

          "attributes": {

            "descr": "",

            "name": "Leaf106",

            "nameAlias": "",

            "ownerKey": "",

            "ownerTag": "",

            "type": "range"

          },

          "children": [{

            "infraNodeBlk": {

              "attributes": {

                "descr": "",

                "from_": "106",

                "name": "Node106",

                "nameAlias": "",

                "to_": "106"

              }

            }

          }]

        }

      }]

    }

  },{ 

    "infraNodeP": {

      "attributes": {

        "descr": "",

        "dn": "uni/infra/nprof-L105-L106",

        "name": "L105-L106",

        "nameAlias": "",

        "ownerKey": "",

        "ownerTag": ""

      },

      "children": [{

        "infraRsAccPortP": {

          "attributes": {

            "tDn": "uni/infra/accportprof-IP-L105-L106"

          }

        }

      },

      {

        "infraLeafS": {

          "attributes": {

            "descr": "",

            "name": "Leaf105-Leaf106",

            "nameAlias": "",

            "ownerKey": "",

            "ownerTag": "",

            "type": "range"

          },

          "children": [{

            "infraNodeBlk": {

              "attributes": {

                "descr": "",

                "from_": "105",

                "name": "Node105-106",

                "nameAlias": "",

                "to_": "106"

              }

            }

          }]

        }

      }]

    }

  }]

}

1 Reply 1

sebas.jacobs
Beginner
Beginner

Hi Doug,

Not sure which url your posting to ? You can use "{{protocol}}://{{apic}}/api/node/mo/uni/infra.json" for this api call.

For the body you will need to iterate this one i think. Make three seperate api calls and fire them to the above api object.

Below a example of the call itself.

[{

  "infraNodeP": {

    "attributes": {

      "descr": "",

      "name": "{{Switch Policies}}"

    },

    "children": [{

      "infraLeafS": {

        "attributes": {

          "descr": "",

          "name": "{{Leaf Selector}}",

          "type": "range"

        },

        "children": [{

          "infraNodeBlk": {

            "attributes": {

              "descr": "",

              "from_": "{{from}}",

              "name": "{{Node-id}}",

              "to_": "{{to}}"

            }

          }

        }]

      }

    },

    {

      "infraRsAccPortP": {

        "attributes": {

          "tDn": "uni/infra/accportprof-{{Interface Policies}}"

        }

      }

    }]

  }

}]

It is advisable to strip all unused object from your calls to keep them readable. Also try using name formatting for the objects you create (suffix/prefix) since this will greatly help you in the future with troubleshooting and such.

Hope this helps

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers