Skip to content

Commit

Permalink
get version on init, initial support of issue falkowich#148
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbarbee committed Apr 28, 2021
1 parent 4a0863c commit f08a61d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
24 changes: 21 additions & 3 deletions ise.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from furl import furl
from datetime import datetime, timedelta
from bs4 import BeautifulSoup

import requests

Expand All @@ -19,7 +20,7 @@ def __str__(self):


class ERS(object):
def __init__(self, ise_node, ers_user, ers_pass, verify=False, disable_warnings=False, use_csrf=False, timeout=2,
def __init__(self, ise_node, ers_user, ers_pass, verify=False, disable_warnings=False, use_csrf=False, timeout=4,
protocol='https'):
"""
Class to interact with Cisco ISE via the ERS API.
Expand Down Expand Up @@ -47,9 +48,10 @@ def __init__(self, ise_node, ers_user, ers_pass, verify=False, disable_warnings=
self.csrf_expires = None
self.timeout = timeout
self.ise.headers.update({'Connection': 'keep_alive'})

if self.disable_warnings:
requests.packages.urllib3.disable_warnings()
self.version = self.get_version()

@staticmethod
def _mac_test(mac):
Expand Down Expand Up @@ -140,6 +142,22 @@ def _request(self, url, method="get", data=None):

return req

def get_version(self):
try:
# Build MnT API URL
url = "https://" + self.ise_node + "/admin/API/mnt/Version"
# Access MnT API
req = self.ise.request('get', url, data=None, timeout=self.timeout)
# Extract version of first node
soup = BeautifulSoup(req.content,'xml')
full_version = soup.find_all('version')[0].get_text()
# Get simple version ie: 2.7
short_version = float(full_version[0:3])
# print("ISE Initializing - Version Check " + full_version)
return short_version
except:
return ""

def _get_groups(self, url, filter: str = None, size: int = 20, page: int = 1):
"""
Get generic group lists.
Expand Down Expand Up @@ -1401,4 +1419,4 @@ def delete_device(self, device):
result['error'] = 404
return result
else:
return ERS._pass_ersresponse(result, resp)
return ERS._pass_ersresponse(result, resp)
2 changes: 2 additions & 0 deletions requirements-publish-pypi.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
setuptools==46.1.3
twine==3.1.1
wheel==0.34.2
beautifulsoup4==4.9.3
lxml==4.6.3
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

furl
requests
beautifulsoup4
lxml

0 comments on commit f08a61d

Please sign in to comment.