<s> import logging <EOL> import time <EOL> from boto . exception import BotoServerError <EOL> from multiprocessing import Process <EOL> from django . core . management import setup_environ <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def make_django_maintenance_announcement ( rds_provisioner , retries_remaining = <NUM_LIT:3> ) : <EOL> """<STR_LIT>""" <EOL> seed_instance = rds_provisioner . seed_node . boto_instance <EOL> security_group = seed_instance . security_group <EOL> ip = rds_provisioner . get_ip ( ) <EOL> cidr = "<STR_LIT>" % ip <EOL> try : <EOL> security_group . authorize ( cidr_ip = cidr ) <EOL> except BotoServerError : <EOL> pass <EOL> import pstat . settings as settings <EOL> process_kwargs = { <EOL> '<STR_LIT>' : settings , <EOL> '<STR_LIT>' : seed_instance , <EOL> '<STR_LIT>' : rds_provisioner . seed_master_password , <EOL> } <EOL> make_announcement_p = Process ( <EOL> target = _make_django_maintenance_announcement , <EOL> kwargs = process_kwargs , <EOL> ) <EOL> make_announcement_p . start ( ) <EOL> make_announcement_p . join ( ) <EOL> if make_announcement_p . exitcode != <NUM_LIT:0> : <EOL> if retries_remaining > <NUM_LIT:0> : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> logger . warning ( "<STR_LIT>" , retries_remaining ) <EOL> return rds_provisioner . make_maintenance_announcement ( <EOL> retries_remaining = retries_remaining - <NUM_LIT:1> ) <EOL> else : <EOL> logger . critical ( "<STR_LIT>" ) <EOL> logger . critical ( "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> security_group . revoke ( cidr_ip = cidr ) <EOL> def _make_django_maintenance_announcement ( <EOL> settings , seed_instance , seed_master_password , <EOL> ) : <EOL> """<STR_LIT>""" <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> host , port = seed_instance . endpoint <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = host <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = port <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = seed_instance . master_username <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = seed_master_password <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> setup_environ ( settings ) <EOL> from announcements . models import Announcement <EOL> from django . contrib . auth . models import User <EOL> if Announcement . objects . count ( ) == <NUM_LIT:0> : <EOL> admin = User . objects . filter ( is_superuser = True ) . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> Announcement . objects . create ( <EOL> title = "<STR_LIT>" , <EOL> content = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) , <EOL> creator = admin , <EOL> site_wide = True ) <EOL> count = Announcement . objects . all ( ) . count ( ) <EOL> if count != <NUM_LIT:1> : <EOL> exit ( <NUM_LIT:1> ) <EOL> exit ( <NUM_LIT:0> ) <EOL> def verify_django_maintenance_announcement ( <EOL> rds_deployer , node , retries_remaining = <NUM_LIT:3> , <EOL> ) : <EOL> """<STR_LIT>""" <EOL> rds_instance = node . boto_instance <EOL> conf = rds_deployer . deployment . deployment_confs [ <EOL> '<STR_LIT>' <EOL> ] [ rds_deployer . node_name ] [ '<STR_LIT>' ] <EOL> security_group = rds_instance . security_group <EOL> ip = rds_deployer . get_ip ( ) <EOL> cidr = "<STR_LIT>" % ip <EOL> try : <EOL> security_group . authorize ( cidr_ip = cidr ) <EOL> except BotoServerError : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> import pstat . settings as settings <EOL> process_kwargs = { <EOL> '<STR_LIT>' : settings , <EOL> '<STR_LIT>' : rds_instance , <EOL> '<STR_LIT>' : conf [ '<STR_LIT>' ] , <EOL> } <EOL> verify_announcement_p = Process ( <EOL> target = _verify_django_maintenance_announcement , <EOL> kwargs = process_kwargs , <EOL> ) <EOL> verify_announcement_p . start ( ) <EOL> verify_announcement_p . join ( ) <EOL> if verify_announcement_p . exitcode != <NUM_LIT:0> : <EOL> if retries_remaining > <NUM_LIT:0> : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> logger . warning ( "<STR_LIT>" , retries_remaining ) <EOL> return rds_deployer . verify_seed_data ( <EOL> node , retries_remaining = retries_remaining - <NUM_LIT:1> ) <EOL> else : <EOL> logger . critical ( "<STR_LIT>" ) <EOL> logger . critical ( "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> try : <EOL> security_group . revoke ( cidr_ip = cidr ) <EOL> except BotoServerError : <EOL> pass <EOL> def _verify_django_maintenance_announcement ( <EOL> settings , rds_instance , master_password , <EOL> ) : <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> host , port = rds_instance . endpoint <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = host <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = port <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = rds_instance . master_username <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = master_password <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> setup_environ ( settings ) <EOL> from announcements . models import Announcement <EOL> from MySQLdb import OperationalError <EOL> from django . db import connection <EOL> try : <EOL> if Announcement . objects . count ( ) == <NUM_LIT:0> : <EOL> logger . critical ( "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> except OperationalError , e : <EOL> logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> logger . warning ( "<STR_LIT>" , e ) <EOL> connection . connection . close ( ) <EOL> connection . connection = None <EOL> time . sleep ( <NUM_LIT:30> ) <EOL> if Announcement . objects . count ( ) == <NUM_LIT:0> : <EOL> logger . critical ( "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:1> ) <EOL> Announcement . objects . all ( ) . delete ( ) <EOL> exit ( <NUM_LIT:0> ) </s>
