Page MenuHomeDevCentral

D2555.id6456.diff
No OneTemporary

D2555.id6456.diff

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,52 @@
-all: generate-webcontent-index
+# -------------------------------------------------------------
+# Salt - Operations repository
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Allow to generate repository or API content
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
-generate-webcontent-index:
+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
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+_default: repo
+
+all: repo api
+
+clean: clean-repo clean-api
+
+# -------------------------------------------------------------
+# Build targets - repository
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+repo: roles/webserver-content/init.sls
+
+roles/webserver-content/init.sls:
tmpfile=`mktemp /tmp/make-rOPS-generate-webcontent-index.XXXXXX` ; \
utils/generate-webcontent-index.py > "$$tmpfile" ;\
- mv "$$tmpfile" roles/webserver-content/init.sls
+ ${MV} "$$tmpfile" roles/webserver-content/init.sls
+
+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
Mon, Nov 18, 19:00 (6 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2250994
Default Alt Text
D2555.id6456.diff (3 KB)

Event Timeline