Skip to content

Commit

Permalink
connection manager sessions query string param workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbalogh committed Feb 23, 2018
1 parent 23a2957 commit 20bec74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
31 changes: 20 additions & 11 deletions ixnetwork/IxnHttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(self, hostname, rest_port=80, secure=False, api_key=None):
self._meta_data = {}
self._headers = {}
self._verify_cert = False
self._deprecated = True
self._links = True
self.trace = False
if api_key is not None:
self._headers['X-Api-Key'] = api_key
Expand Down Expand Up @@ -75,7 +77,9 @@ def auth(self, username, password):

def sessions(self):
"""Get a list of sessions on the server """
return self.get('/api/v1/sessions', links=False)
self._links = False
self._deprecated = False
return self.get('/api/v1/sessions')

def create_session(self):
"""Create and set a new IxNetwork session on the host specified in the constructor """
Expand Down Expand Up @@ -138,13 +142,12 @@ def _process_async_response(self, url, response):
raise Exception('%s: %s - %s' % (response.state, response.message, response.result))
return response

def get(self, url, fid=None, links=True):
if str(url).find('links=true') == -1 and links is True:
if str(url).find('?') == -1:
url += "?"
def get(self, url, fid=None):
if str(url).find('links=true') == -1 and self._links is True:
if '?' in url:
url = '%s&links=true' % url
else:
url += "&"
url += "links=true"
url = '%s?links=true' % url
return self._send_recv('GET', url, payload=None, fid=fid)

def post(self, url, payload=None, fid=None, file_content=None):
Expand Down Expand Up @@ -180,13 +183,19 @@ def _send_recv(self, method, url, payload=None, fid=None, file_content=None):
if url.find('/api/v1/sessions') == -1 and self.current_session is not None:
url = "/api/v1/sessions/%s/ixnetwork%s" % (self.current_session.id, url)
url = '%s%s' % (self._connection, url)
if '?' in url:
url = '%s&deprecated=true' % url
else:
url = '%s?deprecated=true' % url
if str(url).find('deprecated=true') == -1 and self._deprecated is True:
if '?' in url:
url = '%s&deprecated=true' % url
else:
url = '%s?deprecated=true' % url
headers = self._headers.copy()

if self.trace:
print('%s %s %s' % (int(time.time()), method, url))

self._links = True
self._deprecated = True

if payload is not None:
headers['Content-Type'] = 'application/json'
response = requests.request(method, url, data=json.dumps(payload), headers=headers, verify=self._verify_cert)
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.55a54',
version='0.55a55',

description='IxNetwork REST API Client',
long_description=long_description,
Expand Down Expand Up @@ -85,5 +85,7 @@
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=[],
install_requires=[
'requests'
],
)

0 comments on commit 20bec74

Please sign in to comment.