From d76e78b6e0d9a3503ed004cbae7208b3da96b403 Mon Sep 17 00:00:00 2001 From: zacho112 Date: Thu, 29 Jul 2021 09:55:37 +0200 Subject: [PATCH 1/5] Update ise.py Added update endpoint method - usefull for changing group membership --- ise.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/ise.py b/ise.py index 6c9877a..42ddbfb 100644 --- a/ise.py +++ b/ise.py @@ -1178,6 +1178,85 @@ def add_endpoint( return result else: return ERS._pass_ersresponse(result, resp) + + def update_endpoint( + self, + name, + mac, + group_id, + static_profile_assigment="false", + static_group_assignment="true", + profile_id="", + description="", + portalUser="", + customAttributes={}, + ): + """ + Update a user to the local user store. + + :param name: Name + :param mac: Macaddress + :param group_id: OID of group to add endpoint in + :param static_profile_assigment: Set static profile + :param static_group_assignment: Set static group + :param profile_id: OID of profile + :param description: User description + :param portaluser: Portal username + :param customAttributes: key value pairs of custom attributes + :return: result dictionary + """ + is_valid = ERS._mac_test(mac) + if not is_valid: + raise InvalidMacAddress( + "{0}. Must be in the form of AA:BB:CC:00:11:22".format(mac) + ) + else: + self.ise.headers.update( + {"ACCEPT": "application/json", "Content-Type": "application/json"} + ) + + result = { + "success": False, + "response": "", + "error": "", + } + + resp = self.ise.get( + "{0}/config/endpoint?filter=mac.EQ.{1}".format(self.url_base, mac) + ) + found_endpoint = resp.json() + + if found_endpoint["SearchResult"]["total"] == 1: + endpoint_oid = found_endpoint["SearchResult"]["resources"][0]["id"] + data = { + "ERSEndPoint": { + "name": name, + "description": description, + "mac": mac, + "profileId": profile_id, + "staticProfileAssignment": static_profile_assigment, + "groupId": group_id, + "staticGroupAssignment": static_group_assignment, + "portalUser": portalUser, + "customAttributes": {"customAttributes": customAttributes}, + } + } + + resp = self._request( + "{0}/config/endpoint/{1}".format(self.url_base, endpoint_oid), + method="put", + data=json.dumps(data), + ) + elif found_endpoint["SearchResult"]["total"] == 0: + result["response"] = "{0} not found".format(mac) + result["error"] = 404 + return result + + else: + result["response"] = "{0} not found".format(mac) + result["error"] = resp.status_code + return result + def delete_endpoint(self, mac): """ From 2c5b391fab241132154f2556906ac8b8d16ca0a8 Mon Sep 17 00:00:00 2001 From: zacho112 Date: Thu, 29 Jul 2021 09:57:39 +0200 Subject: [PATCH 2/5] Update test_ise_27.py --- test/test_ise_27.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_ise_27.py b/test/test_ise_27.py index c28245b..d3a8c02 100644 --- a/test/test_ise_27.py +++ b/test/test_ise_27.py @@ -70,6 +70,13 @@ def test_get_endpoint(): # noqa D103 assert "'name': 'AA:BB:CC:00:11:22'" in str(r1["response"]) +@pytest.mark.vcr +def test_update_endpoint(): # noqa D103 + r1 = ise.update_endpoint(endpoint["mac"]) + assert r1["success"] is True + assert r1["response"] == "AA:BB:CC:00:11:22 Updated Successfully" + + @pytest.mark.vcr def test_delete_endpoint(): # noqa D103 r1 = ise.delete_endpoint(endpoint["mac"]) From eb7caa595a7fbf0f1e05e42b72ad15e7565241ab Mon Sep 17 00:00:00 2001 From: zacho112 Date: Thu, 29 Jul 2021 09:58:05 +0200 Subject: [PATCH 3/5] Update test_ise_30.py --- test/test_ise_30.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_ise_30.py b/test/test_ise_30.py index 43025ae..4a0b20a 100644 --- a/test/test_ise_30.py +++ b/test/test_ise_30.py @@ -70,6 +70,14 @@ def test_get_endpoint(): # noqa D103 assert "'name': 'AA:BB:CC:00:11:22'" in str(r1["response"]) + +@pytest.mark.vcr +def test_update_endpoint(): # noqa D103 + r1 = ise.update_endpoint(endpoint["mac"]) + assert r1["success"] is True + assert r1["response"] == "AA:BB:CC:00:11:22 Updated Successfully" + + @pytest.mark.vcr def test_delete_endpoint(): # noqa D103 r1 = ise.delete_endpoint(endpoint["mac"]) From c52b7166c1ee42bf0ec83c08a98b4e594d96bc22 Mon Sep 17 00:00:00 2001 From: zacho112 Date: Thu, 29 Jul 2021 10:00:24 +0200 Subject: [PATCH 4/5] Update ise.py --- ise.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ise.py b/ise.py index 42ddbfb..7b9b146 100644 --- a/ise.py +++ b/ise.py @@ -1247,6 +1247,12 @@ def update_endpoint( method="put", data=json.dumps(data), ) + if resp.status_code == 201: + result["success"] = True + result["response"] = "{0} Updated Successfully".format(name) + return result + else: + return ERS._pass_ersresponse(result, resp) elif found_endpoint["SearchResult"]["total"] == 0: result["response"] = "{0} not found".format(mac) result["error"] = 404 From c1de69bd1b3d9e0903cfe486cb3c3cb7aa06deaf Mon Sep 17 00:00:00 2001 From: zacho112 Date: Thu, 29 Jul 2021 10:19:34 +0200 Subject: [PATCH 5/5] Update ise.py --- ise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ise.py b/ise.py index 7b9b146..483c873 100644 --- a/ise.py +++ b/ise.py @@ -1247,7 +1247,7 @@ def update_endpoint( method="put", data=json.dumps(data), ) - if resp.status_code == 201: + if resp.status_code == 200: result["success"] = True result["response"] = "{0} Updated Successfully".format(name) return result