Skip to content

Issues when using the built-in Template System Variables #6

@swooton

Description

@swooton

Script seems to work great for most templates. But when using more advanced Velocity templates that utilize the built-in system variables (like __interface), I can't seem to get it to work.

I tried to dig a little deeper and created my own using the dnacentersdk but I seem to be having similar issues and am not sure if I am just running into limitations with the API or if it is just me. Seems like the more complicated the template the more likely it is to fail. I have been unable to do Composite templates as a whole but would really like to get that it's just I get Error 500 any time I try no matter the inputs (I must be missing something).

Even when doing the API calls directly for complicated templates I seem to get "None of the targets are applicable for the template. Hence not deploying" - I know that the target devices exist since I can run other templates on the same device no issue and the template options are identical with only the code being different. I also know the templates work since doing a standard provision via the GUI seems to work fine, its just hard to manage at scale for thousands of devices.

Specific example below using this template programmer:

C:\Users\xxxxx\Downloads\DNAC-TemplateProgrammer-master>python template.py --template "QoS WAN Routers/IOS-XE Pre-EEM Cleanup" --device 10.xxx.xxx.xxx --force
Looking for: QoS WAN Routers/IOS-XE Pre-EEM Cleanup
https://dnac.xxxxxxx.edu:443/dna/intent/api/v1/template-programmer/template
TemplateId: 7ce080d9-0f79-4e91-94c4-9478e50cda40 Version: 6

https://dnac.xxxxxxxx.edu:443/dna/intent/api/v1/template-programmer/template/7ce080d9-0f79-4e91-94c4-9478e50cda40
Showing Template Body:
{'name': 'IOS-XE Pre-EEM Cleanup', 'description': '', 'author': 'xxxxxxx', 'deviceTypes': [{'productFamily': 'Routers', 'productSeries': 'Cisco 4000 Series Integrated Services Routers'}], 'softwareType': 'IOS-XE', 'softwareVariant': 'XE', 'templateContent': '##VTY prep\n!\nline vty 0 97\n session-timeout 10\n length 0\n!\n##EEM Cleanup\n!\ndo event manager scheduler clear all\n!\nevent manager scheduler applet thread class default number 32\n!\nno event manager applet QOS_CLEANUP\n!\n#foreach( $interface in $_interface )\n !\n no event manager applet PORT_CLEANUP$interface.portName\n !\n#end\n!', 'rollbackTemplateContent': '', 'templateParams': [{'parameterName': '__interface', 'dataType': 'STRING', 'defaultValue': None, 'description': None, 'required': True, 'notParam': False, 'paramArray': True, 'instructionText': None, 'group': None, 'order': 1, 'customOrder': 0, 'selection': {'selectionType': 'MULTI_SELECT', 'selectionValues': {}, 'defaultSelectedValues': [], 'id': 'e8c4eed3-ff79-4488-835a-3cbefd4cae5d'}, 'range': [], 'key': None, 'provider': None, 'binding': '', 'id': 'cd0e8737-af86-4d93-99e7-e3fb66f69064', 'displayName': None}], 'rollbackTemplateParams': [], 'composite': False, 'containingTemplates': [], 'language': 'VELOCITY', 'id': '7ce080d9-0f79-4e91-94c4-9478e50cda40', 'version': '6', 'customParamsOrder': False, 'createTime': 1670607664313, 'lastUpdateTime': 1670614513050, 'latestVersionTime': 1670614515104, 'projectName': 'QoS WAN Routers', 'projectId': '2e036ed8-0389-438e-8139-676343e3a2de', 'parentTemplateId': 'fafd2484-3e96-461f-bea0-a46265572c08', 'validationErrors': {'templateErrors': [], 'rollbackTemplateErrors': [], 'templateId': '7ce080d9-0f79-4e91-94c4-9478e50cda40', 'templateVersion': None}, 'projectAssociated': True, 'documentDatabase': False}
##VTY prep
!
line vty 0 97
session-timeout 10
length 0
!
##EEM Cleanup
!
do event manager scheduler clear all
!
event manager scheduler applet thread class default number 32
!
no event manager applet QOS_CLEANUP
!
#foreach( $interface in $_interface )
!
no event manager applet PORT_CLEANUP
$interface.portName
!
#end
!

Required Parameters for template body: {"__interface":""}

Bindings []

Executing template on:10.xxx.xxx.xxx, with Params:None
Traceback (most recent call last):
File "C:\Users\xxxxxx\Downloads\DNAC-TemplateProgrammer-master\template.py", line 244, in
response = execute(id, params, bindings, args.device, inputParams, args.force)
File "C:\Users\xxxxxxx\Downloads\DNAC-TemplateProgrammer-master\template.py", line 62, in execute
"params": json.loads(params)
File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python310\lib\json_init_.py", line 339, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions