mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge pull request #43603 from Juniper/develop
keep alive feature for junos and schedular support for rpc call
This commit is contained in:
commit
58278a10d3
@ -27,6 +27,7 @@ except ImportError:
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.files
|
||||
from salt.ext import six
|
||||
|
||||
# Juniper interface libraries
|
||||
# https://github.com/Juniper/py-junos-eznc
|
||||
@ -176,6 +177,10 @@ def rpc(cmd=None, dest=None, format='xml', **kwargs):
|
||||
if kwargs['__pub_arg']:
|
||||
if isinstance(kwargs['__pub_arg'][-1], dict):
|
||||
op.update(kwargs['__pub_arg'][-1])
|
||||
elif '__pub_schedule' in kwargs:
|
||||
for key, value in six.iteritems(kwargs):
|
||||
if not key.startswith('__pub_'):
|
||||
op[key] = value
|
||||
else:
|
||||
op.update(kwargs)
|
||||
op['dev_timeout'] = str(op.pop('timeout', conn.timeout))
|
||||
|
@ -37,7 +37,6 @@ Run the salt proxy via the following command:
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
||||
# Import 3rd-party libs
|
||||
@ -47,6 +46,11 @@ try:
|
||||
import jnpr.junos.utils
|
||||
import jnpr.junos.utils.config
|
||||
import jnpr.junos.utils.sw
|
||||
from jnpr.junos.exception import RpcTimeoutError
|
||||
from jnpr.junos.exception import ConnectClosedError
|
||||
from jnpr.junos.exception import RpcError
|
||||
from jnpr.junos.exception import ConnectError
|
||||
from ncclient.operations.errors import TimeoutExpiredError
|
||||
except ImportError:
|
||||
HAS_JUNOS = False
|
||||
|
||||
@ -118,11 +122,31 @@ def conn():
|
||||
|
||||
def alive(opts):
|
||||
'''
|
||||
Return the connection status with the remote device.
|
||||
Validate and return the connection status with the remote device.
|
||||
|
||||
.. versionadded:: Oxygen
|
||||
'''
|
||||
return thisproxy['conn'].connected
|
||||
|
||||
dev = conn()
|
||||
|
||||
# Check that the underlying netconf connection still exists.
|
||||
if dev._conn is None:
|
||||
return False
|
||||
|
||||
# call rpc only if ncclient queue is empty. If not empty that means other
|
||||
# rpc call is going on.
|
||||
if hasattr(dev._conn, '_session'):
|
||||
if dev._conn._session._transport.is_active():
|
||||
# there is no on going rpc call.
|
||||
if dev._conn._session._q.empty():
|
||||
thisproxy['conn'].connected = ping()
|
||||
else:
|
||||
# ssh connection is lost
|
||||
dev.connected = False
|
||||
else:
|
||||
# other connection modes, like telnet
|
||||
thisproxy['conn'].connected = ping()
|
||||
return dev.connected
|
||||
|
||||
|
||||
def proxytype():
|
||||
@ -150,7 +174,16 @@ def ping():
|
||||
'''
|
||||
Ping? Pong!
|
||||
'''
|
||||
return thisproxy['conn'].connected
|
||||
|
||||
dev = conn()
|
||||
try:
|
||||
dev.rpc.file_list(path='/dev/null', dev_timeout=2)
|
||||
return True
|
||||
except (RpcTimeoutError, ConnectClosedError):
|
||||
try:
|
||||
dev.close()
|
||||
except (RpcError, ConnectError, TimeoutExpiredError):
|
||||
return False
|
||||
|
||||
|
||||
def shutdown(opts):
|
||||
|
Loading…
Reference in New Issue
Block a user