- REST APIのPUTを使って複数のデバイスへCLIテンプレートを適用。
- 以下は1デバイスの場合のJSONペイロードです。複数デバイスの場合はPythonのFORループでそれぞれのデバイスへPUTを行いますが、PUTの度にジョブが作成されます!数百台のデバイスの場合、数百のジョブができます。
{
"cliTemplateCommand" : {
"targetDevices" : {
"targetDevice" : {
"targetDeviceID" : "122421412",
"variableValues" : {
"variableValue" : {
"name" : "comString",
"value" : "API_Com_String"
}
}
}
},
"templateName" : "SNMP_Template"
}
}
パラメータとデバイスのリストを用意します。"targetDevice" はこのようなリストになります。
{
"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"
}
}
- それぞれのデバイスのPUTのステータスはどのようにわかるのでしょう。
この “deployTemplateThroughJob” メソッドはジョブでステータスを提供します。もし100台のデバイスへプッシュし、4台失敗していたとしたら、どのようにしてその4台の確認できるでしょう。Job run history APIで確認できます。
ジョブの詳細な履歴を確認できます。
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"
}
}
}
サマリーも利用できます: GET
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
コメント
0件のコメント
サインインしてコメントを残してください。