Merge pull request #28027 from cro/persistent_ssh

Make ssh conn persistent.
This commit is contained in:
Aditya Kulkarni 2015-10-16 14:50:51 -04:00
commit 4f81358e9a
2 changed files with 36 additions and 20 deletions

View file

@ -86,7 +86,7 @@ VALID_OPTS = {
# Selects a random master when starting a minion up in multi-master mode
'master_shuffle': bool,
# When in mulit-master mode, temporarily remove a master from the list if a conenction
# When in multi-master mode, temporarily remove a master from the list if a conenction
# is interrupted and try another master in the list.
'master_alive_interval': int,
@ -239,7 +239,7 @@ VALID_OPTS = {
# The ipc strategy. (i.e., sockets versus tcp, etc)
'ipc_mode': str,
# Enable ipv6 support for deamons
# Enable ipv6 support for daemons
'ipv6': bool,
# The chunk size to use when streaming files with the file server
@ -394,7 +394,7 @@ VALID_OPTS = {
'range_server': str,
# The tcp keepalive interval to set on TCP ports. This setting can be used to tune salt connectivity
# issues in messy network environments with misbeahving firewalls
# issues in messy network environments with misbehaving firewalls
'tcp_keepalive': bool,
# Sets zeromq TCP keepalive idle. May be used to tune issues with minion disconnects
@ -1188,7 +1188,13 @@ DEFAULT_MASTER_OPTS = {
DEFAULT_PROXY_MINION_OPTS = {
'conf_file': os.path.join(salt.syspaths.CONFIG_DIR, 'proxy'),
'log_file': os.path.join(salt.syspaths.LOGS_DIR, 'proxy'),
'add_proxymodule_to_opts': True
'add_proxymodule_to_opts': True,
# Default multiprocessing to False since anything that needs
# salt.vt will have trouble with our forking model.
# Proxies with non-persistent (mostly REST API) connections
# can change this back to True
'multiprocessing': False
}
# ----- Salt Cloud Configuration Defaults ----------------------------------->

View file

@ -13,10 +13,13 @@ import logging
# Import Salt's libs
from salt.utils.vt_helper import SSHConnection
from salt.utils.vt import TerminalException
# This must be present or the Salt loader won't load this module
__proxyenabled__ = ['ssh_sample']
DETAILS = {}
# Want logging!
log = logging.getLogger(__file__)
@ -28,6 +31,7 @@ def __virtual__():
Only return if all the modules are available
'''
log.info('ssh_sample proxy __virtual__() called...')
return True
@ -36,15 +40,22 @@ def init(opts):
Required.
Can be used to initialize the server connection.
'''
pass
try:
DETAILS['server'] = SSHConnection(host=__opts__['proxy']['host'],
username=__opts__['proxy']['username'],
password=__opts__['proxy']['password'])
out, err = DETAILS['server'].sendline('help')
except TerminalException as e:
log.error(e)
return False
def shutdown(opts):
'''
Required.
Can be used to dispose the server connection.
Disconnect
'''
pass
DETAILS['server'].close_connection()
def package_list():
@ -56,19 +67,18 @@ def package_list():
salt target_minion pkg.list_pkgs
'''
# This method shows the full sequence from
# initializing a connection, executing a command,
# parsing the output and closing the connection.
# In production these steps can (and probably should)
# be in separate methods.
# Create the server connection
server = SSHConnection(host='salt',
username='salt',
password='password')
# Send the command to execute
out, err = server.sendline('pkg_list')
out, err = DETAILS['server'].sendline('pkg_list')
jsonret = []
in_json = False
# "scrape" the output and return the right fields as a dict
return json.loads(out[9:-7])
for l in out.split():
if '{' in l:
in_json = True
if in_json:
jsonret.append(l)
if '}' in l:
in_json = False
return json.loads('\n'.join(jsonret))