salt-api
#
Salt API Factory.
- class saltfactories.daemons.api.SaltApi(*, config, config_dir=_Nothing.NOTHING, python_executable=None, system_service=False, cwd=_Nothing.NOTHING, environ=_Nothing.NOTHING, slow_stop=True, system_encoding=_Nothing.NOTHING, timeout=_Nothing.NOTHING, script_name, base_script_args=_Nothing.NOTHING, check_ports=_Nothing.NOTHING, stats_processes=None, start_timeout, max_start_attempts=3, extra_cli_arguments_after_first_start_failure=_Nothing.NOTHING, start_checks_callbacks=_Nothing.NOTHING, event_listener=None, factories_manager=None, started_at=None)[source]#
Bases:
SaltDaemon
salt-api daemon factory.
- Parameters:
environ (EnvironDict) –
slow_stop (bool) –
system_encoding (str) –
script_name (str) –
stats_processes (StatsProcesses) –
max_start_attempts (int) –
- get_check_events()[source]#
Return salt events to check.
Return a list of tuples in the form of (master_id, event_tag) check against to ensure the daemon is running
- after_start(callback, *args, **kwargs)#
Register a function callback to run after the daemon starts.
- Arguments:
- callback:
The function to call back
- Keyword Arguments:
- args:
The arguments to pass to the callback
- kwargs:
The keyword arguments to pass to the callback
- Returns:
Nothing.
- after_terminate(callback, *args, **kwargs)#
Register a function callback to run after the daemon terminates.
- Arguments:
- callback:
The function to call back
- Keyword Arguments:
- args:
The arguments to pass to the callback
- kwargs:
The keyword arguments to pass to the callback
- Returns:
Nothing.
- before_start(callback, *args, **kwargs)#
Register a function callback to run before the daemon starts.
- Arguments:
- callback:
The function to call back
- Keyword Arguments:
- args:
The arguments to pass to the callback
- kwargs:
The keyword arguments to pass to the callback
- Returns:
Nothing.
- before_terminate(callback, *args, **kwargs)#
Register a function callback to run before the daemon terminates.
- Arguments:
- callback:
The function to call back
- Keyword Arguments:
- args:
The arguments to pass to the callback
- kwargs:
The keyword arguments to pass to the callback
- Returns:
Nothing.
- cmdline(*args)#
Construct a list of arguments to use when starting the subprocess.
- Parameters:
args (str) – Additional arguments to use when starting the subprocess
- classmethod configure(factories_manager, daemon_id, root_dir=None, defaults=None, overrides=None, **configure_kwargs)#
Configure the salt daemon.
- get_base_script_args()#
Returns any additional arguments to pass to the CLI script.
- get_check_ports()#
Return a list of ports to check against to ensure the daemon is running.
- get_display_name()#
Returns a human readable name for the factory.
- get_script_args()#
Returns any additional arguments to pass to the CLI script.
- get_start_check_callbacks()#
Return a list of the start check callbacks.
- process_output(stdout, stderr, cmdline=None)#
Process the output. When possible JSON is loaded from the output.
- Returns:
Returns a tuple in the form of
(stdout, stderr, loaded_json)
- run(*args, env=None, _timeout=None, **kwargs)#
Run the given command synchronously.
- Keyword Arguments:
- args:
The list of arguments to pass to
cmdline()
to construct the command to run- env:
Pass a dictionary of environment key, value pairs to inject into the subprocess.
- _timeout:
The timeout value for this particular
run()
call. If this value is notNone
, it will be used instead oftimeout
, the default timeout.
- Parameters:
args (str) –
env (EnvironDict | None) –
kwargs (Any) –
- Return type:
- run_start_checks(started_at, timeout_at)#
Run checks to confirm that the daemon has started.
- start(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)#
Start the daemon.
- start_check(callback, *args, **kwargs)#
Register a function to run after the daemon starts to confirm readiness for work.
The callback must accept as the first argument
timeout_at
which is a float. The callback must stop trying to confirm running behavior oncetime.time() > timeout_at
. The callback should returnTrue
to confirm that the daemon is ready for work.- Arguments:
- callback:
The function to call back
- Keyword Arguments:
- args:
The arguments to pass to the callback
- kwargs:
The keyword arguments to pass to the callback
- Returns:
Nothing.
- Example:
def check_running_state(timeout_at: float) -> bool: while time.time() <= timeout_at: # run some checks ... # if all is good break else: return False return True
- started(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)#
Start the daemon and return it’s instance so it can be used as a context manager.
- stopped(before_stop_callback=None, after_stop_callback=None, before_start_callback=None, after_start_callback=None)#
Stop the daemon and return it’s instance so it can be used as a context manager.
- Keyword Arguments:
- before_stop_callback:
A callable to run before stopping the daemon. The callback must accept one argument, the daemon instance.
- after_stop_callback:
A callable to run after stopping the daemon. The callback must accept one argument, the daemon instance.
- before_start_callback:
A callable to run before starting the daemon. The callback must accept one argument, the daemon instance.
- after_start_callback:
A callable to run after starting the daemon. The callback must accept one argument, the daemon instance.
This context manager will stop the factory while the context is in place, it re-starts it once out of context.
- Example:
assert factory.is_running() is True with factory.stopped(): assert factory.is_running() is False assert factory.is_running() is True
- terminate()#
Terminate the started subprocess.
- Return type:
- classmethod verify_config(config)#
Verify the configuration dictionary.
- classmethod write_config(config)#
Write the configuration to file.