본문 바로가기
<개인공부> - IT/[Python]

Cisco ISE ERS API (Device Update)

by Aggies '19 2020. 8. 26.
반응형

오늘 날짜를 기준으로 (2020/8/25) PyPi에서 검색해서 사용할 수 있는 ISE ERS 라이브러리에는 Network Device의 정보를 업데이트 할 수 있는 함수가 구현되어있지 않다.

As of today's date (08/25/2020), the Cisco ISE ERS library, which can be gotten from PyPi, does not have a update function to update the network device information.

 

>>> https://pypi.org/project/ISE/

 

ISE

Python wrapper for Cisco ISE ERS API

pypi.org

회사 업무를 하던 중, ISE의 Network Device 정보를 업데이트 할 일이 생겼다. ISE에서는 아래 그림과 같이 Import와 Export 기능을 제공한다.

I came up with a task to update the network device information of ISE. Basically, ISE provides import and export functions as shown in the figure below.

 

가장 간단한 방법으로는 해당 장비의 리스트를 Export 후 원하는 정보만 수정해서 다시 Import 하면 된다. 하이라이팅한 옵션을 체크해주어야 수정된 정보를 Import 할 수 있다. 해당 옵션을 클릭하지 않으면 동일한 IP에 대한 정보가 이미 있다는 에러메시지와 함께 정보가 업데이트 되지 않는다.

A simple way is to export the list of devices, modify only the certain information that I want to update in my case device name and description, and then import it again. Don't forget to check "Overwirte existing data with new data". If this option is not checked, the information will not be updated since ISE recognizes that data is duplicate.

기존에 잘 구현된 library 안에 내가 필요한 기능인 device 정보를 update 하는 함수를 구현해보았다.

I implemented a function that updates device information.

 

[Update 함수 구현부분 / Implementation of update function]

# This function should be copied & pasted to ise.py

def update_device(self,
                  deviceData,
                  idx,
                  name,
                  description):

        """
        Update a device.

        :param deviceData: device data received by calling get_device
        :param idx: device unique ID
        :param name: A new device
        :param description: A new description
        :return: Result dictionary
        """
        
        result = {
            'success': False,
            'response': '',
            'error': '',
        }

        self.ise.headers.update(
            {'ACCEPT': 'application/json', 'Content-Type': 'application/json'})

        data = dict()
        data['NetworkDevice'] = deviceData['response']
        data['NetworkDevice']['name'] = name
        data['NetworkDevice']['description'] = description
        del data['NetworkDevice']['authenticationSettings']['radiusSharedSecret']

        url = f'{self.url_base}/config/networkdevice/' + idx
        resp = self._request(url, method='put', data=json.dumps(data))

        if resp.status_code == 200:
            result['success'] = True
            result['response'] = resp.json()
            return result
        else:
            return ERS._pass_ersresponse(result, resp)

구현하는데 있어서 특이점이 몇 가지 있었다. 그 부분에 대해서 공유해보고자 한다. 우선, Cisco ISE API documentation을 보면 Get-By-Id 함수가 있다. id를 filter값으로 이용하여 device에 대한 정보를 얻는 것일텐데 id로 filter는 적용되지 않는다. 실제로 구현해놓은 코드를 보면 name를 통해서 filter하여 장비의 정보를 얻는 것을 볼 수 있다.

There are several peculiarities during my implementation. I would like to introduce it. Based on Cisco ISE API documentation I can retrieve device intormation by id. However, I am not able to use id value as a filter parameter. 

The get_device function has been implemeted like below using name as a filter.

resp = self.ise.get(
            '{0}/config/networkdevice?filter=name.EQ.{1}'.format(self.url_base, device))

[deviceData 변수의 목적 / Purpose of the deviceData variable]

 

1. id로 장비 검색이 안됨 / Not able to search by device's id

2. 많은 환경설정 정보 / Lots of configuration information

 

즉, 쉽게 말해서 device의 name과 description만 변경할 것이었기 때문에 기존 정보는 그대고 갖고 가되 name과 description만 별도로 업데이트 하는 것으로 구현했다. 

In other words, only the name and description of the device are to be changed, so I save the current device details and only update the name and the description.

 

[특정 정보의 삭제의 이유 / Reasons for deletion of specific information]

del data['NetworkDevice']['authenticationSettings']['radiusSharedSecret']

우리가 운영하는 ISE 환경에서만 발생하는 오류일 수도 있거나 Cisco ISE API documentation의 오류라고 생각하는 부분이다. 아래 그림과 같이 networkProtocol이 정의없이 radiusSharedSecret key에 대한 정보만 있을 경우 오류가 발생된다. 한 가지 의문점은 API documentation을 기준으로 networkProtocol은 required한 정보가 아니라는 점이다. 요약하면 내가 장비를 조회하고 되면 networkProtocol은 없이 radiusSharedSecret만 조회되었고 그 정보를 그대로 json dump화 해서 update 함수를 호출하면 에러가 발생하였기에 radiusSharedSecret 부분을 강제로 지웠다.

It may be an error that occurs only in the ISE environment we operate, or it is an error in the Cisco ISE API documentation. As shown in the figure below, if there is only information about the radiusSharedSecret key without networkProtocol definition, an error occurs. My question is that networkProtocol is not required data based on API documentation. Anyway, when I searched the device, only radiusSharedSecret got retrieved without networkProtocol. It occurs the error when calling the update function so I forcibly delete the radiusSharedSecret part before constructing json data.

 

반응형