Page MenuHomeDevCentral

show-local-states.py
No OneTemporary

show-local-states.py

#!/usr/bin/env python3
# -------------------------------------------------------------
# Salt - Show local states
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Gets the list of states to run from the topfile,
# then gets their state data.
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
import json
import subprocess
# -------------------------------------------------------------
# Show state information
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def run_salt_command(command, *args):
full_command = ["salt-call", "--local", "--output=json", command, *args]
process = subprocess.run(full_command, capture_output=True, check=True)
return json.loads(process.stdout)
def get_states_from_top():
return run_salt_command("state.show_top")["local"]["base"]
def get_state(state):
try:
return run_salt_command("state.show_sls", state)["local"]
except subprocess.CalledProcessError:
return {}
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def run():
states = {state: get_state(state) for state in get_states_from_top()}
print(json.dumps(states))
if __name__ == "__main__":
run()

File Metadata

Mime Type
text/x-python
Expires
Fri, Feb 28, 22:47 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2436339
Default Alt Text
show-local-states.py (1 KB)

Event Timeline