From 6938928db766d7d3e4f1d1d2b21c2885eac2b081 Mon Sep 17 00:00:00 2001 From: ethangrinnell78 Date: Wed, 26 May 2021 18:32:36 -0700 Subject: [PATCH 1/3] Added timeout to all self.ise.get requests --- ise.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/ise.py b/ise.py index 6c9877a..4775bf2 100644 --- a/ise.py +++ b/ise.py @@ -150,7 +150,9 @@ def _request(self, url, method="get", data=None): ) resp = self.ise.get( - "{0}/config/deploymentinfo/versioninfo".format(self.url_base) + "{0}/config/deploymentinfo/versioninfo".format( + self.url_base), + timeout=self.timeout ) self.csrf = resp.headers["X-CSRF-Token"] self.csrf_expires = datetime.utcfromtimestamp(0) + timedelta(seconds=60) @@ -197,7 +199,7 @@ def _get_groups(self, url, filter: str = None, size: int = 20, page: int = 1): self.ise.headers.update( {"ACCEPT": "application/json", "Content-Type": "application/json"} ) - resp = self.ise.get(f.url) + resp = self.ise.get(f.url, timeout=self.timeout) if resp.status_code == 200: result["success"] = True @@ -239,7 +241,7 @@ def _get_objects(self, url, filter: str = None, size: int = 20, page: int = 1): if filter: f.args["filter"] = filter - resp = self.ise.get(f.url) + resp = self.ise.get(f.url, timeout=self.timeout) # TODO add dynamic paging? if resp.status_code == 200: @@ -303,7 +305,7 @@ def get_endpoint_group(self, group): resp = self.ise.get( "{0}/config/endpointgroup?filter=name.EQ.{1}".format( self.url_base, group - ) + ), timeout=self.timeout ) found_group = resp.json() @@ -378,11 +380,11 @@ def get_sgt(self, sgt): else: if isinstance(sgt, int): resp = self.ise.get( - "{0}/config/sgt?filter=value.EQ.{1}".format(self.url_base, sgt) + "{0}/config/sgt?filter=value.EQ.{1}".format(self.url_base, sgt), timeout=self.timeout ) else: resp = self.ise.get( - "{0}/config/sgt?filter=name.EQ.{1}".format(self.url_base, sgt) + "{0}/config/sgt?filter=name.EQ.{1}".format(self.url_base, sgt), timeout=self.timeout ) found_group = resp.json() @@ -591,7 +593,7 @@ def get_sgacl(self, sgacl): # If not valid OID, perform regular search else: resp = self.ise.get( - "{0}/config/sgacl?filter=name.EQ.{1}".format(self.url_base, sgacl) + "{0}/config/sgacl?filter=name.EQ.{1}".format(self.url_base, sgacl), timeout=self.timeout ) found_group = resp.json() @@ -801,7 +803,7 @@ def get_egressmatrixcell(self, emc, src_sgt=None, dst_sgt=None): resp = self.ise.get( "{0}/config/egressmatrixcell?filter=description.EQ.{1}".format( self.url_base, emc - ) + ), timeout=self.timeout ) found_group = resp.json() elif src_sgt and dst_sgt: @@ -810,7 +812,7 @@ def get_egressmatrixcell(self, emc, src_sgt=None, dst_sgt=None): resp = self.ise.get( "{0}/config/egressmatrixcell?filter=sgtSrcValue.EQ.{1}&filter=sgtDstValue.EQ.{2}".format( self.url_base, srcsgtval, dstsgtval - ) + ), timeout=self.timeout ) found_group = resp.json() else: @@ -1054,7 +1056,7 @@ def get_object(self, url: str, objectid: str, objecttype: str): f = furl(url) f.path /= objectid - resp = self.ise.get(f.url) + resp = self.ise.get(f.url, timeout=self.timeout) if resp.status_code == 200: result["success"] = True @@ -1090,7 +1092,7 @@ def get_endpoint(self, mac_address): resp = self.ise.get( "{0}/config/endpoint?filter=mac.EQ.{1}".format( self.url_base, mac_address - ) + ), timeout=self.timeout ) found_endpoint = resp.json() @@ -1197,7 +1199,7 @@ def delete_endpoint(self, mac): } resp = self.ise.get( - "{0}/config/endpoint?filter=mac.EQ.{1}".format(self.url_base, mac) + "{0}/config/endpoint?filter=mac.EQ.{1}".format(self.url_base, mac), timeout=self.timeout ) found_endpoint = resp.json() if found_endpoint["SearchResult"]["total"] == 1: @@ -1256,7 +1258,7 @@ def get_identity_group(self, group): } resp = self.ise.get( - "{0}/config/identitygroup?filter=name.EQ.{1}".format(self.url_base, group) + "{0}/config/identitygroup?filter=name.EQ.{1}".format(self.url_base, group), timeout=self.timeout ) found_group = resp.json() @@ -1305,7 +1307,7 @@ def get_user(self, user_id): } resp = self.ise.get( - "{0}/config/internaluser?filter=name.EQ.{1}".format(self.url_base, user_id) + "{0}/config/internaluser?filter=name.EQ.{1}".format(self.url_base, user_id), timeout=self.timeout ) found_user = resp.json() @@ -1402,7 +1404,7 @@ def delete_user(self, user_id): } resp = self.ise.get( - "{0}/config/internaluser?filter=name.EQ.{1}".format(self.url_base, user_id) + "{0}/config/internaluser?filter=name.EQ.{1}".format(self.url_base, user_id), timeout=self.timeout ) found_user = resp.json() @@ -1465,7 +1467,7 @@ def get_device_group(self, device_group_oid=None, name=None): resp = self.ise.get( "{0}/config/networkdevicegroup?filter=name.contains.{1}".format( self.url_base, quote(name) - ) + ), timeout=self.timeout ) found_group = resp.json() @@ -1599,7 +1601,7 @@ def delete_device_group(self, name): resp = self.ise.get( "{0}/config/networkdevicegroup?filter=name.contains.{1}".format( self.url_base, quote(name) - ) + ), timeout=self.timeout ) found_group = resp.json() if found_group["SearchResult"]["total"] == 1: @@ -1657,7 +1659,7 @@ def get_device(self, device): } resp = self.ise.get( - "{0}/config/networkdevice?filter=name.EQ.{1}".format(self.url_base, device) + "{0}/config/networkdevice?filter=name.EQ.{1}".format(self.url_base, device), timeout=self.timeout ) found_device = resp.json() @@ -1826,7 +1828,7 @@ def delete_device(self, device): } resp = self.ise.get( - "{0}/config/networkdevice?filter=name.EQ.{1}".format(self.url_base, device) + "{0}/config/networkdevice?filter=name.EQ.{1}".format(self.url_base, device), timeout=self.timeout ) found_device = resp.json() if found_device["SearchResult"]["total"] == 1: From 43bf07b6109ddcf925f5bc71910f702354e2b347 Mon Sep 17 00:00:00 2001 From: ethangrinnell78 Date: Wed, 26 May 2021 18:33:56 -0700 Subject: [PATCH 2/3] Formatted all requests --- ise.py | 302 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 236 insertions(+), 66 deletions(-) diff --git a/ise.py b/ise.py index 4775bf2..0e6cf4a 100644 --- a/ise.py +++ b/ise.py @@ -1,3 +1,5 @@ +# Final edit + """Class to configure Cisco ISE via the ERS API.""" import json import os @@ -151,7 +153,8 @@ def _request(self, url, method="get", data=None): resp = self.ise.get( "{0}/config/deploymentinfo/versioninfo".format( - self.url_base), + self.url_base + ), timeout=self.timeout ) self.csrf = resp.headers["X-CSRF-Token"] @@ -199,7 +202,10 @@ def _get_groups(self, url, filter: str = None, size: int = 20, page: int = 1): self.ise.headers.update( {"ACCEPT": "application/json", "Content-Type": "application/json"} ) - resp = self.ise.get(f.url, timeout=self.timeout) + resp = self.ise.get( + f.url, + timeout=self.timeout + ) if resp.status_code == 200: result["success"] = True @@ -241,7 +247,10 @@ def _get_objects(self, url, filter: str = None, size: int = 20, page: int = 1): if filter: f.args["filter"] = filter - resp = self.ise.get(f.url, timeout=self.timeout) + resp = self.ise.get( + f.url, + timeout=self.timeout + ) # TODO add dynamic paging? if resp.status_code == 200: @@ -274,7 +283,11 @@ def get_endpoint_groups(self, size=20, page=1): :return: result dictionary """ return self._get_groups( - "{0}/config/endpointgroup".format(self.url_base), size=size, page=page + "{0}/config/endpointgroup".format( + self.url_base + ), + size=size, + page=page ) def get_endpoint_group(self, group): @@ -297,21 +310,29 @@ def get_endpoint_group(self, group): # If it's a valid OID, perform a more direct GET-call if self._oid_test(group): result = self.get_object( - "{0}/config/endpointgroup".format(self.url_base), group, "EndPointGroup" + "{0}/config/endpointgroup".format( + self.url_base + ), + group, + "EndPointGroup" ) return result # If not valid OID, perform regular search else: resp = self.ise.get( "{0}/config/endpointgroup?filter=name.EQ.{1}".format( - self.url_base, group - ), timeout=self.timeout + self.url_base, + group + ), + timeout=self.timeout ) found_group = resp.json() if found_group["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/endpointgroup".format(self.url_base), + "{0}/config/endpointgroup".format( + self.url_base + ), found_group["SearchResult"]["resources"][0]["id"], "EndPointGroup", ) # noqa E501 @@ -333,7 +354,9 @@ def get_endpoints(self, groupID=None, size=20, page=1): filter = None return self._get_objects( - "{0}/config/endpoint".format(self.url_base), + "{0}/config/endpoint".format( + self.url_base + ), filter=filter, size=size, page=page, @@ -352,7 +375,12 @@ def get_sgts(self, sgtNum=None, size=20, page=1): filter = None return self._get_objects( - "{0}/config/sgt".format(self.url_base), filter=filter, size=size, page=page + "{0}/config/sgt".format( + self.url_base + ), + filter=filter, + size=size, + page=page ) def get_sgt(self, sgt): @@ -374,23 +402,38 @@ def get_sgt(self, sgt): # If it's a valid OID, perform a more direct GET-call if self._oid_test(sgt): - result = self.get_object("{0}/config/sgt".format(self.url_base), sgt, "Sgt") + result = self.get_object( + "{0}/config/sgt".format( + self.url_base + ), + sgt, + "Sgt") return result # If not valid OID, perform regular search else: if isinstance(sgt, int): resp = self.ise.get( - "{0}/config/sgt?filter=value.EQ.{1}".format(self.url_base, sgt), timeout=self.timeout + "{0}/config/sgt?filter=value.EQ.{1}".format( + self.url_base, + sgt + ), + timeout=self.timeout ) else: resp = self.ise.get( - "{0}/config/sgt?filter=name.EQ.{1}".format(self.url_base, sgt), timeout=self.timeout + "{0}/config/sgt?filter=name.EQ.{1}".format( + self.url_base, + sgt + ), + timeout=self.timeout ) found_group = resp.json() if found_group["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/sgt".format(self.url_base), + "{0}/config/sgt".format( + self.url_base + ), found_group["SearchResult"]["resources"][0]["id"], "Sgt", ) @@ -441,7 +484,9 @@ def add_sgt( } resp = self._request( - "{0}/config/sgt".format(self.url_base), + "{0}/config/sgt".format( + self.url_base + ), method="post", data=json.dumps(data), ) @@ -504,7 +549,9 @@ def update_sgt( } resp = self._request( - ("{0}/config/sgt/" + sgt).format(self.url_base), + ("{0}/config/sgt/" + sgt).format( + self.url_base + ), method="put", data=json.dumps(data), ) @@ -536,7 +583,11 @@ def delete_sgt(self, sgt): } resp = self._request( - "{0}/config/sgt/{1}".format(self.url_base, sgt), method="delete" + "{0}/config/sgt/{1}".format( + self.url_base, + sgt + ), + method="delete" ) if resp.status_code == 204: @@ -561,7 +612,9 @@ def get_sgacls(self, size=20, page=1): filter = None return self._get_objects( - "{0}/config/sgacl".format(self.url_base), + "{0}/config/sgacl".format( + self.url_base + ), filter=filter, size=size, page=page, @@ -587,19 +640,29 @@ def get_sgacl(self, sgacl): # If it's a valid OID, perform a more direct GET-call if self._oid_test(sgacl): result = self.get_object( - "{0}/config/sgacl".format(self.url_base), sgacl, "Sgacl" + "{0}/config/sgacl".format( + self.url_base + ), + sgacl, + "Sgacl" ) return result # If not valid OID, perform regular search else: resp = self.ise.get( - "{0}/config/sgacl?filter=name.EQ.{1}".format(self.url_base, sgacl), timeout=self.timeout + "{0}/config/sgacl?filter=name.EQ.{1}".format( + self.url_base, + sgacl + ), + timeout=self.timeout ) found_group = resp.json() if found_group["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/sgacl".format(self.url_base), + "{0}/config/sgacl".format( + self.url_base + ), found_group["SearchResult"]["resources"][0]["id"], "Sgacl", ) @@ -650,7 +713,9 @@ def add_sgacl( } resp = self._request( - "{0}/config/sgacl".format(self.url_base), + "{0}/config/sgacl".format( + self.url_base + ), method="post", data=json.dumps(data), ) @@ -707,7 +772,9 @@ def update_sgacl( } resp = self._request( - ("{0}/config/sgacl/" + sgacl).format(self.url_base), + ("{0}/config/sgacl/" + sgacl).format( + self.url_base + ), method="put", data=json.dumps(data), ) @@ -739,7 +806,11 @@ def delete_sgacl(self, sgacl): } resp = self._request( - "{0}/config/sgacl/{1}".format(self.url_base, sgacl), method="delete" + "{0}/config/sgacl/{1}".format( + self.url_base, + sgacl + ), + method="delete" ) if resp.status_code == 204: @@ -764,7 +835,9 @@ def get_egressmatrixcells(self, size=20, page=1): filter = None return self._get_objects( - "{0}/config/egressmatrixcell".format(self.url_base), + "{0}/config/egressmatrixcell".format( + self.url_base + ), filter=filter, size=size, page=page, @@ -792,7 +865,9 @@ def get_egressmatrixcell(self, emc, src_sgt=None, dst_sgt=None): # If it's a valid OID, perform a more direct GET-call if self._oid_test(emc): result = self.get_object( - "{0}/config/egressmatrixcell".format(self.url_base), + "{0}/config/egressmatrixcell".format( + self.url_base + ), emc, "EgressMatrixCell", ) @@ -802,8 +877,10 @@ def get_egressmatrixcell(self, emc, src_sgt=None, dst_sgt=None): if emc: resp = self.ise.get( "{0}/config/egressmatrixcell?filter=description.EQ.{1}".format( - self.url_base, emc - ), timeout=self.timeout + self.url_base, + emc + ), + timeout=self.timeout ) found_group = resp.json() elif src_sgt and dst_sgt: @@ -811,8 +888,11 @@ def get_egressmatrixcell(self, emc, src_sgt=None, dst_sgt=None): dstsgtval = self.get_sgt(dst_sgt)["response"]["value"] resp = self.ise.get( "{0}/config/egressmatrixcell?filter=sgtSrcValue.EQ.{1}&filter=sgtDstValue.EQ.{2}".format( - self.url_base, srcsgtval, dstsgtval - ), timeout=self.timeout + self.url_base, + srcsgtval, + dstsgtval + ), + timeout=self.timeout ) found_group = resp.json() else: @@ -820,7 +900,9 @@ def get_egressmatrixcell(self, emc, src_sgt=None, dst_sgt=None): if found_group["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/egressmatrixcell".format(self.url_base), + "{0}/config/egressmatrixcell".format( + self.url_base + ), found_group["SearchResult"]["resources"][0]["id"], "EgressMatrixCell", ) @@ -908,7 +990,9 @@ def add_egressmatrixcell( } resp = self._request( - "{0}/config/egressmatrixcell".format(self.url_base), + "{0}/config/egressmatrixcell".format( + self.url_base + ), method="post", data=json.dumps(data), ) @@ -988,7 +1072,9 @@ def update_egressmatrixcell( } resp = self._request( - ("{0}/config/egressmatrixcell/" + emc).format(self.url_base), + ("{0}/config/egressmatrixcell/" + emc).format( + self.url_base + ), method="put", data=json.dumps(data), ) @@ -1020,7 +1106,10 @@ def delete_egressmatrixcell(self, emc): } resp = self._request( - "{0}/config/egressmatrixcell/{1}".format(self.url_base, emc), + "{0}/config/egressmatrixcell/{1}".format( + self.url_base, + emc + ), method="delete", ) @@ -1056,7 +1145,10 @@ def get_object(self, url: str, objectid: str, objecttype: str): f = furl(url) f.path /= objectid - resp = self.ise.get(f.url, timeout=self.timeout) + resp = self.ise.get( + f.url, + timeout=self.timeout + ) if resp.status_code == 200: result["success"] = True @@ -1091,14 +1183,18 @@ def get_endpoint(self, mac_address): resp = self.ise.get( "{0}/config/endpoint?filter=mac.EQ.{1}".format( - self.url_base, mac_address - ), timeout=self.timeout + self.url_base, + mac_address + ), + timeout=self.timeout ) found_endpoint = resp.json() if found_endpoint["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/endpoint/".format(self.url_base), + "{0}/config/endpoint/".format( + self.url_base + ), found_endpoint["SearchResult"]["resources"][0]["id"], "ERSEndPoint", ) # noqa E501 @@ -1170,7 +1266,9 @@ def add_endpoint( } resp = self._request( - "{0}/config/endpoint".format(self.url_base), + "{0}/config/endpoint".format( + self.url_base + ), method="post", data=json.dumps(data), ) @@ -1199,13 +1297,20 @@ def delete_endpoint(self, mac): } resp = self.ise.get( - "{0}/config/endpoint?filter=mac.EQ.{1}".format(self.url_base, mac), timeout=self.timeout + "{0}/config/endpoint?filter=mac.EQ.{1}".format( + self.url_base, + mac + ), + timeout=self.timeout ) found_endpoint = resp.json() if found_endpoint["SearchResult"]["total"] == 1: endpoint_oid = found_endpoint["SearchResult"]["resources"][0]["id"] resp = self._request( - "{0}/config/endpoint/{1}".format(self.url_base, endpoint_oid), + "{0}/config/endpoint/{1}".format( + self.url_base, + endpoint_oid + ), method="delete", ) @@ -1234,7 +1339,9 @@ def get_identity_groups(self, filter=None, size=20, page=1): :return: result dictionary """ return self._get_groups( - "{0}/config/identitygroup".format(self.url_base), + "{0}/config/identitygroup".format( + self.url_base + ), filter=filter, size=size, page=page, @@ -1258,13 +1365,19 @@ def get_identity_group(self, group): } resp = self.ise.get( - "{0}/config/identitygroup?filter=name.EQ.{1}".format(self.url_base, group), timeout=self.timeout + "{0}/config/identitygroup?filter=name.EQ.{1}".format( + self.url_base, + group + ), + timeout=self.timeout ) found_group = resp.json() if found_group["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/identitygroup/".format(self.url_base), + "{0}/config/identitygroup/".format( + self.url_base + ), found_group["SearchResult"]["resources"][0]["id"], "IdentityGroup", ) @@ -1286,7 +1399,11 @@ def get_users(self, size=20, page=1): :return: List of tuples of user details """ return self._get_objects( - "{0}/config/internaluser".format(self.url_base), size=size, page=page + "{0}/config/internaluser".format( + self.url_base + ), + size=size, + page=page ) def get_user(self, user_id): @@ -1307,13 +1424,19 @@ def get_user(self, user_id): } resp = self.ise.get( - "{0}/config/internaluser?filter=name.EQ.{1}".format(self.url_base, user_id), timeout=self.timeout + "{0}/config/internaluser?filter=name.EQ.{1}".format( + self.url_base, + user_id + ), + timeout=self.timeout ) found_user = resp.json() if found_user["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/internaluser/".format(self.url_base), + "{0}/config/internaluser/".format( + self.url_base + ), found_user["SearchResult"]["resources"][0]["id"], "InternalUser", ) @@ -1375,7 +1498,9 @@ def add_user( } resp = self._request( - "{0}/config/internaluser".format(self.url_base), + "{0}/config/internaluser".format( + self.url_base + ), method="post", data=json.dumps(data), ) @@ -1404,14 +1529,21 @@ def delete_user(self, user_id): } resp = self.ise.get( - "{0}/config/internaluser?filter=name.EQ.{1}".format(self.url_base, user_id), timeout=self.timeout + "{0}/config/internaluser?filter=name.EQ.{1}".format( + self.url_base, + user_id + ), + timeout=self.timeout ) found_user = resp.json() if found_user["SearchResult"]["total"] == 1: user_oid = found_user["SearchResult"]["resources"][0]["id"] resp = self._request( - "{0}/config/internaluser/{1}".format(self.url_base, user_oid), + "{0}/config/internaluser/{1}".format( + self.url_base, + user_oid + ), method="delete", ) @@ -1439,7 +1571,11 @@ def get_device_groups(self, size=20, page=1): :return: """ return self._get_groups( - "{0}/config/networkdevicegroup".format(self.url_base), size=size, page=page + "{0}/config/networkdevicegroup".format( + self.url_base + ), + size=size, + page=page ) def get_device_group(self, device_group_oid=None, name=None): @@ -1458,7 +1594,9 @@ def get_device_group(self, device_group_oid=None, name=None): if device_group_oid is not None: device_group = self.get_object( - "{0}/config/networkdevicegroup/".format(self.url_base), + "{0}/config/networkdevicegroup/".format( + self.url_base + ), device_group_oid, "NetworkDeviceGroup", ) # noqa E501 @@ -1466,8 +1604,10 @@ def get_device_group(self, device_group_oid=None, name=None): # Using quote() function from urllib.parse to urlencode the name of the group resp = self.ise.get( "{0}/config/networkdevicegroup?filter=name.contains.{1}".format( - self.url_base, quote(name) - ), timeout=self.timeout + self.url_base, + quote(name) + ), + timeout=self.timeout ) found_group = resp.json() @@ -1512,7 +1652,9 @@ def add_device_group(self, name, description=""): } resp = self._request( - "{0}/config/networkdevicegroup".format(self.url_base), + "{0}/config/networkdevicegroup".format( + self.url_base + ), method="post", data=json.dumps(data), ) @@ -1567,7 +1709,10 @@ def update_device_group(self, device_group_oid, name=None, description=None): data["NetworkDeviceGroup"]["description"] = description resp = self._request( - "{0}/config/networkdevicegroup/{1}".format(self.url_base, device_group_oid), + "{0}/config/networkdevicegroup/{1}".format( + self.url_base, + device_group_oid + ), method="put", data=json.dumps(data), ) @@ -1600,14 +1745,19 @@ def delete_device_group(self, name): # Using quote() function from urllib.parse to urlencode the name of the group resp = self.ise.get( "{0}/config/networkdevicegroup?filter=name.contains.{1}".format( - self.url_base, quote(name) - ), timeout=self.timeout + self.url_base, + quote(name) + ), + timeout=self.timeout ) found_group = resp.json() if found_group["SearchResult"]["total"] == 1: group_oid = found_group["SearchResult"]["resources"][0]["id"] resp = self._request( - "{0}/config/networkdevicegroup/{1}".format(self.url_base, group_oid), + "{0}/config/networkdevicegroup/{1}".format( + self.url_base, + group_oid + ), method="delete", ) @@ -1635,7 +1785,9 @@ def get_devices(self, filter=None, size=20, page=1): :return: result dictionary """ return self._get_objects( - "{0}/config/networkdevice".format(self.url_base), + "{0}/config/networkdevice".format( + self.url_base + ), filter=filter, size=size, page=page, @@ -1659,13 +1811,19 @@ def get_device(self, device): } resp = self.ise.get( - "{0}/config/networkdevice?filter=name.EQ.{1}".format(self.url_base, device), timeout=self.timeout + "{0}/config/networkdevice?filter=name.EQ.{1}".format( + self.url_base, + device + ), + timeout=self.timeout ) found_device = resp.json() if found_device["SearchResult"]["total"] == 1: result = self.get_object( - "{0}/config/networkdevice/".format(self.url_base), + "{0}/config/networkdevice/".format( + self.url_base + ), found_device["SearchResult"]["resources"][0]["id"], "NetworkDevice", ) # noqa E501 @@ -1798,7 +1956,9 @@ def add_device( return result resp = self._request( - "{0}/config/networkdevice".format(self.url_base), + "{0}/config/networkdevice".format( + self.url_base + ), method="post", data=json.dumps(data), ) @@ -1828,13 +1988,20 @@ def delete_device(self, device): } resp = self.ise.get( - "{0}/config/networkdevice?filter=name.EQ.{1}".format(self.url_base, device), timeout=self.timeout + "{0}/config/networkdevice?filter=name.EQ.{1}".format( + self.url_base, + device + ), + timeout=self.timeout ) found_device = resp.json() if found_device["SearchResult"]["total"] == 1: device_oid = found_device["SearchResult"]["resources"][0]["id"] resp = self._request( - "{0}/config/networkdevice/{1}".format(self.url_base, device_oid), + "{0}/config/networkdevice/{1}".format( + self.url_base, + device_oid + ), method="delete", ) @@ -2127,7 +2294,10 @@ def update_device( # noqa C901 data = {"NetworkDevice": device} resp = self._request( - "{0}/config/networkdevice/{1}".format(self.url_base, device_oid), + "{0}/config/networkdevice/{1}".format( + self.url_base, + device_oid + ), method="put", data=json.dumps(data), ) From 636e268b5cc85769491f2bd288ba717ded4b1c03 Mon Sep 17 00:00:00 2001 From: ethangrinnell78 Date: Sun, 30 May 2021 23:41:40 -0700 Subject: [PATCH 3/3] Remove accidental comment --- ise.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ise.py b/ise.py index 0e6cf4a..49d1467 100644 --- a/ise.py +++ b/ise.py @@ -1,5 +1,3 @@ -# Final edit - """Class to configure Cisco ISE via the ERS API.""" import json import os