Skip to content

Commit

Permalink
Merge pull request #31 from mirceaulinic/IS-ALIVE
Browse files Browse the repository at this point in the history
is_alive() method
  • Loading branch information
mirceaulinic authored Nov 28, 2016
2 parents 913f249 + 4b932b9 commit 3cc0323
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pyIOSXR/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IOSXRException(Exception):

def __init__(self, msg=None, dev=None):

super(Exception, self).__init__(msg)
super(IOSXRException, self).__init__(msg)
if dev:
self._xr = dev
# release the XML agent
Expand All @@ -34,7 +34,11 @@ def __init__(self, msg=None, dev=None):
class ConnectError(IOSXRException):
"""Exception while openning the connection."""

pass
def __init__(self, msg=None, dev=None):
super(ConnectError, self).__init__(msg=msg, dev=dev)
if dev:
self._xr = dev
self._xr._xml_agent_alive = False


class CommitError(IOSXRException):
Expand Down
8 changes: 8 additions & 0 deletions pyIOSXR/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self,
self.locked = False
self._cli_prompt = None
self._xml_agent_locker = Lock()
self._xml_agent_alive = False

def __getattr__(self, item):
"""
Expand Down Expand Up @@ -155,6 +156,7 @@ def open(self):
username=self.username,
password=self.password)
self.device.timeout = self.timeout
self._xml_agent_alive = True # successfully open thus alive
except NetMikoTimeoutException as t_err:
raise ConnectError(t_err.message)
except NetMikoAuthenticationException as au_err:
Expand All @@ -164,6 +166,12 @@ def open(self):

self._enter_xml_mode()

def is_alive(self):
"""
Returns the XML agent connection state.
"""
return self._xml_agent_alive

def _timeout_exceeded(self, start=None, msg='Timeout exceeded!'):
if not start:
return False # reference not specified, noth to compare => no error
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# e.g. ['django==1.5.1', 'mezzanine==1.4.6']
reqs = [str(ir.req) for ir in install_reqs]

version = '0.25'
version = '0.26'

setup(
name='pyIOSXR',
Expand Down

0 comments on commit 3cc0323

Please sign in to comment.