<s> RECORD_TYPES = [ '<STR_LIT:A>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> from boto . resultset import ResultSet <EOL> class ResourceRecordSets ( ResultSet ) : <EOL> ChangeResourceRecordSetsBody = """<STR_LIT>""" <EOL> ChangeXML = """<STR_LIT>""" <EOL> def __init__ ( self , connection = None , hosted_zone_id = None , comment = None ) : <EOL> self . connection = connection <EOL> self . hosted_zone_id = hosted_zone_id <EOL> self . comment = comment <EOL> self . changes = [ ] <EOL> self . next_record_name = None <EOL> self . next_record_type = None <EOL> ResultSet . __init__ ( self , [ ( '<STR_LIT>' , Record ) ] ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . hosted_zone_id <EOL> def add_change ( self , action , name , type , ttl = <NUM_LIT> , alias_hosted_zone_id = None , alias_dns_name = None ) : <EOL> """<STR_LIT>""" <EOL> change = Record ( name , type , ttl , alias_hosted_zone_id = alias_hosted_zone_id , alias_dns_name = alias_dns_name ) <EOL> self . changes . append ( [ action , change ] ) <EOL> return change <EOL> def to_xml ( self ) : <EOL> """<STR_LIT>""" <EOL> changesXML = "<STR_LIT>" <EOL> for change in self . changes : <EOL> changeParams = { "<STR_LIT:action>" : change [ <NUM_LIT:0> ] , "<STR_LIT>" : change [ <NUM_LIT:1> ] . to_xml ( ) } <EOL> changesXML += self . ChangeXML % changeParams <EOL> params = { "<STR_LIT>" : self . comment , "<STR_LIT>" : changesXML } <EOL> return self . ChangeResourceRecordSetsBody % params <EOL> def commit ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . connection : <EOL> import boto <EOL> self . connection = boto . connect_route53 ( ) <EOL> return self . connection . change_rrsets ( self . hosted_zone_id , self . to_xml ( ) ) <EOL> def endElement ( self , name , value , connection ) : <EOL> """<STR_LIT>""" <EOL> if name == '<STR_LIT>' : <EOL> self . next_record_name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . next_record_type = value <EOL> else : <EOL> return ResultSet . endElement ( self , name , value , connection ) <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> results = ResultSet . __iter__ ( self ) <EOL> while results : <EOL> for obj in results : <EOL> yield obj <EOL> if self . is_truncated : <EOL> self . is_truncated = False <EOL> results = self . connection . get_all_rrsets ( self . hosted_zone_id , name = self . next_record_name , type = self . next_record_type ) <EOL> else : <EOL> results = None <EOL> class Record ( object ) : <EOL> """<STR_LIT>""" <EOL> XMLBody = """<STR_LIT>""" <EOL> ResourceRecordsBody = """<STR_LIT>""" <EOL> ResourceRecordBody = """<STR_LIT>""" <EOL> AliasBody = """<STR_LIT>""" <EOL> def __init__ ( self , name = None , type = None , ttl = <NUM_LIT> , resource_records = None , alias_hosted_zone_id = None , alias_dns_name = None ) : <EOL> self . name = name <EOL> self . type = type <EOL> self . ttl = ttl <EOL> if resource_records == None : <EOL> resource_records = [ ] <EOL> self . resource_records = resource_records <EOL> self . alias_hosted_zone_id = alias_hosted_zone_id <EOL> self . alias_dns_name = alias_dns_name <EOL> def add_value ( self , value ) : <EOL> """<STR_LIT>""" <EOL> self . resource_records . append ( value ) <EOL> def set_alias ( self , alias_hosted_zone_id , alias_dns_name ) : <EOL> """<STR_LIT>""" <EOL> self . alias_hosted_zone_id = alias_hosted_zone_id <EOL> self . alias_dns_name = alias_dns_name <EOL> def to_xml ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . alias_hosted_zone_id != None and self . alias_dns_name != None : <EOL> body = self . AliasBody % ( self . alias_hosted_zone_id , self . alias_dns_name ) <EOL> else : <EOL> records = "<STR_LIT>" <EOL> for r in self . resource_records : <EOL> records += self . ResourceRecordBody % r <EOL> body = self . ResourceRecordsBody % { <EOL> "<STR_LIT>" : self . ttl , <EOL> "<STR_LIT>" : records , <EOL> } <EOL> params = { <EOL> "<STR_LIT:name>" : self . name , <EOL> "<STR_LIT:type>" : self . type , <EOL> "<STR_LIT:body>" : body , <EOL> } <EOL> return self . XMLBody % params <EOL> def to_print ( self ) : <EOL> if self . alias_hosted_zone_id != None and self . alias_dns_name != None : <EOL> return '<STR_LIT>' + self . alias_hosted_zone_id + '<STR_LIT:U+0020>' + self . alias_dns_name <EOL> else : <EOL> return "<STR_LIT:U+002C>" . join ( self . resource_records ) <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT:Name>' : <EOL> self . name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . type = value <EOL> elif name == '<STR_LIT>' : <EOL> self . ttl = value <EOL> elif name == '<STR_LIT>' : <EOL> self . resource_records . append ( value ) <EOL> elif name == '<STR_LIT>' : <EOL> self . alias_hosted_zone_id = value <EOL> elif name == '<STR_LIT>' : <EOL> self . alias_dns_name = value <EOL> def startElement ( self , name , attrs , connection ) : <EOL> return None </s>
