Logo Search packages:      
Sourcecode: bcfg2 version File versions  Download package

def lib::Server::Plugins::Hostbase::buildDHCP (   self  ) 

Pre-build dhcpd.conf and stash in the filedata table

Definition at line 277 of file Hostbase.py.

00277                        :
        '''Pre-build dhcpd.conf and stash in the filedata table'''

        # fetches all the hosts with DHCP == True
        cursor = connection.cursor()
        SELECT hostname, mac_addr, ip_addr
        FROM (hostbase_host h INNER JOIN hostbase_interface i ON h.id = i.host_id)
        INNER JOIN hostbase_ip ip ON i.id = ip.interface_id
        WHERE i.dhcp=1 AND h.status='active' AND i.mac_addr <> ''
        AND i.mac_addr <> 'float' AND i.mac_addr <> 'unknown'
        ORDER BY h.hostname, i.mac_addr

        dhcphosts = cursor.fetchall()
        count = 0
        hosts = []
        hostdata = [dhcphosts[0][0], dhcphosts[0][1], dhcphosts[0][2]]
        if len(dhcphosts) > 1:
            for x in range(1, len(cursor.fetchall())):
                # if an interface has 2 or more ip addresses
                # adds the ip to the current interface
                if hostdata[0].split(".")[0] == dhcphosts[x][0].split(".")[0] and hostdata[1] == dhcphosts[x][1]:
                    hostdata[2] = ", ".join([hostdata[2], dhcphosts[x][2]])
                # if a host has 2 or more interfaces
                # writes the current one and grabs the next
                elif hostdata[0].split(".")[0] == dhcphosts[x][0].split(".")[0]:
                    count += 1
                    hostdata = ["-".join([dhcphosts[x][0], str(count)]), dhcphosts[x][1], dhcphosts[x][2]]
                # new host found, writes current data to the template
                    count = 0
                    hostdata = [dhcphosts[x][0], dhcphosts[x][1], dhcphosts[x][2]]
        #makes sure the last of the data gets written out
        if hostdata not in hosts:

        context = Context({
            'hosts': hosts,
            'numips': len(hosts),

        self.filedata['dhcpd.conf'] = self.templates['dhcp'].render(context)
        self.Entries['ConfigFile']['/etc/dhcp3/dhcpd.conf'] = self.FetchFile

    def buildHosts(self):

Generated by  Doxygen 1.6.0   Back to index