<s> import yaml <EOL> import requests <EOL> import boto . route53 <EOL> from boto . route53 . record import ResourceRecordSets <EOL> CONFIG_FILE = "<STR_LIT>" <EOL> METADATA_URL = "<STR_LIT>" <EOL> def get_info ( config_file = CONFIG_FILE ) : <EOL> try : <EOL> contents = open ( config_file , '<STR_LIT:r>' ) . read ( ) <EOL> info_dict = yaml . load ( contents ) <EOL> except Exception , e : <EOL> print "<STR_LIT>" % config_file <EOL> print "<STR_LIT>" % e <EOL> raise <EOL> return info_dict <EOL> def get_ec2_dns ( ) : <EOL> content = None <EOL> try : <EOL> url = METADATA_URL + "<STR_LIT>" <EOL> r = requests . get ( url ) <EOL> content = r . content <EOL> except : <EOL> raise <EOL> return content <EOL> def update_template ( template_string , sm_dns_name , aws_dns_name ) : <EOL> str2 = rrset_template . replace ( "<STR_LIT>" , sm_dns_name ) <EOL> str3 = str2 . replace ( "<STR_LIT>" , aws_dns_name ) <EOL> newstr1 = template_string . replace ( "<STR_LIT>" , sm_dns_name ) <EOL> newstr2 = newstr1 . replace ( "<STR_LIT>" , aws_dns_name ) <EOL> return newstr2 <EOL> rrset_template = '''<STR_LIT>''' <EOL> def get_route53_connection ( region ) : <EOL> conn = None <EOL> try : <EOL> conn = boto . route53 . connect_to_region ( region ) <EOL> except Exception , e : <EOL> print "<STR_LIT>" % e <EOL> return conn <EOL> def update_dns_cname_record ( conn , zone_id , cname_record , cname_value ) : <EOL> result = None <EOL> try : <EOL> changes = ResourceRecordSets ( conn , zone_id ) <EOL> change = changes . add_change ( "<STR_LIT>" , cname_record , "<STR_LIT>" , <NUM_LIT> ) <EOL> change . add_value ( cname_value ) <EOL> result = changes . commit ( ) <EOL> except Exception , e : <EOL> print "<STR_LIT>" % e <EOL> return result <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> info_dict = get_info ( ) <EOL> region = info_dict . get ( '<STR_LIT>' , None ) <EOL> print "<STR_LIT>" % region <EOL> sm_dns_name = info_dict . get ( '<STR_LIT>' , None ) <EOL> print "<STR_LIT>" % sm_dns_name <EOL> aws_dns_name = get_ec2_dns ( ) <EOL> print "<STR_LIT>" % aws_dns_name <EOL> hosted_zone_id = info_dict . get ( '<STR_LIT>' , None ) <EOL> print "<STR_LIT>" % hosted_zone_id <EOL> print <EOL> conn = get_route53_connection ( region ) <EOL> result = update_dns_cname_record ( conn , hosted_zone_id , sm_dns_name , aws_dns_name ) <EOL> print result </s>
