Page MenuHomeDevCentral

D2555.diff
No OneTemporary

D2555.diff

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -2,20 +2,27 @@
# Salt - Operations repository
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
-# Description: Allow to generate repository content
+# Description: Allow to generate repository or API content
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
+HOST_NAME != hostname -s
+HOST_DOMAIN != hostname -d
+API_DIR=/var/wwwroot/$(HOST_DOMAIN)/$(HOST_NAME)/datasources/infra
+
RM=rm -f
+MKDIR=mkdir -p
MV=mv
# -------------------------------------------------------------
# Main targets
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-all: repo
+_default: repo
+
+all: repo api
-clean: clean-repo
+clean: clean-repo clean-api
# -------------------------------------------------------------
# Build targets - repository
@@ -30,3 +37,16 @@
clean-repo:
${RM} roles/webserver-content/init.sls
+
+# -------------------------------------------------------------
+# Build targets - API
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+api: $(API_DIR)/all-states.json
+
+$(API_DIR)/all-states.json:
+ ${MKDIR} ${API_DIR}
+ utils/show-local-states.py > ${API_DIR}/all-states.json
+
+clean-api:
+ ${RM} ${API_DIR}/all-states.json
diff --git a/utils/show-local-states.py b/utils/show-local-states.py
new file mode 100755
--- /dev/null
+++ b/utils/show-local-states.py
@@ -0,0 +1,51 @@
+#!/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/plain
Expires
Thu, Dec 19, 23:48 (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2307041
Default Alt Text
D2555.diff (2 KB)

Event Timeline