rpathsync / amiconfig

A extensible contextualization client for Amazon's EC2 instance data service.

Clone this repository (size: 127.3 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/rpathsync/amiconfig/
commit 131: 9be38b1b6ba4
parent 130: 494b215035fe
branch: default
cfg does not need to be an instance var
Elliot Peele
2 years ago

Changed (Δ70 bytes):

raw changeset »

amiconfig/plugins/dnsupdate.py (13 lines added, 13 lines removed)

Up to file-list amiconfig/plugins/dnsupdate.py:

@@ -17,11 +17,11 @@ class AMIConfigPlugin(AMIPlugin):
17
17
    def configure(self):
18
18
        try:
19
19
            # NOTE: This method forces all variable names to be lower case
20
            self.cfg = self.ud.getSection('dnsupdate')
20
            cfg = self.ud.getSection('dnsupdate')
21
21
        except EC2DataRetrievalError:
22
22
            return
23
23
        for key in ('tsighost', 'tsigkey', 'host', 'domain', 'server'):
24
            if key not in self.cfg:
24
            if key not in cfg:
25
25
                return
26
26
27
27
        instanceid = self.id.getInstanceId()
@@ -37,27 +37,27 @@ class AMIConfigPlugin(AMIPlugin):
37
37
            index = int(self.id.getAMILaunchIndex())
38
38
            start = int(cfg['start'])
39
39
            clusterid = '%02d' % (start + index)
40
            self.cfg['host'] = '%s%s' % (cfg['prefix'], clusterid)
40
            cfg['host'] = '%s%s' % (cfg['prefix'], clusterid)
41
41
42
42
        # Set keyring using TSIG variables from User Data
43
43
        keyring = dns.tsigkeyring.from_text({
44
            self.cfg['tsighost'] : self.cfg['tsigkey']
44
            cfg['tsighost'] : cfg['tsigkey']
45
45
        })
46
        update = dns.update.Update(self.cfg['domain'], keyring=keyring)
46
        update = dns.update.Update(cfg['domain'], keyring=keyring)
47
47
48
48
        # Clear all TXT and A entries for domain
49
        update.delete(self.cfg['host'], 'a')
50
        response = dns.query.tcp(update, self.cfg['server'])
51
        update.delete(self.cfg['host'], 'txt')
52
        response = dns.query.tcp(update, self.cfg['server'])
49
        update.delete(cfg['host'], 'a')
50
        response = dns.query.tcp(update, cfg['server'])
51
        update.delete(cfg['host'], 'txt')
52
        response = dns.query.tcp(update, cfg['server'])
53
53
54
54
        # Create A entry with public IP address
55
        update.add(self.cfg['host'], 300, 'a', ipaddr)
56
        response = dns.query.tcp(update, self.cfg['server'])
55
        update.add(cfg['host'], 300, 'a', ipaddr)
56
        response = dns.query.tcp(update, cfg['server'])
57
57
58
58
        # Create TXT entry with instanceID
59
        update.add(self.cfg['host'], 300, 'txt', instanceid)
60
        response = dns.query.tcp(update, self.cfg['server'])
59
        update.add(cfg['host'], 300, 'txt', instanceid)
60
        response = dns.query.tcp(update, cfg['server'])
61
61
62
62
        # Response checking code should live here
63
63