From 20bec744c743d5953340799c842d1c8e8635e123 Mon Sep 17 00:00:00 2001 From: Andy Balogh Date: Fri, 23 Feb 2018 08:31:47 -0800 Subject: [PATCH] connection manager sessions query string param workaround --- ixnetwork/IxnHttp.py | 31 ++++++++++++++++++++----------- setup.py | 6 ++++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ixnetwork/IxnHttp.py b/ixnetwork/IxnHttp.py index ec69267..920cf97 100644 --- a/ixnetwork/IxnHttp.py +++ b/ixnetwork/IxnHttp.py @@ -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 @@ -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 """ @@ -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): @@ -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) diff --git a/setup.py b/setup.py index 96ca724..50488fc 100644 --- a/setup.py +++ b/setup.py @@ -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, @@ -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' + ], )