cisco-en-programmability / dnacentersdk

Cisco DNA Center Python SDK
https://dnacentersdk.readthedocs.io/en/latest/
MIT License
70 stars 33 forks source link

dnacentersdk/api/v2_3_3_0/configuration_templates.py - Cannot resolve property #109

Closed usafdixon closed 11 months ago

usafdixon commented 1 year ago

Prerequisites

Describe the bug Error while evaluating template Cannot resolve property

Traceback Details Checking DNAC Inventory. Traceback (most recent call last): File "dnacentersdk\api\v2_3_3_0\configuration_templates.py", line 1283, in deploy_template File "dnacentersdk\restsession.py", line 619, in post File "dnacentersdk\restsession.py", line 471, in request File "dnacentersdk\utils.py", line 209, in check_response_code dnacentersdk.exceptions.ApiError: [400] - NCTP10032: Error while evaluating template Cannot resolve property 'portType' in '' [19728] Failed to execute script 'main' due to unhandled exception!

Expected behavior dnacentersdk should resolve the properties for Implicit Variables in a DNAC Jinja Template.

Screenshots See Attached screenshot of postman showing resolved property.

DNAC Template Example: {% for interfaces in __interface %} {% if interfaces.portType == 'Ethernet SVI' && interfaces.adminStatus == 'UP' && interfaces.portMode == 'routed' %} interface {{ interfaces.portName }} no ip helper-address 1.1.1.1 no ip helper-address 1.1.1.2 no ip helper-address 1.1.1.3 no ip helper-address 1.1.1.4 ip helper-address 2.2.2.1 ip helper-address 2.2.2.2 {% endif %} {% endfor %}

Environment (please complete the following information): Cisco DNA Center Version and patch: 2.3.3.7 Python version: v3.9.6 SDK version: 2.5.6 OS Version: IOS-XE 17.3.5

Additional context Add any other context about the problem here. Interface API portType Property

fmunozmiranda commented 1 year ago

Hi @usafdixon , could you please show me how are you calling SDK function?

usafdixon commented 1 year ago

Hi @usafdixon , could you please show me how are you calling SDK function?

Please see below:

from dnacentersdk import api  def get_api_client(self):  if self.strategy != 'singleton' or not self._dnac:  self._dnac = api.DNACenterAPI(  username=creds.get_username(),  password=creds.get_password(),  base_url=set_base_url(),  version='2.1.2',  verify=False  )  return self._dnac

dnac = dnac_factory.get_api_client() all_templates = dnac.configuration_templates.gets_the_templates_available()

fmunozmiranda commented 1 year ago

@usafdixon could you please show me when you call deploy_template function, cause is seems that SDK is failing there.

It also seems that api is failing with v2.3.3.0 and in code you provide I see that your using there v2.1.2.

usafdixon commented 1 year ago

We got it resolved. We need to add the resource parameters to the payload.

example: targetInfo = [ { 'id': 'POD3-EDGE2.POD3.CSS.COM', 'params': { 'description': '1234567'}, 'type': 'MANAGED_DEVICE_HOSTNAME', "resourceParams": [ { "type": "MANAGED_DEVICE_HOSTNAME", "scope": "RUNTIME", "value": "POD3-EDGE2.POD3.CSS.COM" }] } ]

fmunozmiranda commented 11 months ago

Thanks for update.