cisco-en-programmability / dnacentersdk

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

Sda.adds_border_device virtualNetwork array not accepted as value #64

Closed nextnoob closed 2 years ago

nextnoob commented 2 years ago

Prerequisites

Yes →

Example Payload:

[
    {
        "deviceManagementIpAddress": "172.22.4.2",
        "siteNameHierarchy": "Global/SH-2",
        "deviceRole": [
            "Border_Node", 
            "Control_Plane_Node",
            "Edge_Node"
        ],
        "externalDomainRoutingProtocolName": "BGP",
        "externalConnectivityIpPoolName": "L3-Handoff",
        "internalAutonomouSystemNumber": "65101",
        "borderPriority": "10",
        "borderSessionType": "ANYWHERE",
        "connectedToInternet": "True",
        "borderWithExternalConnectivity": "True",
        "externalConnectivitySettings": [
            {
                "interfaceName": "GigabitEthernet1/0/24",
                "interfaceDescription": "Automated Value",
                "externalAutonomouSystemNumber": "65100",
                "l3Handoff": [
                    {
                        "virtualNetwork": 
                            {
                                "virtualNetworkName": "INFRA_VN",
                                "vlanId": "3200" 
                            }                       
                    },
                    {
                        "virtualNetwork": 
                            {
                                "virtualNetworkName": "BECHTLAB",
                                "vlanId": "3201" 
                            }                           
                    }                      
                ]
            }
        ]
    }
]
pip show dnacentersdk
Name: dnacentersdk
Version: 2.5.2
Summary: Cisco DNA Center Platform SDK
Home-page: https://dnacentersdk.readthedocs.io/en/latest/
Author: Jose Bogarin Solano
Author-email: jbogarin@altus.cr
License: MIT
Location: c:\users\username\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages
Requires: fastjsonschema, future, requests, requests-toolbelt
Required-by: 

Describe the bug

Class: classSda Function: adds_border_device(headers=None, payload=None, active_validation=True, **request_parameters)

The scheme under Developer DNAC Docs wants arrays for the key virtualNetworkand as values. Unfortunately, in reality arrays are not accepted by the DNA Center here.

Payload:

[
    {
        "deviceManagementIpAddress": "172.22.4.2",
        "siteNameHierarchy": "Global/SH-2",
        "deviceRole": [
            "Border_Node", 
            "Control_Plane_Node",
            "Edge_Node"
        ],
        "externalDomainRoutingProtocolName": "BGP",
        "externalConnectivityIpPoolName": "L3-Handoff",
        "internalAutonomouSystemNumber": "65101",
        "borderPriority": "10",
        "borderSessionType": "ANYWHERE",
        "connectedToInternet": "True",
        "borderWithExternalConnectivity": "True",
        "externalConnectivitySettings": [
            {
                "interfaceName": "GigabitEthernet1/0/24",
                "interfaceDescription": "Automated Value",
                "externalAutonomouSystemNumber": "65100",
                "l3Handoff": [
                    {
                        "virtualNetwork": [
                            {
                                "virtualNetworkName": "INFRA_VN",
                                "vlanId": "3200" 
                            } 
                        ]                          
                    },  
                    {
                        "virtualNetwork": [
                            {
                                "virtualNetworkName": "BECHTLAB",
                                "vlanId": "3201" 
                            } 
                        ]                          
                    }             
                ]
            }
        ]
    }
]

Error message:

