Skip to content

Instantly share code, notes, and snippets.

@rikonor
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikonor/39d5c7a21be3de93c1b2 to your computer and use it in GitHub Desktop.
Save rikonor/39d5c7a21be3de93c1b2 to your computer and use it in GitHub Desktop.
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)
}
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