mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Lint, and some parameter fixes to add proxy= to some overridden load_modules fns.
This commit is contained in:
parent
1032ad28fc
commit
db4c034596
5 changed files with 3 additions and 167 deletions
|
@ -31,7 +31,7 @@ class SSHState(salt.state.State):
|
|||
self.wrapper = wrapper
|
||||
super(SSHState, self).__init__(opts, pillar)
|
||||
|
||||
def load_modules(self, data=None):
|
||||
def load_modules(self, data=None, proxy=None):
|
||||
'''
|
||||
Load up the modules for remote compilation via ssh
|
||||
'''
|
||||
|
|
|
@ -2510,7 +2510,6 @@ class ProxyMinion(Minion):
|
|||
fq_proxyname = self.opts['pillar']['proxy']['proxytype']
|
||||
self.opts['proxy'] = self.opts['pillar']['proxy']
|
||||
|
||||
|
||||
self.proxy = salt.loader.proxy(self.opts)
|
||||
self.functions, self.returners, self.function_errors = self._load_modules(proxy=self.proxy)
|
||||
self.functions.pack['__proxy__'] = self.proxy
|
||||
|
@ -2524,7 +2523,6 @@ class ProxyMinion(Minion):
|
|||
self._running = False
|
||||
raise SaltSystemExit(code=-1)
|
||||
|
||||
|
||||
proxy_init_fn = self.proxy[fq_proxyname+'.init']
|
||||
proxy_init_fn(self.opts)
|
||||
self.opts['grains'] = salt.loader.grains(self.opts)
|
||||
|
|
|
@ -41,6 +41,7 @@ def get_all():
|
|||
salt '*' service.get_all
|
||||
'''
|
||||
proxy_fn = 'rest_sample.service_list'
|
||||
log.debug(__salt__['test.arg'](1,2,3))
|
||||
return __proxy__[proxy_fn]()
|
||||
|
||||
|
||||
|
|
|
@ -1,163 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
This is a simple proxy-minion designed to connect to and communicate with
|
||||
the bottle-based web service contained in https://github.com/salt-contrib/proxyminion_rest_example
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
import salt.utils.http
|
||||
|
||||
HAS_REST_EXAMPLE = True
|
||||
|
||||
# This must be present or the Salt loader won't load this module
|
||||
__proxyenabled__ = ['rest_sample']
|
||||
|
||||
|
||||
# Variables are scoped to this module so we can have persistent data
|
||||
# across calls to fns in here.
|
||||
GRAINS_CACHE = {}
|
||||
DETAILS = {}
|
||||
|
||||
# Want logging!
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
|
||||
# This does nothing, it's here just as an example and to provide a log
|
||||
# entry when the module is loaded.
|
||||
def __virtual__():
|
||||
'''
|
||||
Only return if all the modules are available
|
||||
'''
|
||||
log.debug('rest_sample proxy __virtual__() called...')
|
||||
return True
|
||||
|
||||
|
||||
def init(opts):
|
||||
'''
|
||||
Every proxy module needs an 'init', though you can
|
||||
just put a 'pass' here if it doesn't need to do anything.
|
||||
'''
|
||||
log.debug('rest_sample proxy init() called...')
|
||||
|
||||
# Save the REST URL
|
||||
DETAILS['url'] = opts['proxy']['url']
|
||||
|
||||
# Make sure the REST URL ends with a '/'
|
||||
if not DETAILS['url'].endswith('/'):
|
||||
DETAILS['url'] += '/'
|
||||
|
||||
|
||||
def grains():
|
||||
'''
|
||||
Get the grains from the proxied device
|
||||
'''
|
||||
if not GRAINS_CACHE:
|
||||
r = salt.utils.http.query(DETAILS['url']+'info', decode_type='json', decode=True)
|
||||
GRAINS_CACHE = r['dict']
|
||||
return GRAINS_CACHE
|
||||
|
||||
|
||||
def grains_refresh():
|
||||
'''
|
||||
Refresh the grains from the proxied device
|
||||
'''
|
||||
GRAINS_CACHE = {}
|
||||
return grains()
|
||||
|
||||
|
||||
def service_start(name):
|
||||
'''
|
||||
Start a "service" on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'service/start/'+name, decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def service_stop(name):
|
||||
'''
|
||||
Stop a "service" on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'service/stop/'+name, decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def service_restart(name):
|
||||
'''
|
||||
Restart a "service" on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'service/restart/'+name, decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def service_list():
|
||||
'''
|
||||
List "services" on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'service/list', decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def service_status(name):
|
||||
'''
|
||||
Check if a service is running on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'service/status/'+name, decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def package_list():
|
||||
'''
|
||||
List "packages" installed on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'package/list', decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def package_install(name, **kwargs):
|
||||
'''
|
||||
Install a "package" on the REST server
|
||||
'''
|
||||
cmd = DETAILS['url']+'package/install/'+name
|
||||
if 'version' in kwargs:
|
||||
cmd += '/'+kwargs['version']
|
||||
else:
|
||||
cmd += '/1.0'
|
||||
r = salt.utils.http.query(cmd, decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def package_remove(name):
|
||||
|
||||
'''
|
||||
Remove a "package" on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'package/remove/'+name, decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def package_status(name):
|
||||
'''
|
||||
Check the installation status of a package on the REST server
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'package/status/'+name, decode_type='json', decode=True)
|
||||
return r['dict']
|
||||
|
||||
|
||||
def ping():
|
||||
'''
|
||||
Is the REST server up?
|
||||
'''
|
||||
r = salt.utils.http.query(DETAILS['url']+'ping', decode_type='json', decode=True)
|
||||
try:
|
||||
return r['dict'].get('ret', False)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def shutdown(opts):
|
||||
'''
|
||||
For this proxy shutdown is a no-op
|
||||
'''
|
||||
log.debug('rest_sample proxy shutdown() called...')
|
|
@ -3202,7 +3202,7 @@ class MasterState(State):
|
|||
def __init__(self, opts, minion):
|
||||
State.__init__(self, opts)
|
||||
|
||||
def load_modules(self, data=None):
|
||||
def load_modules(self, data=None, proxy=None):
|
||||
'''
|
||||
Load the modules into the state
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue