cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2483
Views
4
Helpful
5
Replies

deployTemplateThroughJob to Multiple Devices from PI3.0 API

choywy
Level 1
Level 1

Hi,

I was trying to deploy CLI template using PUT REST API(Using Python). I manage to do iit to one device. But I'm stuck when I try to multiple devices.

Below is the JSON payload for one device. How does it look like for multiple devices? I can run a FOR loop in python and PUT to each device but the problem is each PUT will create a new Job!! Hence, if I have a few hundred devices, my Job table will have hundreds over jobs!!!

Any help will be greatly appreciated.....

{

  "cliTemplateCommand" : {

  "targetDevices" : {

  "targetDevice" : {

  "targetDeviceID" : "122421412",

  "variableValues" : {

  "variableValue" : {

  "name" : "comString",

  "value" : "API_Com_String"

  }

  }

  }

  },

  "templateName" : "SNMP_Template"

  }

}

1 Accepted Solution

Accepted Solutions

aradford
Cisco Employee
Cisco Employee

Hi,

you can supply a list of devices with parameters.  Notice how "targetDevice" can be a list.

{

  "cliTemplateCommand" : {

    "targetDevices" : {

      "targetDevice" : [{

        "targetDeviceID" : "610622",

        "variableValues" : {

          "variableValue": [

            {

              "name": "InterfaceName",

              "value": "gigabitethernet1/0/2"

            },

            {

              "name": "Description",

              "value": "Fred1"

            },

            {

              "name": "StaticAccessVLan",

              "value": "8"

            },

            {

              "name": "A1",

              "value": "Access"

            },

            { "name": "NativeVLan", "value": ""},

            { "name": "duplexField","value": ""},

            { "name": "TrunkAllowedVLan","value": "" },

            { "name": "spd","value": "" },

            { "name": "VoiceVlan" ,"value": ""},

            { "name": "PortFast","value": "" }

          ]

        }

      },

      {

        "targetDeviceID" : "8624616",

        "variableValues" : {

          "variableValue": [

            {

              "name": "InterfaceName",

              "value": "gigabitethernet1/0/2"

            },

            {

              "name": "Description",

              "value": "Fred1"

            },

            {

              "name": "StaticAccessVLan",

              "value": "8"

            },

            {

              "name": "A1",

              "value": "Access"

            },

            { "name": "NativeVLan", "value": ""},

            { "name": "duplexField","value": ""},

            { "name": "TrunkAllowedVLan","value": "" },

            { "name": "spd","value": "" },

            { "name": "VoiceVlan" ,"value": ""},

            { "name": "PortFast","value": "" }

          ]

        }

      }

      ]

    },

    "templateName" : "Configure Interface"

  }

}

View solution in original post

5 Replies 5

aradford
Cisco Employee
Cisco Employee

Hi,

you can supply a list of devices with parameters.  Notice how "targetDevice" can be a list.

{

  "cliTemplateCommand" : {

    "targetDevices" : {

      "targetDevice" : [{

        "targetDeviceID" : "610622",

        "variableValues" : {

          "variableValue": [

            {

              "name": "InterfaceName",

              "value": "gigabitethernet1/0/2"

            },

            {

              "name": "Description",

              "value": "Fred1"

            },

            {

              "name": "StaticAccessVLan",

              "value": "8"

            },

            {

              "name": "A1",

              "value": "Access"

            },

            { "name": "NativeVLan", "value": ""},

            { "name": "duplexField","value": ""},

            { "name": "TrunkAllowedVLan","value": "" },

            { "name": "spd","value": "" },

            { "name": "VoiceVlan" ,"value": ""},

            { "name": "PortFast","value": "" }

          ]

        }

      },

      {

        "targetDeviceID" : "8624616",

        "variableValues" : {

          "variableValue": [

            {

              "name": "InterfaceName",

              "value": "gigabitethernet1/0/2"

            },

            {

              "name": "Description",

              "value": "Fred1"

            },

            {

              "name": "StaticAccessVLan",

              "value": "8"

            },

            {

              "name": "A1",

              "value": "Access"

            },

            { "name": "NativeVLan", "value": ""},

            { "name": "duplexField","value": ""},

            { "name": "TrunkAllowedVLan","value": "" },

            { "name": "spd","value": "" },

            { "name": "VoiceVlan" ,"value": ""},

            { "name": "PortFast","value": "" }

          ]

        }

      }

      ]

    },

    "templateName" : "Configure Interface"

  }

}

Hi Adam,

Bingo…It works….But stuck in another problem….

How do I find out the PUT status of individual device?

This “deployTemplateThroughJob” method will provide status on the Job itself. If I push 100 devices and 4 devices fail, how do I find out which of that 4 devices fail? Coz’ the Job runhistory API only give the Job status but not in device detail….

Any idea?

Thanks…

sure,  you can look at the full history of the job.

GET https://{{pi-server}}/webacs/api/v1/op/jobService/runhistory.json?jobName=JobCliTemplateDeployIOSDevices08_32_27_953_AM_08_27_2016

