08-24-2016 10:22 PM
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"
}
}
Solved! Go to Solution.
08-25-2016 02:55 AM
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"
}
}
08-25-2016 02:55 AM
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"
}
}
08-25-2016 04:21 PM
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…
08-26-2016 03:38 PM
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"
}
}
}
08-26-2016 03:39 PM
08-28-2016 04:58 PM
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"
}
}
}
}
}
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide