Skip to content

Commit 4b932b9

Browse files
committed
is_alive() method
1 parent 913f249 commit 4b932b9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pyIOSXR/exceptions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class IOSXRException(Exception):
2323

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

26-
super(Exception, self).__init__(msg)
26+
super(IOSXRException, self).__init__(msg)
2727
if dev:
2828
self._xr = dev
2929
# release the XML agent
@@ -34,7 +34,11 @@ def __init__(self, msg=None, dev=None):
3434
class ConnectError(IOSXRException):
3535
"""Exception while openning the connection."""
3636

37-
pass
37+
def __init__(self, msg=None, dev=None):
38+
super(ConnectError, self).__init__(msg=msg, dev=dev)
39+
if dev:
40+
self._xr = dev
41+
self._xr._xml_agent_alive = False
3842

3943

4044
class CommitError(IOSXRException):

pyIOSXR/iosxr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(self,
9191
self.locked = False
9292
self._cli_prompt = None
9393
self._xml_agent_locker = Lock()
94+
self._xml_agent_alive = False
9495

9596
def __getattr__(self, item):
9697
"""
@@ -155,6 +156,7 @@ def open(self):
155156
username=self.username,
156157
password=self.password)
157158
self.device.timeout = self.timeout
159+
self._xml_agent_alive = True # successfully open thus alive
158160
except NetMikoTimeoutException as t_err:
159161
raise ConnectError(t_err.message)
160162
except NetMikoAuthenticationException as au_err:
@@ -164,6 +166,12 @@ def open(self):
164166

165167
self._enter_xml_mode()
166168

169+
def is_alive(self):
170+
"""
171+
Returns the XML agent connection state.
172+
"""
173+
return self._xml_agent_alive
174+
167175
def _timeout_exceeded(self, start=None, msg='Timeout exceeded!'):
168176
if not start:
169177
return False # reference not specified, noth to compare => no error

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# e.g. ['django==1.5.1', 'mezzanine==1.4.6']
2929
reqs = [str(ir.req) for ir in install_reqs]
3030

31-
version = '0.25'
31+
version = '0.26'
3232

3333
setup(
3434
name='pyIOSXR',

0 commit comments

Comments
 (0)