~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/route53/record.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2013-05-10 23:38:14 UTC
  • mfrom: (1.1.10) (14.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130510233814-701dvlop7xfh88i7
Tags: 2.9.2-1
New upstream release (Closes: #700743).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (c) 2010 Chris Moyer http://coredumped.org/
 
2
# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
 
3
# Copyright (c) 2012 Amazon.com, Inc. or its affiliates.
2
4
# All rights reserved.
3
5
#
4
6
# Permission is hereby granted, free of charge, to any person obtaining a
33
35
    """
34
36
 
35
37
    ChangeResourceRecordSetsBody = """<?xml version="1.0" encoding="UTF-8"?>
36
 
    <ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/">
 
38
    <ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2012-02-29/">
37
39
            <ChangeBatch>
38
40
                <Comment>%(comment)s</Comment>
39
41
                <Changes>%(changes)s</Changes>
55
57
        ResultSet.__init__(self, [('ResourceRecordSet', Record)])
56
58
 
57
59
    def __repr__(self):
58
 
        return '<ResourceRecordSets: %s>' % self.hosted_zone_id
 
60
        if self.changes:
 
61
            record_list = ','.join([c.__repr__() for c in self.changes])
 
62
        else:
 
63
            record_list = ','.join([record.__repr__() for record in self])
 
64
        return '<ResourceRecordSets:%s [%s]' % (self.hosted_zone_id,
 
65
                                                record_list)
59
66
 
60
67
    def add_change(self, action, name, type, ttl=600,
61
68
            alias_hosted_zone_id=None, alias_dns_name=None, identifier=None,
62
 
            weight=None):
 
69
            weight=None, region=None):
63
70
        """
64
71
        Add a change request to the set.
65
72
 
96
103
            Information about the domain to which you are redirecting traffic.
97
104
 
98
105
        :type identifier: str
99
 
        :param identifier: *Weighted resource record sets only* An
100
 
            identifier that differentiates among multiple resource
 
106
        :param identifier: *Weighted and latency-based resource record sets
 
107
            only* An identifier that differentiates among multiple resource
101
108
            record sets that have the same combination of DNS name and type.
102
109
 
103
110
        :type weight: int
105
112
            record sets that have the same combination of DNS name and type,
106
113
            a value that determines what portion of traffic for the current
107
114
            resource record set is routed to the associated location
 
115
 
 
116
        :type region: str
 
117
        :param region: *Latency-based resource record sets only* Among resource
 
118
            record sets that have the same combination of DNS name and type,
 
119
            a value that determines which region this should be associated with
 
120
            for the latency-based routing
108
121
        """
109
122
        change = Record(name, type, ttl,
110
123
                alias_hosted_zone_id=alias_hosted_zone_id,
111
124
                alias_dns_name=alias_dns_name, identifier=identifier,
112
 
                weight=weight)
 
125
                weight=weight, region=region)
113
126
        self.changes.append([action, change])
114
127
        return change
115
128
 
 
129
    def add_change_record(self, action, change):
 
130
        """Add an existing record to a change set with the specified action"""
 
131
        self.changes.append([action, change])
 
132
        return
 
133
 
116
134
    def to_xml(self):
117
135
        """Convert this ResourceRecordSet into XML
118
136
        to be saved via the ChangeResourceRecordSetsRequest"""
169
187
        <Weight>%(weight)s</Weight>
170
188
    """
171
189
 
 
190
    RRRBody = """
 
191
        <SetIdentifier>%(identifier)s</SetIdentifier>
 
192
        <Region>%(region)s</Region>
 
193
    """
 
194
 
172
195
    ResourceRecordsBody = """
173
196
        <TTL>%(ttl)s</TTL>
174
197
        <ResourceRecords>
188
211
 
189
212
    def __init__(self, name=None, type=None, ttl=600, resource_records=None,
190
213
            alias_hosted_zone_id=None, alias_dns_name=None, identifier=None,
191
 
            weight=None):
 
214
            weight=None, region=None):
192
215
        self.name = name
193
216
        self.type = type
194
217
        self.ttl = ttl
199
222
        self.alias_dns_name = alias_dns_name
200
223
        self.identifier = identifier
201
224
        self.weight = weight
 
225
        self.region = region
 
226
 
 
227
    def __repr__(self):
 
228
        return '<Record:%s:%s:%s>' % (self.name, self.type, self.to_print())
202
229
 
203
230
    def add_value(self, value):
204
231
        """Add a resource record value"""
227
254
        if self.identifier != None and self.weight != None:
228
255
            weight = self.WRRBody % {"identifier": self.identifier, "weight":
229
256
                    self.weight}
 
257
        elif self.identifier != None and self.region != None:
 
258
            weight = self.RRRBody % {"identifier": self.identifier, "region":
 
259
                    self.region}
 
260
        
230
261
        params = {
231
262
            "name": self.name,
232
263
            "type": self.type,
246
277
 
247
278
        if self.identifier != None and self.weight != None:
248
279
            rr += ' (WRR id=%s, w=%s)' % (self.identifier, self.weight)
 
280
        elif self.identifier != None and self.region != None:
 
281
            rr += ' (LBR id=%s, region=%s)' % (self.identifier, self.region)
249
282
 
250
283
        return rr
251
284
 
266
299
            self.identifier = value
267
300
        elif name == 'Weight':
268
301
            self.weight = value
 
302
        elif name == 'Region':
 
303
            self.region = value
269
304
 
270
305
    def startElement(self, name, attrs, connection):
271
306
        return None