Subversion Repositories DevTools

Rev

Rev 5808 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5808 Rev 5809
Line 11... Line 11...
11
 
11
 
12
#debug setting for dry-run
12
#debug setting for dry-run
13
#IS_DRY_RUN = True
13
#IS_DRY_RUN = True
14
IS_DRY_RUN = False
14
IS_DRY_RUN = False
15
 
15
 
-
 
16
#tagging start and stop times is used to prevent starting / stopping instances 
-
 
17
#multiple times an hour, but it can be turned off to reduce number of tags used 
-
 
18
#by script if you don't think this is an issue (eg script only runs once an hour)
-
 
19
#TAG_START_STOP_TIMES = False
-
 
20
TAG_START_STOP_TIMES = True
-
 
21
 
16
###################################################################################
22
###################################################################################
17
# Shoudn't need to modify anything below here
23
# Shoudn't need to modify anything below here
18
###################################################################################
24
###################################################################################
19
 
25
 
20
#State Code Constants
26
#State Code Constants
Line 85... Line 91...
85
        stop_hour_gmt = getSetTag(instance, 'STOP_HOUR_GMT', DEFAULT_STOP_GMT)
91
        stop_hour_gmt = getSetTag(instance, 'STOP_HOUR_GMT', DEFAULT_STOP_GMT)
86
        action_days = getSetTag(instance, 'ACTION_DAYS', DEFAULT_WEEKDAY_ACTION)
92
        action_days = getSetTag(instance, 'ACTION_DAYS', DEFAULT_WEEKDAY_ACTION)
87
 
93
 
88
        no_boot_until_time = getTimeFromInstance(instance, 'NO_BOOT_UNTIL', DEFAULT_NO_BOOT_TIME, TAG_DATE_TIME_FORMAT)
94
        no_boot_until_time = getTimeFromInstance(instance, 'NO_BOOT_UNTIL', DEFAULT_NO_BOOT_TIME, TAG_DATE_TIME_FORMAT)
89
        no_kill_until_time = getTimeFromInstance(instance, 'NO_KILL_UNTIL', DEFAULT_NO_KILL_TIME, TAG_DATE_TIME_FORMAT)
95
        no_kill_until_time = getTimeFromInstance(instance, 'NO_KILL_UNTIL', DEFAULT_NO_KILL_TIME, TAG_DATE_TIME_FORMAT)
-
 
96
        
-
 
97
        if ( TAG_START_STOP_TIMES ):
90
        last_auto_start_time = getTimeFromInstance(instance, 'LAST_AUTO_START', DEFAULT_AUTO_TIME, TODAY_HOUR_DT_FORMAT) 
98
            last_auto_start_time = getTimeFromInstance(instance, 'LAST_AUTO_START', DEFAULT_AUTO_TIME, TODAY_HOUR_DT_FORMAT) 
91
        last_auto_stop_time = getTimeFromInstance(instance, 'LAST_AUTO_STOP', DEFAULT_AUTO_TIME, TODAY_HOUR_DT_FORMAT)
99
            last_auto_stop_time = getTimeFromInstance(instance, 'LAST_AUTO_STOP', DEFAULT_AUTO_TIME, TODAY_HOUR_DT_FORMAT)
92
 
100
 
93
        action_taken = "Do Nothing"
101
        action_taken = "Do Nothing"
94
        try: 
102
        try: 
95
            if ( int(start_hour_gmt) == int(stop_hour_gmt) ):
103
            if ( int(start_hour_gmt) == int(stop_hour_gmt) ):
96
                action_taken = "Not modifying - Start (" + start_hour_gmt + ") and stop (" \
104
                action_taken = "Not modifying - Start (" + start_hour_gmt + ") and stop (" \
Line 204... Line 212...
204
        action_taken = "Starting - no action already running"
212
        action_taken = "Starting - no action already running"
205
    elif ( state_code == STATE_STOPPED ):
213
    elif ( state_code == STATE_STOPPED ):
206
        action_taken = "Starting instance"
214
        action_taken = "Starting instance"
207
        try:
215
        try:
208
            conn.start_instances(instance_ids=instance.id, dry_run=IS_DRY_RUN)
216
            conn.start_instances(instance_ids=instance.id, dry_run=IS_DRY_RUN)
-
 
217
            if ( TAG_START_STOP_TIMES ):
209
            #tag the instance so we don't potentially attempt to start it again this hour
218
                #tag the instance so we don't potentially attempt to start it again this hour
210
            instance.add_tag('LAST_AUTO_START', this_hour_str)
219
                instance.add_tag('LAST_AUTO_START', this_hour_str)
211
        except boto.exception.EC2ResponseError, e:
220
        except boto.exception.EC2ResponseError, e:
212
            print "Except while starting -", e
221
            print "Except while starting -", e
213
        #TODO start the instance and poss set elastip ip
222
        #TODO start the instance and poss set elastip ip
214
    else:
223
    else:
215
        action_taken = "Starting - ERROR state_code"
224
        action_taken = "Starting - ERROR state_code"
Line 230... Line 239...
230
        action_taken = "Stopping - no action already shutting/shutdown"
239
        action_taken = "Stopping - no action already shutting/shutdown"
231
    elif ( state_code == STATE_RUNNING ):
240
    elif ( state_code == STATE_RUNNING ):
232
        action_taken = "Stopping instance"
241
        action_taken = "Stopping instance"
233
        try:
242
        try:
234
            conn.stop_instances(instance_ids=instance.id, dry_run=IS_DRY_RUN)
243
            conn.stop_instances(instance_ids=instance.id, dry_run=IS_DRY_RUN)
-
 
244
            if ( TAG_START_STOP_TIMES ):
235
            #tag the instance so we don't potentially attempt to stop it again this hour
245
                #tag the instance so we don't potentially attempt to stop it again this hour
236
            instance.add_tag('LAST_AUTO_STOP', this_hour_str)
246
                instance.add_tag('LAST_AUTO_STOP', this_hour_str)
237
        except boto.exception.EC2ResponseError, e:
247
        except boto.exception.EC2ResponseError, e:
238
            print "Except while stopping -", e
248
            print "Except while stopping -", e
239
    else:
249
    else:
240
        action_taken = "Stopping - ERROR state_code"
250
        action_taken = "Stopping - ERROR state_code"
241
 
251