Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #151 from jasonbarbee/version-support
Browse files Browse the repository at this point in the history
Obtain version on class init, allow compatibility with 2.x and 3.x APIs.
  • Loading branch information
falkowich authored May 22, 2021
2 parents e6412f6 + 0d79383 commit d30524c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 20 additions & 2 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 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.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ beautifulsoup4
furl
lxml
requests
beautifulsoup4
lxml

0 comments on commit d30524c

Please sign in to comment.