Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793841
show-local-states.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
show-local-states.py
View Options
#!/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
Details
Attached
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)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment