06-13-2016 09:02 AM
Hi,
I have a query regarding the Cisco Prime Infrastructure API documentation hosted under URL: https://developer.cisco.com/site/prime-infrastructure/documents/api-reference/rest-api-v3-0/. I am using ReST apis mentioned in the above stated url to fetch inventory data from the Prime Infrastructure (PI) without using the GUI provided from the PI. Similarly I want to create VLAN on a switch using ReST api calls without using GUI.
My query is that can we create VLAN from ReST api calls? If so, is it through Cli templates?
According to the documentation mentioned above, it is said that we can download Cli templates for Configure vlan from the URL mentioned under "Get Cli Templates" section of the documentation and it is also said that we can deploy templates through jobs. Therefore, I followed the documentation and downloaded Cli template for Configure vlan and deployed it through job using the urls mentioned in the documentation, I am getting an error message saying "Invalid variable values" and the vlan is not being created.
Am I missing something here? Any advice for me ?
Thanks in advance
Solved! Go to Solution.
06-26-2016 10:38 PM
Hi Aradford,
I have solved the access issue. Now Job is not throwing any error, Job's run history says success, but how to check whether the vlan is created or not?. Following is the JSON body I am using.
Am I missing something here?
{
"cliTemplateCommand": {
"targetDevices": {
"targetDevice": {
"targetDeviceID": "074084",
"variableValues": {
"variableValue": [
{
"name": "encapsulation",
"value": ""
},
{
"name": "interfaceName",
"value": ""
},
{
"name": "mtu",
"value": ""
},
{
"name": "vlanid",
"value": "244"
},
{
"name": "vlanName",
"value": "vlan199"
},
{
"name": "mode",
"value": ""
},
{
"name": "option",
"value": ""
}
]
}
}
},
"templateName": "Configure VLAN"
}
}
06-26-2016 10:48 PM
Hi Arun,
almost there..
This particular template is to apply an VLAN to an interface. You need to specify an "name": "interfaceName", on the device.
For example "gig1/0/3" would apply vlan #244 to int gig1/0/3.
{ "name": "interfaceName",
"value" : "gig1/0/3"
}
If you just want to create a vlan on a device, there is another template for that. You can get a list of templates using the tools in the github repo i mentioned earlier.
Here is the schema for "create_vlan"
$ python get_template.py -n Add_Vlan -s
{
"cliTemplateCommand": {
"targetDevices": {
"targetDevice": {
"targetDeviceID": "<DEVICEID>",
"variableValues": {
"variableValue": [
{
"name": "vlanId",
"value": "required"
},
{
"name": "vlanName",
"value": "required"
}
]
}
}
},
"templateName": "Add_Vlan"
}
}
06-27-2016 12:45 AM
Hi Aradford,
I have tried the above specified JSON but I am sorry to say that "Add_Vlan" template does not exist in my instance of Cisco Prime.
Correct me If I am wrong. We can apply VLAN to an interface, only if that VLAN is already created and exists isn't it ? . Will configure VLAN template creates VLAN and add it to the interface?
06-27-2016 12:58 AM
sorry, that may be the case. I am using PI 3.1
However, if you want to assign the vlan to a switch port and the VLAN does not exist, the switch will create it for you.
3650-dns(config-if)#switchport access vlan 222
% Access VLAN does not exist. Creating vlan 222
3650-dns#show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
222 VLAN0222 active Gi1/0/10
Adam
06-27-2016 02:05 AM
Hi Aradford,
I am using Cisco Prime Infrastructure 3.0 instance. Should we give any option like "Create" for the "options" variable in the template to create VLAN from ReST APIs.
Thanks
06-27-2016 02:17 AM
If you look at the definition of the template ( you can use $ python get_template.py -n "Configure VLAN")
Option can be create or delete. You should set "Create"
{
"name": "option",
"value": "Create"
}
{
"displayLabel": "Operation",
"description": "Create,Delete",
"defaultValue": "Create,Delete",
"required": false,
"type": "Dropdown",
"name": "option"
}
06-27-2016 03:27 AM
Hi Aradford,
As suggested , following is the JSON I am using here. But still I am not able to see the VLAN being created. But I really wonder how job is complete and success?
{
"cliTemplateCommand": {
"targetDevices": {
"targetDevice": {
"targetDeviceID": "074084",
"variableValues": {
"variableValue": [
{
"name": "encapsulation",
"value": ""
},
{
"name": "interfaceName",
"value": "GigabitEthernet0/21"
},
{
"name": "mtu",
"value": ""
},
{
"name": "vlanid",
"value": "249"
},
{
"name": "vlanName",
"value": "vlan249"
},
{
"name": "mode",
"value": "Access"
},
{
"name": "option",
"value": "Create"
}
]
}
}
},
"templateName": "Configure VLAN"
}
}
06-27-2016 03:41 AM
That looks ok. If there is an issue, take a look at the detailed job history.
first you get the job name after you create job above.. I assume you have done the first part (got the job name)?
jobname = result.json()['mgmtResponse']['cliTemplateCommandJobResult']['jobName']
Then you monitor the job name until it completes
url = BASE + 'data/JobSummary.json?jobName=%s' %jobname
jobresult = requests.get(url, verify=False)
status = jobresult['queryResponse']['entityId'][0]['@displayName'].split(",")[-1]
# Status will be != "SCHEDULED" when job completes
Then you need to get the job number.
jobnumber = jobresult['queryResponse']['entityId'][0]['$']
from the job number, you can get the full information about the job.
url = base + 'data/JobSummary/%s.json' %jobnumber
jobdeteailresult = requests.get(url, verify=False)
print jobdetailresult.json()
That should show you something like the following:
{
"mgmtResponse": {
"@responseType": "operation",
"job": {
"description": "Cli Template Deploy for IOS devices",
"runInstances": {
"runInstance": {
"runStatus": "COMPLETED",
"results": {
"result": [
{
"property": "JobCliTemplateDeployIOSDevices08_40_09_490_PM_06_27_2016",
"value": "1/1 template configurations successfully applied."
},
{
"property": 610622,
"value": "configlet:\n interface gigabitethernet1/0/2\n description Fred1\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 Fred1\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 Fred1\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>"
}
]
},
"lastStartTime": "2016-06-27T20:40:39.565+10:00",
"completionTime": "2016-06-27T20:40:40.588+10:00",
"runId": 6365409,
"resultStatus": "SUCCESS"
}
},
"jobStatus": "COMPLETED",
"jobName": "JobCliTemplateDeployIOSDevices08_40_09_490_PM_06_27_2016",
"jobId": 560879,
"jobType": "CliTemplateDeployIOSDevices"
},
"@rootUrl": "https://adam-pi/webacs/api/v1/op",
"@requestUrl": "https://adam-pi/webacs/api/v1/op/jobService/runhistory?jobName=JobCliTemplateDeployIOSDevices08_40_09_490_PM_06_27_2016"
}
}
06-27-2016 07:29 AM
Hi Aradford,
As suggested, using JobID generated I am querying both Job Summary as well as full Run History that can give me full run history of the job deployed. I will check in switch console and keep you posted on this.
Thanks
Arun
06-27-2016 11:06 AM
can you share the Run History similar to mine above please?
That will tell you the commands that were run and if they were successful.
06-28-2016 03:38 AM
Hi Aradford,
This is the run history I am getting right now. It says error in running some XDE procedure, is this a problem with the switch I am using?. Till yesterday my run history was telling me that job completed successfully. But now I don't know what has happened. And Also I am not able to see the vlan in the console also.
<job>
<jobId>49695729</jobId>
JobCliTemplateDeployIOSDevices10_28_17_099_AM_06_28_2016
</jobName>
<jobStatus>COMPLETED</jobStatus>
<jobType>CliTemplateDeployIOSDevices</jobType>
<lastStartTime>2016-06-28T10:28:47.186Z</lastStartTime>
<resultStatus>FAILURE</resultStatus>
Error in running XDE Procedure, Error Message::Failed to establish ssh2 connection to device- Cause: Authentication failed on device. Update the Device credentials and retry the task.
</value>
</result>
</results>
<runId>60328470</runId>
<runStatus>COMPLETED</runStatus>
</runInstance>
</runInstances>
</job>
06-28-2016 05:14 AM
yes. that indicates that PI was not able to log in to the device via ssh.
Can you check the status of the device?
GET https://pi-server/webacs/api/v1/data/Devices?.full=true&ipAddress=10.10.8.100 Where pi-server is your Prime Infrastructure.
You should see something like this?
{
"queryResponse": {
"@last": "0",
"@first": "0",
"@count": "1",
"@type": "Devices",
"@responseType": "listEntityInstances",
"@requestUrl": "https://adam-pi/webacs/api/v1/data/Devices?.full=true&ipAddress=10.10.8.100",
"@rootUrl": "https://adam-pi/webacs/api/v1/data",
"entity": [
{
"@dtoType": "devicesDTO",
"@type": "Devices",
"@url": "https://adam-pi/webacs/api/v1/data/Devices/610622",
"devicesDTO": {
"@displayName": "610622",
"@id": "610622",
"clearedAlarms": 1,
"collectionDetail": "<status><general code=\"SUCCESS\"/></status>",
"collectionTime": "2016-06-28T22:00:35.708+10:00",
"creationTime": "2016-05-15T17:27:46.354+10:00",
"criticalAlarms": 0,
"deviceId": 614650,
"deviceName": "3650-dns",
"deviceType": "Cisco Catalyst 36xx stack-able ethernet switch",
"informationAlarms": 0,
"ipAddress": "10.10.8.100",
"majorAlarms": 0,
"managementStatus": "MANAGED_AND_SYNCHRONIZED",
"manufacturerPartNrs": {
"manufacturerPartNr": "WS-C3650-48PD-L"
},
"minorAlarms": 0,
"productFamily": "Switches and Hubs",
"reachability": "Reachable",
"softwareType": "IOS-XE",
"softwareVersion": "03.07.04E",
"warningAlarms": 0
}
}
]
}
}
06-28-2016 07:01 AM
Hi Aradford,
Yes, there was a login issue. I sincerely appreciate your dedication to help me. With able help, I am able to resolve the issue I had. Thanks a lot for your help and time. Your expertise helped me a lot in resolving this issue.
Thanks again for guiding me in each and every step.
Regards,
Arun
06-28-2016 07:09 AM
Absolute pleasure Arun.
I glad we got it resolved. Thanks for your patience and dedication.
Regards,
Adam
PS, Thanks for marking the question as resolved.
06-28-2016 07:19 AM
Sure Aradford!! . Thanks a lot to you too.
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