Created
July 21, 2015 19:15
-
-
Save moali87/0fe18520bbd4e50e2600 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
''' | |
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. | |
''' | |
import salt.cloud.CloudClient as client | |
def __virtual__(): | |
''' | |
Only for machines running more than 7 minutes | |
''' | |
# return 'checkhighstate' if __grains__['uptime_minutes'] > 7 else False | |
if __grains__['uptime_minutes'] < 7: | |
return 'False' | |
return 'checkhighstate' | |
def DestroyInstance(): | |
''' | |
Destroy minion if __virtual__ is True | |
CLI Example:: | |
salt '*' checkhighstate.destroy | |
''' | |
module_name = __grains__['id'] | |
out = client.destroy(names=[minion_name]) | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment