Skip to content

Instantly share code, notes, and snippets.

@moali87
Created July 21, 2015 16:14
Show Gist options
  • Save moali87/acbb8540172464eada0d to your computer and use it in GitHub Desktop.
Save moali87/acbb8540172464eada0d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import salt.config
import salt.cloud.CloudClient as client
import salt.loader
__opts__ salt.config.minion_config('/etc/salt/minion')
__grains__ = salt.loader.grains(__opts__)
minion_name = __grains__['id']
def CheckHighstate():
'''
This function gathers the grains uptime_minutes and assigns it to uptime_grain, if uptime_grain is more than 7 minutes,
it will destroy the instance given by instance name provided by grains ID.
'''
try:
uptime_grain = __grains__['uptime_minutes']
except Exception:
return False
if uptime_grain > 7:
client.destroy(names=[minion_name])
return minion_name
else:
print('Minion is not within the 7 minute target')
if __name__ = '__main__':
CheckHighstate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment