mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Fix some problems with the rest_sample, remove unnecessary file and make sure that rest_service has the right contents.
This commit is contained in:
parent
f4944fe68a
commit
e3ebff9bce
@ -43,11 +43,11 @@ def defaults():
|
||||
|
||||
|
||||
def facts():
|
||||
log.debug('----------- Trying to get facts')
|
||||
if 'proxymodule' in __opts__:
|
||||
facts = __opts__['proxymodule']['junos.facts']()
|
||||
facts['version_info'] = 'override'
|
||||
return facts
|
||||
if 'junos.facts' in __opts__['proxymodule']:
|
||||
facts = __opts__['proxymodule']['junos.facts']()
|
||||
facts['version_info'] = 'override'
|
||||
return facts
|
||||
return None
|
||||
|
||||
|
||||
|
@ -2,12 +2,16 @@
|
||||
'''
|
||||
Generate baseline proxy minion grains
|
||||
'''
|
||||
import logging
|
||||
|
||||
__proxyenabled__ = ['rest_sample']
|
||||
|
||||
__virtualname__ = 'rest_sample'
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
def __virtual__():
|
||||
log.debug('In RestExample grains virtual-------------------------------')
|
||||
if 'proxy' not in __opts__:
|
||||
return False
|
||||
else:
|
||||
@ -19,7 +23,7 @@ def kernel():
|
||||
|
||||
|
||||
def os():
|
||||
return {'os': 'proxy'}
|
||||
return {'os': 'RestExampleOS'}
|
||||
|
||||
|
||||
def location():
|
||||
|
@ -253,6 +253,7 @@ def proxy(opts, functions, whitelist=None, loaded_base_name=None):
|
||||
'''
|
||||
Returns the proxy module for this salt-proxy-minion
|
||||
'''
|
||||
dirs = _module_dirs(opts, 'proxy', 'proxy')
|
||||
return LazyLoader(_module_dirs(opts, 'proxy', 'proxy'),
|
||||
opts,
|
||||
tag='proxy',
|
||||
|
@ -2515,9 +2515,18 @@ class ProxyMinion(Minion):
|
||||
|
||||
self.opts['proxymodule'] = salt.loader.proxy(self.opts, None, loaded_base_name=fq_proxyname)
|
||||
self.functions, self.returners, self.function_errors = self._load_modules()
|
||||
proxy_fn = self.opts['proxymodule'].loaded_base_name + '.init'
|
||||
self.opts['proxymodule'][proxy_fn](self.opts)
|
||||
|
||||
if ('{0}.init'.format(fq_proxyname) not in self.opts['proxymodule']
|
||||
or '{0}.shutdown'.format(fq_proxyname) not in self.opts['proxymodule']):
|
||||
log.error('Proxymodule {0} is missing an init() or a shutdown() or both.'.format(fq_proxyname));
|
||||
log.error('Check your proxymodule. Salt-proxy aborted.')
|
||||
self._running = False
|
||||
raise SaltSystemExit(code=-1)
|
||||
|
||||
proxy_fn = self.opts['proxymodule'].loaded_base_name + '.init'
|
||||
|
||||
self.opts['proxymodule'][proxy_fn](self.opts)
|
||||
# reload ?!?
|
||||
self.serial = salt.payload.Serial(self.opts)
|
||||
self.mod_opts = self._prep_mod_opts()
|
||||
self.matcher = Matcher(self.opts, self.functions)
|
||||
|
@ -1,99 +1,117 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Service support for the REST example
|
||||
Provide the service module for the proxy-minion REST sample
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
|
||||
__proxyenabled__ = ['rest_sample']
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__proxyenabled__ = ['rest_sample']
|
||||
__func_alias__ = {
|
||||
'reload_': 'reload'
|
||||
}
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'service'
|
||||
|
||||
# Don't shadow built-ins.
|
||||
__func_alias__ = {
|
||||
'list_': 'list'
|
||||
}
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only work on RestExampleOS
|
||||
Only work on systems that are a proxy minion
|
||||
'''
|
||||
# Enable on these platforms only.
|
||||
enable = set((
|
||||
'RestExampleOS',
|
||||
))
|
||||
if __grains__['os'] in enable:
|
||||
if __grains__['os'] == 'proxy':
|
||||
return __virtualname__
|
||||
return False
|
||||
|
||||
|
||||
def start(name):
|
||||
def get_all():
|
||||
'''
|
||||
Start the specified service
|
||||
Return a list of all available services
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' rest_service.start <service name>
|
||||
salt '*' service.get_all
|
||||
'''
|
||||
return __opts__['proxyobject'].service_start(name)
|
||||
proxy_fn = 'rest_sample'+ '.service_list'
|
||||
return __opts__['proxymodule'][proxy_fn]()
|
||||
|
||||
|
||||
def stop(name):
|
||||
def start(name, sig=None):
|
||||
'''
|
||||
Stop the specified service
|
||||
Start the specified service on the rest_sample
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' rest_service.stop <service name>
|
||||
salt '*' service.start <service name>
|
||||
'''
|
||||
return __opts__['proxyobject'].service_stop(name)
|
||||
|
||||
proxy_fn = 'rest_sample'+ '.service_start'
|
||||
return __opts__['proxymodule'][proxy_fn](name)
|
||||
|
||||
|
||||
def restart(name):
|
||||
def stop(name, sig=None):
|
||||
'''
|
||||
Restart the named service
|
||||
Stop the specified service on the rest_sample
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' rest_service.restart <service name>
|
||||
salt '*' service.stop <service name>
|
||||
'''
|
||||
|
||||
return __opts__['proxyobject'].service_restart(name)
|
||||
proxy_fn = 'rest_sample'+ '.service_stop'
|
||||
return __opts__['proxymodule'][proxy_fn](name)
|
||||
|
||||
|
||||
def status(name):
|
||||
def restart(name, sig=None):
|
||||
'''
|
||||
Return the status for a service, returns a bool whether the service is
|
||||
running.
|
||||
Restart the specified service with rest_sample
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' rest_service.status <service name>
|
||||
salt '*' service.restart <service name>
|
||||
'''
|
||||
return __opts__['proxyobject'].service_status(name)
|
||||
|
||||
proxy_fn = 'rest_sample'+ '.service_restart'
|
||||
return __opts__['proxymodule'][proxy_fn](name)
|
||||
|
||||
|
||||
def list_():
|
||||
def status(name, sig=None):
|
||||
'''
|
||||
List services.
|
||||
Return the status for a service via rest_sample, returns a bool
|
||||
whether the service is running.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' rest_service.list <service name>
|
||||
salt '*' service.status <service name>
|
||||
'''
|
||||
return __opts__['proxyobject'].service_list()
|
||||
|
||||
proxy_fn = 'rest_sample' + '.service_status'
|
||||
resp = __opts__['proxymodule'][proxy_fn](name)
|
||||
if resp['comment'] == 'stopped':
|
||||
return False
|
||||
if resp['comment'] == 'running':
|
||||
return True
|
||||
|
||||
def running(name, sig=None):
|
||||
'''
|
||||
Return whether this service is running.
|
||||
'''
|
||||
return status(name).get(name, False)
|
||||
|
||||
def enabled(name, sig=None):
|
||||
'''
|
||||
Only the 'redbull' service is 'enabled' in the test
|
||||
'''
|
||||
return name == 'redbull'
|
||||
|
@ -1,105 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Provide the service module for the proxy-minion REST sample
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
|
||||
__proxyenabled__ = ['rest_sample']
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__func_alias__ = {
|
||||
'reload_': 'reload'
|
||||
}
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'service'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only work on systems that are a proxy minion
|
||||
'''
|
||||
if __grains__['kernel'] == 'proxy':
|
||||
return __virtualname__
|
||||
return False
|
||||
|
||||
|
||||
def get_all():
|
||||
'''
|
||||
Return a list of all available services
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' service.get_all
|
||||
'''
|
||||
proxy_fn = 'rest_sample'+ '.service_list'
|
||||
return __opts__['proxymodule'][proxy_fn]()
|
||||
|
||||
|
||||
def start(name):
|
||||
'''
|
||||
Start the specified service on the rest_sample
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' service.start <service name>
|
||||
'''
|
||||
|
||||
proxy_fn = 'rest_sample'+ '.service_start'
|
||||
return __opts__['proxymodule'][proxy_fn](name)
|
||||
|
||||
|
||||
def stop(name):
|
||||
'''
|
||||
Stop the specified service on the rest_sample
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' service.stop <service name>
|
||||
'''
|
||||
proxy_fn = 'rest_sample'+ '.service_stop'
|
||||
return __opts__['proxymodule'][proxy_fn](name)
|
||||
|
||||
|
||||
def restart(name):
|
||||
'''
|
||||
Restart the specified service with rest_sample
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' service.restart <service name>
|
||||
'''
|
||||
|
||||
proxy_fn = 'rest_sample'+ '.service_restart'
|
||||
return __opts__['proxymodule'][proxy_fn](name)
|
||||
|
||||
|
||||
def status(name, sig):
|
||||
'''
|
||||
Return the status for a service via rest_sample, returns a bool
|
||||
whether the service is running.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' service.status <service name>
|
||||
'''
|
||||
|
||||
proxy_fn = 'rest_sample' + '.service_status'
|
||||
resp = __opts__['proxymodule'][proxy_fn](name)
|
||||
if resp['comment'] == 'stopped':
|
||||
return {name: False}
|
||||
if resp['comment'] == 'running':
|
||||
return {name: True}
|
Loading…
Reference in New Issue
Block a user