# $Id: zone.py 3572 2008-10-16 09:11:19Z hsaliak $ # # Copyright 2007 Platform Computing Inc # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # # import sys import string import time from kusu.genconfig import Report class thisReport(Report): def toolHelp(self): """toolHelp - This method provides the help screen for this particular plugin. All plugins must implement this method.""" print self.gettext("genconfig_Zone_Help") def runPlugin(self, pluginargs): """runPlugin - This method provides the database report for this plugin. All plugins must implement this method.""" _ = self.gettext # Test to see if the Installer node should be running DNS. dnsenabled = self.db.getAppglobals('InstallerServeDNS') if dnsenabled != '1': sys.exit(0) # Get the name of the primary installer primaryinst = self.db.getAppglobals('PrimaryInstaller') if not primaryinst: sys.stderr.write(_("genconfig_cannot_determine_primary_installer\n")) sys.exit(-1) # Get the DNS Zone served by the Installer dnszone = self.db.getAppglobals('DNSZone') if not dnszone: sys.stderr.write(_("genconfig_cannot_determine_DNS_zone\n")) sys.exit(-1) # Get the name of the primary mail server mailserv = self.db.getAppglobals('SMTPServer') if not mailserv: servesmtp = self.db.getAppglobals('InstallerServeSMTP') if servesmtp == 'True': mailserv = '%s.%s' % (primaryinst, dnszone) # Generate the file contents print "; " print "; Dynamically generated by: genconfig (Do not edit!)" print "; " print '; Zone file %s.zone for: %s' % (dnszone, dnszone) print '$TTL 2d ; 172800 secs default TTL for zone' print '@\t\tIN\tSOA\t%s.%s. root.%s. (' % (primaryinst, dnszone, dnszone) tmp = '%f' % time.time() serial = string.split(tmp, '.')[0] print '\t\t\t%s\t; Serial number' % serial print '\t\t\t4h\t; Refresh' print '\t\t\t15m\t; Update retry time' print '\t\t\t24h\t; Expiry time' print '\t\t\t1d\t; Minimum TTL' print '\t\t\t)' # Print out all the NS entries query = ('select nodes.name, nics.ip, networks.suffix from ' 'nodes, nics, networks ' 'where networks.netid=nics.netid and ' 'nodes.ngid=1 and nics.nid=nodes.nid and networks.usingdhcp=False') try: self.db.execute(query) except: sys.stderr.write(_("DB_Query_Error\n")) sys.exit(-1) data = self.db.fetchall() if data: for row in data: dnsname, ip, suffix = row outline = '\t\tIN\tNS\t%s' % dnsname if suffix and suffix != '': outline += '%s' % suffix outline += '.%s.' % dnszone print outline if mailserv != '': print '\t\tIN\tMX 50 %s.' % mailserv print '' # Print out all the available names query = ('select nodes.name,nics.ip, networks.suffix, nics.boot from ' 'nodes,nics,networks where nodes.nid=nics.nid and ' 'nics.netid=networks.netid and networks.usingdhcp=False order by nodes.name') try: self.db.execute(query) except: sys.stderr.write(_("DB_Query_Error\n")) sys.exit(-1) data = self.db.fetchall() if data: for row in data: dnsname, ip, suffix, boot = row outline = '%s%s\tIN\tA\t%s' % (dnsname, suffix, ip) print '%s' % outline if boot: # Add the short name as well outline = '%s\tIN\tA\t%s' % (dnsname, ip) print '%s' % outline