Esempio n. 1
0
class Nv2Route53(object):
    ''' Update Route53 with AWS hostnames in nventory. '''
    def __init__(self, options):
        self.options = options
        self.cmgr = ZambiConn()
        self.accounts = self.cmgr.get_accounts(self.options.aws_account)
        for self.account in self.accounts:
            self.dns = None
            self.update_records()
            if self.options.graphite:
                self.send_metrics()

    def send_metrics(self):
        ''' Send route53 metrics to graphite '''
        mpfx = 'business.aws.route53.%s' % self.account
        (creates, updates, count) = self.dns.get_metrics()
        grp = Graphite(server=self.options.graphite_server)
        grp.send_metric(mpfx + ".updates",
                       updates, self.options.debug)
        grp.send_metric(mpfx + ".creates",
                       creates, self.options.debug)
        grp.send_metric(mpfx + ".count",
                       count, self.options.debug)

    def update_records(self):
        ''' Run route53 updates based on nventory '''
        nvd = Nventory(ini_file=self.options.nv_ini)
        conn = self.cmgr.get_connection(self.account, service='route53')
        self.dns = HostedZone(conn, self.account, self.options.comment,
                              domain=self.options.domain)
        data = {
            'loc': '',
            'env': '',
            'sclass': '',
            'acct': self.account,
            'domain': self.options.domain}
        nodes = nvd.get_nodes(data)
        nvec2nodes = dict()
        for node in nodes:
            if node['name'] and node['ec2_instance_id']:
                nvec2nodes[node['name']] = {
                    'type': 'CNAME',
                    'ttl': self.options.ttl,
                    'resource': [node['ec2_public_hostname']]}
        if nvec2nodes:
            self.dns.add_update_records(
                nvec2nodes, record_type='CNAME', ttl=self.options.ttl)
        else:
            print 'INFO: No nodes found in external data source.'
Esempio n. 2
0
 def update_records(self):
     ''' Run route53 updates based on nventory '''
     nvd = Nventory(ini_file=self.options.nv_ini)
     conn = self.cmgr.get_connection(self.account, service='route53')
     self.dns = HostedZone(conn, self.account, self.options.comment,
                           domain=self.options.domain)
     data = {
         'loc': '',
         'env': '',
         'sclass': '',
         'acct': self.account,
         'domain': self.options.domain}
     nodes = nvd.get_nodes(data)
     nvec2nodes = dict()
     for node in nodes:
         if node['name'] and node['ec2_instance_id']:
             nvec2nodes[node['name']] = {
                 'type': 'CNAME',
                 'ttl': self.options.ttl,
                 'resource': [node['ec2_public_hostname']]}
     if nvec2nodes:
         self.dns.add_update_records(
             nvec2nodes, record_type='CNAME', ttl=self.options.ttl)
     else:
         print 'INFO: No nodes found in external data source.'