-
-
Save rikonor/39d5c7a21be3de93c1b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import json | |
from minion_metadata import minion_metadata | |
def cluster_metadata(): | |
''' | |
main_ip - the private_ip of the main machine with same idx as this machine | |
main_ips - the private_ips of all main machines | |
''' | |
def get_ips(query): | |
main_ip = subprocess.check_output( | |
["salt-call", "mine.get", query_main_ip, "private_ip", "expr_form=compound", "--output=json"] | |
) | |
main_ip = json.loads(main_ip)['data'].values() | |
return main_ip | |
mmd = minion_metadata() | |
query_main_ip = "'G@env:{} and G@role:main and G@idx:{}'".format(mmd['env'], mmd['idx']) | |
query_main_ips = "'G@env:{} and G@role:main'".format(mmd['env']) | |
return { | |
'main_ip': get_ips(query_main_ip)[0], | |
'main_ips': get_ips(query_main_ips) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The above custom grain causes non-stop calls to: | |
/usr/bin/python /usr/bin/salt-call mine.get "<query>" private_ip expr_form=compound --output=json | |
I would expect/hope that when the grain is executed the mine.get call will also be executed only once. | |
Does the mine.get itself invoke a refresh of the grains? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment