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-19-2016 02:42 AM
I have changed the script to just include "" for the vars that are not required.
It displays "required" as the value for the variables that are mandatory.
I am also posting a fully worked example.
06-13-2016 11:31 AM
Hi Arun,
let me post an example. will do this later this morning
06-14-2016 11:53 PM
Hi Arun,
here are some examples for you.
There is also a little utility to create (JSON) schema for the template you want to use
06-16-2016 02:24 AM
Thanks aradford. Appreciate your help. But following is the error I am getting when I try to execute "get_template.py" script you had shared in GitHub.
$ python get_template.py -t 445464 -s
Traceback (most recent call last):
File "get_template.py", line 69, in <module>
show_template(args.t, args.s)
File "get_template.py", line 59, in show_template
show_a_template(template, schema)
File "get_template.py", line 47, in show_a_template
result = requests.get(BASE + "data/CliTemplate/%s.json?.full=true" % template, verify=False)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 421, in request
prep = self.prepare_request(req)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 359, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 287, in prepare
self.prepare_url(url, params)
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 334, in prepare_url
scheme, auth, host, port, path, query, fragment = parse_url(url)
File "/usr/lib/python2.7/dist-packages/urllib3/util.py", line 390, in parse_url
raise LocationParseError("Failed to parse: %s" % url)
urllib3.exceptions.LocationParseError: Failed to parse: Failed to parse: root:win
Thanks in advance.
06-14-2016 12:15 AM
Hi Arun,
I have found that you need to post all variables in a template (even if they're not used) when you submit the job.
Also if you look in the "pnp_tempate.log" file you'll see which variable is causing the error.
Andy
06-14-2016 04:44 AM
Thanks a lot for your reply. I thought, only those fields/variables which are marked "Required" were supposed to be given in the request body while submitting the job. Anyways, I will try this workaround and definitely get back to you on this.
And as suggested, I downloaded log files from Administration -> Logging, but it doesn't contain any file name "pnp_template.log".
06-14-2016 05:05 AM
The log can be accessed from the console shell (/opt/CSCOlumos/logs/ifm_template.log)
06-14-2016 08:24 AM
This is the error line I am able to see in the log file ifm_template.log .
[2016-06-07 10:30:55,008] [seqtaskexecutor-1] [service] [ERROR] - Thread Id : [213,330] : IFM_TEMPLATE_ERROR_DETAILS: [Unable to find value for variable: option] : IFM_TEMPLATE_ERROR: [Method getVarValue: Variable name- option does not exist!]
Run history of job returns the following response
<job>
<description>Cli Template Deploy for IOS devices</description>
<jobId>49695693</jobId>
<jobName>JobCliTemplateDeployIOSDevices01_07_39_575_PM_06_14_2016</jobName>
<jobStatus>COMPLETED</jobStatus>
<jobType>CliTemplateDeployIOSDevices</jobType>
<runInstances>
<runInstance>
<completionTime>2016-06-14T13:08:10.741Z</completionTime>
<lastStartTime>2016-06-14T13:08:09.710Z</lastStartTime>
<resultStatus>FAILURE</resultStatus>
<results>
<result>
<property>1074074</property>
<value>Invalid var Values for given template's variables</value>
</result>
</results>
<runId>55253918</runId>
<runStatus>COMPLETED</runStatus>
</runInstance>
</runInstances>
</job>
Request body for configure vlan Cli template is as given in the following snippet
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliTemplateCommand>
<targetDevices>
<targetDevice>
<targetDeviceID>1074074</targetDeviceID>
<variableValues>
<variableValues>
<variableValue>
<name>vlanid</name>
<value>200</value>
</variableValue>
<variableValue>
<name>vlanName</name>
<value>vlan2</value>
</variableValue>
</variableValues>
</targetDevice>
</targetDevices>
<templateName>Configure VLAN</templateName>
</cliTemplateCommand>
06-16-2016 02:28 AM
Hi Andy, as suggested I have included all variables available in the body even if it is not mandatory. But still I am facing the same issue. It says invalid variable values.
Thanks in advance for your help.
06-16-2016 02:33 AM
Hi Arun,
are you using JSON or XML?
If you are using JSON, if you goto the REPO I mentioned earlier I wrote a little utility to generate a JSON schema from the CLI_template. You just need to fill in the blanks. Make sure you add a valid DEVICEID
python get_template.py -n "Configure Interface" -s
{
"cliTemplateCommand" : {
"targetDevices" : {
"targetDevice" : {
"targetDeviceID" : "<DEVICEID>",
"variableValues" : {
"variableValue": [
{ "name": "Description", "value" : NONE }
#required
{ "name": "InterfaceName", "value" : NONE }
{ "name": "NativeVLan", "value" : NONE }
{ "name": "StaticAccessVLan", "value" : NONE }
{ "name": "TrunkAllowedVLan", "value" : NONE }
{ "name": "VoiceVlan", "value" : NONE }
{ "name": "spd", "value" : NONE }
{ "name": "A1", "value" : NONE }
{ "name": "duplexField", "value" : NONE }
{ "name": "PortFast", "value" : NONE }
]
}
}
},
"templateName" : "Configure Interface"
}
}
06-17-2016 07:08 AM
Hi Aradford,
I have tried both JSON and XML formats. For XML format I have used, you can refer to my previous replies to this question. Here I am posting you the JSON format that I have used.
Firstly, I downloaded the CLI template for Configure vlan from the Prime using the python script shared by you.
$python get_template.py -t 445464 -s
{
"cliTemplateCommand" : {
"targetDevices" : {
"targetDevice" : {
"targetDeviceID" : "<DEVICEID>",
"variableValues" : {
"variableValue": [
{ "name": "encapsulation", "value" : NONE }
{ "name": "interfaceName", "value" : NONE }
{ "name": "mtu", "value" : NONE }
#required
{ "name": "vlanid", "value" : NONE }
{ "name": "vlanName", "value" : NONE }
{ "name": "mode", "value" : NONE }
{ "name": "option", "value" : NONE }
]
}
}
},
"templateName" : "Configure VLAN"
}
}
Then I modified this JSON format according to my requirement, i.e I just supplied values for vlanid as follows
{
"cliTemplateCommand" : {
"targetDevices" : {
"targetDevice" : {
"targetDeviceID" : "1074084",
"variableValues" : {
"variableValue": [
{ "name": "encapsulation", "value" : NONE }
{ "name": "interfaceName", "value" : NONE }
{ "name": "mtu", "value" : NONE }
{ "name": "vlanid", "value" : 200 }
{ "name": "vlanName", "value" : NONE }
{ "name": "mode", "value" : NONE }
{ "name": "option", "value" : NONE }
]
}
}
},
"templateName" : "Configure VLAN"
}
}
But when I deploy this data to prime, and check the run history, it gives me the following response
<job>
<description>Cli Template Deploy for IOS devices</description>
<jobId>49695709</jobId>
<jobName>
JobCliTemplateDeployIOSDevices12_04_13_021_PM_06_17_2016
</jobName>
<jobStatus>COMPLETED</jobStatus>
<jobType>CliTemplateDeployIOSDevices</jobType>
<runInstances>
<runInstance>
<completionTime>2016-06-17T12:04:44.132Z</completionTime>
<lastStartTime>2016-06-17T12:04:43.107Z</lastStartTime>
<resultStatus>FAILURE</resultStatus>
<results>
<result>
<property>1074084</property>
<value>Invalid var Values for given template's variables</value>
</result>
</results>
<runId>56445468</runId>
<runStatus>COMPLETED</runStatus>
</runInstance>
</runInstances>
</job>undefined</mgmtResponse>
Any workaround suggested here? Thanks in advance
06-17-2016 12:06 PM
oh sorry... my mistake...
NONE should be None
I will fix this
06-19-2016 02:42 AM
I have changed the script to just include "" for the vars that are not required.
It displays "required" as the value for the variables that are mandatory.
I am also posting a fully worked example.
06-21-2016 04:05 AM
Any update on this? I have updated my scripts on github.
Adam
06-21-2016 05:13 AM
Hi Aradford,
Thanks for the update. I have issues with accessing Cisco Prime Server. I will definitely keep you posted. I really appreciate your help. Thanks a lot.
Regards,
Arun
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