PS E:\Users\username\ios-xe-nc-trial> python3 .\add_border_node.py
Traceback (most recent call last):
  File "E:\Users\username\ios-xe-nc-trial\add_border_node.py", line 78, in <module>
    dnac.sda.adds_border_device(payload = payload)
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\api\v2_3_3_0\sda.py", line 370, in adds_border_device
    json_data = self._session.post(endpoint_full_url, params=_params,
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\restsession.py", line 619, in post
    response = self.request('POST', url, erc, 0, params=params,
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\restsession.py", line 471, in request
    check_response_code(response, erc)
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\utils.py", line 209, in check_response_code
    raise ApiError(response)
dnacentersdk.exceptions.ApiError: [400] Bad Request - The request was invalid or cannot be otherwise served.

image

Expected behavior The API should accept arrays according to the schema, but it does not.

Screenshots image image

Environment (please complete the following information):

Additional context

Thanks for maintaining the very good SDK :blush:

fmunozmiranda commented 2 years ago

Hey @nextnoob , there´s a new version of dnacentersdk (2.5.3) with solved problem, try it and let us know if it works for you.

nextnoob commented 2 years ago

Hey @fmunozmiranda ,

unfortunately the validation does not work yet.

Error Message:

Reason: data[0].externalConnectivitySettings[0].l3Handoff[0].virtualNetwork must be object

Detail:

PS E:\Users\username\ios-xe-nc-trial> python3 .\add_border_node.py      
Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\models\validators\v2_3_3_0\jsd_b6f2d8e46cdd5f05bb06f52cd1b26fb2.py", line 142, in validate
    self._validator(request)
  File "<string>", line 124, in validate
fastjsonschema.exceptions.JsonSchemaValueException: data[0].externalConnectivitySettings[0].l3Handoff[0].virtualNetwork must be object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Users\username\ios-xe-nc-trial\add_border_node.py", line 78, in <module>
    dnac.sda.adds_border_device(payload = payload)
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\api\v2_3_3_0\sda.py", line 355, in adds_border_device
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\models\validators\v2_3_3_0\jsd_b6f2d8e46cdd5f05bb06f52cd1b26fb2.py", line 144, in validate
    raise MalformedRequest(
dnacentersdk.exceptions.MalformedRequest: [{'deviceManagementIpAddress': '172.22.4.2', 'siteNameHierarchy': 'Global/SH-2', 'deviceRole': ['Border_Node', 'Control_Plane_Node', 'Edge_Node'], 'externalDomainRoutingProtocolName': 'BGP', 'externalConnectivityIpPoolName': 'L3-Handoff', 'internalAutonomouSystemNumber': '65101', 'borderPriority': '10', 'borderSessionType': 'ANYWHERE', 'connectedToInternet': 'True', 'borderWithExternalConnectivity': 'True', 'externalConnectivitySettings': [{'interfaceName': 'GigabitEthernet1/0/24', 'interfaceDescription': 'Automated Value', 'externalAutonomouSystemNumber': '65100', 'l3Handoff': [{'virtualNetwork': [{'virtualNetworkName': 'INFRA_VN', 'vlanId': '3200'}]}, {'virtualNetwork': [{'virtualNetworkName': 'BECHTLAB', 'vlanId': '3201'}]}]}]}] is invalid. Reason: data[0].externalConnectivitySettings[0].l3Handoff[0].virtualNetwork must be object
fmunozmiranda commented 2 years ago

@nextnoob, I see may be something wrong with the object creation. Malformed request details this structure:

"l3Handoff": [
                    {
                        "virtualNetwork": [
                            {
                                "virtualNetworkName": "INFRA_VN",
                                "vlanId": "3200"
                            }
                        ]
                    },
                    {
                        "virtualNetwork": [
                            {
                                "virtualNetworkName": "BECHTLAB",
                                "vlanId": "3201"
                            }
                        ]
                    }
                ]

A valid request, should be like this:


 "l3Handoff": [
                    {
                        "virtualNetwork": 
                            {
                                "virtualNetworkName": "INFRA_VN",
                                "vlanId": "3200"
                            }

                    },
                    {
                        "virtualNetwork": 
                            {
                                "virtualNetworkName": "BECHTLAB",
                                "vlanId": "3201"
                            }

                    }
                ]
nextnoob commented 2 years ago

Oh, my mistake. I still had the "old" syntax from the DNAC API documentation.

Thank you for the fix.