{

  "mgmtResponse": {

    "@responseType": "operation",

    "@requestUrl": "https://adam-pi/webacs/api/v1/op/jobService/runhistory?jobName=JobCliTemplateDeployIOSDevices08_32_27_953_AM_08_27_2016",

    "@rootUrl": "https://adam-pi/webacs/api/v1/op",

    "job": {

      "description": "Cli Template Deploy for IOS devices",

      "jobId": 8897938,

      "jobName": "JobCliTemplateDeployIOSDevices08_32_27_953_AM_08_27_2016",

      "jobStatus": "COMPLETED",

      "jobType": "CliTemplateDeployIOSDevices",

      "runInstances": {

        "runInstance": {

          "completionTime": "2016-08-27T08:33:00.052+10:00",

          "lastStartTime": "2016-08-27T08:32:58.024+10:00",

          "resultStatus": "SUCCESS",

          "results": {

            "result": [

              {

                "property": 610622,

                "value": "configlet:\n        interface gigabitethernet1/0/2\n                   description Fred2\n                            switchport mode access\n                            switchport ACCess vlan 8   \n                            \n               \n        \n        \n        \n        \n         \n        exit\n\n\n\n\n\n\n\n\n\n\n response:\n<cliChunks><cliChunk><cli>terminal width 0\nconfig t\ninterface gigabitethernet1/0/2\ndescription Fred2\nswitchport mode access\nswitchport ACCess vlan 8\nexit\n</cli><response><![CDATA[terminal width 0\n3650-dns#config t\nEnter configuration commands, one per line.  End with CNTL/Z.\n3650-dns(config)#interface gigabitethernet1/0/2\n3650-dns(config-if)#description Fred2\n3650-dns(config-if)#switchport mode access\n3650-dns(config-if)#switchport ACCess vlan 8\n3650-dns(config-if)#exit\n3650-dns(config)#]]></response></cliChunk></cliChunks>"

              },

              {

                "property": "JobCliTemplateDeployIOSDevices08_32_27_953_AM_08_27_2016",

                "value": "2/2 template configurations successfully applied."

              },

              {

                "property": 8624616,

                "value": "configlet:\n        interface gigabitethernet1/0/2\n                   description Fred2\n                            switchport mode access\n                            switchport ACCess vlan 8   \n                            \n               \n        \n        \n        \n        \n         \n        exit\n\n\n\n\n\n\n\n\n\n\n response:\n<cliChunks><cliChunk><cli>terminal width 0\nconfig t\ninterface gigabitethernet1/0/2\ndescription Fred2\nswitchport mode access\nswitchport ACCess vlan 8\nexit\n</cli><response><![CDATA[terminal width 0\n3650-dhcp#config t\nEnter configuration commands, one per line.  End with CNTL/Z.\n3650-dhcp(config)#interface gigabitethernet1/0/2\n3650-dhcp(config-if)#description Fred2\n3650-dhcp(config-if)#switchport mode access\n3650-dhcp(config-if)#switchport ACCess vlan 8\n3650-dhcp(config-if)#exit\n3650-dhcp(config)#]]></response></cliChunk></cliChunks>"

              }

            ]

          },

          "runId": 14722720,

          "runStatus": "COMPLETED"

        }

      }

    }

You can also GET summary too:

https://{{pi-server}}/webacs/api/v1/data/JobSummary/8897938.json

https://{{pi-server}}/webacs/api/v1/data/JobSummary.json?jobName=JobCliTemplateDeployIOSDevices08_32_27_953_AM_08_27_2016

Strange…I use the following API to deploy and check the Job status…For the runhistory API, I didn’t get the detail listing of each device (eg. Configlet..etc)? Do I need to turn on some options?

https://pi-test/webacs/api/v1/op/cliTemplateConfiguration/deployTemplateThroughJob

{

"cliTemplateCommand" : {

"targetDevices" : {

"targetDevice" : [{

"targetDeviceID" : "11178829663",

"variableValues" : {

"variableValue": [

{

"name": "Seq",

"value": "36"

}

]

}

},

{

"targetDeviceID" : "12109061967",

"variableValues" : {

"variableValue": [

{

"name": "Seq",

"value": "36"

}

]

}

}

]

},

"templateName" : "Test_ACL "

}

}

https://pi-test/webacs/api/v1/op/jobService/runhistory?jobName=JobCliTemplateDeployIOSDevices09_48_24_474_AM_08_29_2016

{

"mgmtResponse": {

"@rootUrl": "https://pi-test/webacs/api/v1/op",

"@requestUrl": "https://pi-test/webacs/api/v1/op/jobService/runhistory?jobName=JobCliTemplateDeployIOSDevices09_48_24_474_AM_08_29_2016",

"@responseType": "operation",

"job": {

"description": "Cli Template Deploy for IOS devices",

"jobId": 12289268062,

"jobName": "JobCliTemplateDeployIOSDevices09_48_24_474_AM_08_29_2016",

"jobStatus": "COMPLETED",

"jobType": "CliTemplateDeployIOSDevices",

"runInstances": {

"runInstance": {

"completionTime": "2016-08-29T09:49:03.626+10:00",

"lastStartTime": "2016-08-29T09:48:54.597+10:00",

"resultStatus": "SUCCESS",

"results": "",

"runId": 12326851611,

"runStatus": "COMPLETED"

}

}

}

}

}

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: