# $Id: resolv.py 873 2008-02-25 20:49:32Z mblack $ # # 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 # # from kusu.genconfig import Report import sys import string 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_Resolv_Help") def runPlugin(self, pluginargs): """runPlugin - This method provides the database report for this plugin. All plugins must implement this method.""" # What type of file should we generate type = 'master' if pluginargs: if pluginargs[0] == 'client': type = 'client' # Test to see if the Installer node should be running DNS. dnsenabled = 0 data = self.db.getAppglobals('InstallerServeDNS') if data != '0': dnsenabled = 1 _ = self.gettext # Get the DNS data dnszone = self.db.getAppglobals('DNSZone') if not dnszone: # No local DNS zone. dnszone = '' publicdns = self.db.getAppglobals('PublicDNSZone') if not publicdns: # No public DNS zone. publicdns = '' dnssearch = self.db.getAppglobals('DNSSearch') if not dnssearch: # No DNS search list. dnssearch = '' # Get a list of installers IPs. These will be DNS primary/slave servers serverIPs = [] query = ('select nics.ip from nics,nodes where ' 'nics.nid=nodes.nid ' 'and nodes.ngid=1') 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: serverIPs.append(row[0]) search = '' if dnszone: search += ' %s' % dnszone if publicdns: search += ' %s' % publicdns if dnssearch: search += ' %s' % dnssearch print "#" print "# Dynamically generated by: genconfig (Do not edit!)" print "# Type = %s\n" % type if search: print 'search%s\n' % search if type == 'master': # Generate the DNS config file for an Installer node if dnsenabled == 1: print "# Local DNS enabled." print "nameserver 127.0.0.1" else: print "# No local DNS server!" dns1 = self.db.getAppglobals('dns1') if dns1: print "nameserver %s" % dns1 dns2 = self.db.getAppglobals('dns2') if dns2: print "nameserver %s" % dns2 dns3 = self.db.getAppglobals('dns3') if dns3: print "nameserver %s" % dns3 else: # Generate a DNS config file for a slave node if dnsenabled == 1: print "# Installer DNS enabled." for ip in serverIPs: print "nameserver %s" % ip else: print "# No Installer DNS server." dns1 = self.db.getAppglobals('dns1') if dns1: print "nameserver %s" % dns1 dns2 = self.db.getAppglobals('dns2') if dns2: print "nameserver %s" % dns2 dns3 = self.db.getAppglobals('dns3') if dns3: print "nameserver %s" % dns3 print ""