mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add salt-api on Windows platform
salt-api is broken on Windows platform due to pickling issues on the salt.loader.netapi Workaround that by creating a runner class that can be pickled. Signed-off-by: Rares POP <rares.pop@ni.com>
This commit is contained in:
parent
56e0ed7996
commit
c640b5cd42
4 changed files with 74 additions and 1 deletions
|
@ -559,3 +559,14 @@ it could only search for users via the 'accountattributename' field. This releas
|
|||
add an additional search using the 'groupattribute' field as well. The original
|
||||
'accountattributename' search is done first then the 'groupattribute' allowing for
|
||||
backward compatibility with previous Salt releases.
|
||||
|
||||
============================
|
||||
salt-api
|
||||
============================
|
||||
|
||||
salt-api Windows support
|
||||
--------------------------------
|
||||
Previously, salt-api was was not supported on the Microsoft Windows platforms. Now it is!
|
||||
salt-api is providing a RESTful interface to a running Salt system. It allows
|
||||
for viewing minions, runners, and jobs as well as running execution modules
|
||||
and runners of a running Salt system through a REST API that returns JSON.
|
||||
|
|
12
pkg/windows/buildenv/salt-api.bat
Normal file
12
pkg/windows/buildenv/salt-api.bat
Normal file
|
@ -0,0 +1,12 @@
|
|||
@ echo off
|
||||
:: Script for starting the Salt-Api
|
||||
:: Accepts all parameters that Salt-Api accepts
|
||||
|
||||
:: Define Variables
|
||||
Set SaltDir=%~dp0
|
||||
Set SaltDir=%SaltDir:~0,-1%
|
||||
Set Python=%SaltDir%\bin\python.exe
|
||||
Set Script=%SaltDir%\bin\Scripts\salt-api
|
||||
|
||||
:: Launch Script
|
||||
"%Python%" -E -s "%Script%" %*
|
|
@ -14,6 +14,41 @@ import salt.utils.process
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RunNetapi(salt.utils.process.SignalHandlingMultiprocessingProcess):
|
||||
'''
|
||||
Runner class that's pickable for netapi modules
|
||||
'''
|
||||
def __init__(self, opts, fname, **kwargs):
|
||||
super(RunNetapi, self).__init__(**kwargs)
|
||||
self.opts = opts
|
||||
self.fname = fname
|
||||
|
||||
# __setstate__ and __getstate__ are only used on Windows.
|
||||
# We do this so that __init__ will be invoked on Windows in the child
|
||||
# process so that a register_after_fork() equivalent will work on Windows.
|
||||
def __setstate__(self, state):
|
||||
self._is_child = True
|
||||
self.__init__(
|
||||
state['opts'],
|
||||
state['fname'],
|
||||
log_queue=state['log_queue'],
|
||||
log_queue_level=state['log_queue_level']
|
||||
)
|
||||
|
||||
def __getstate__(self):
|
||||
return {
|
||||
'opts': self.opts,
|
||||
'fname': self.fname,
|
||||
'log_queue': self.log_queue,
|
||||
'log_queue_level': self.log_queue_level
|
||||
}
|
||||
|
||||
def run(self):
|
||||
netapi = salt.loader.netapi(self.opts)
|
||||
netapi_func = netapi[self.fname]
|
||||
netapi_func()
|
||||
|
||||
|
||||
class NetapiClient(object):
|
||||
'''
|
||||
Start each netapi module that is configured to run
|
||||
|
@ -30,10 +65,20 @@ class NetapiClient(object):
|
|||
if not len(self.netapi):
|
||||
log.error("Did not find any netapi configurations, nothing to start")
|
||||
|
||||
kwargs = {}
|
||||
if salt.utils.platform.is_windows():
|
||||
kwargs['log_queue'] = salt.log.setup.get_multiprocessing_logging_queue()
|
||||
kwargs['log_queue_level'] = salt.log.setup.get_multiprocessing_logging_level()
|
||||
|
||||
for fun in self.netapi:
|
||||
if fun.endswith('.start'):
|
||||
log.info('Starting %s netapi module', fun)
|
||||
self.process_manager.add_process(self.netapi[fun])
|
||||
self.process_manager.add_process(
|
||||
RunNetapi,
|
||||
args=(self.opts, fun),
|
||||
kwargs=kwargs,
|
||||
name='RunNetapi'
|
||||
)
|
||||
|
||||
# Install the SIGINT/SIGTERM handlers if not done so far
|
||||
if signal.getsignal(signal.SIGINT) is signal.SIG_DFL:
|
||||
|
|
|
@ -42,6 +42,11 @@ class NetapiClient(object):
|
|||
Note, this will return an invalid success if the master crashed or was
|
||||
not shut down cleanly.
|
||||
'''
|
||||
# Windows doesn't have IPC. Assume the master is running.
|
||||
# At worse, it will error 500.
|
||||
if salt.utils.platform.is_windows():
|
||||
return True
|
||||
|
||||
if self.opts['transport'] == 'tcp':
|
||||
ipc_file = 'publish_pull.ipc'
|
||||
else:
|
||||
|
|
Loading…
Add table
Reference in a new issue