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

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

Makes the *-machine files

Definition at line 496 of file Hostbase.py.

00496                             :
        """Makes the *-machine files"""
        header = """###################################################################
#  This file lists hosts in the '%s' machine netgroup, it is
#  automatically generated. DO NOT EDIT THIS FILE!
#
#  Number of hosts in '%s' machine netgroup: %i
#\n\n"""

        cursor = connection.cursor()
        # fetches all the hosts that with valid netgroup entries
        cursor.execute("""
        SELECT h.hostname, n.name, h.netgroup, n.only FROM ((hostbase_host h
        INNER JOIN hostbase_interface i ON h.id = i.host_id)
        INNER JOIN hostbase_ip p ON i.id = p.interface_id)
        INNER JOIN hostbase_name n ON p.id = n.ip_id
        WHERE h.netgroup <> '' AND h.netgroup <> 'none' AND h.status = 'active'
        ORDER BY h.netgroup, h.hostname
        """)
        nameslist = cursor.fetchall()
        # gets the first host and initializes the hash
        hostdata = nameslist[0]
        netgroups = {hostdata[2]:[hostdata[0]]}
        for row in nameslist:
            # if new netgroup, create it
            if row[2] not in netgroups:
                netgroups.update({row[2]:[]})
            # if it belongs in the netgroup and has multiple interfaces, put them in
            if hostdata[0] == row[0] and row[3]:
                netgroups[row[2]].append(row[1])
                hostdata = row
            # if its a new host, write the old one to the hash
            elif hostdata[0] != row[0]:
                netgroups[row[2]].append(row[0])
                hostdata = row

        for netgroup in netgroups:
            fileoutput = header % (netgroup, netgroup, len(netgroups[netgroup]))
            for each in netgroups[netgroup]:
                fileoutput += each + "\n"
            self.filedata['%s-machines' % netgroup] = fileoutput
            self.Entries['ConfigFile']['%s-machines' % netgroup] = self.FetchFile

        cursor.execute("""
        UPDATE hostbase_host SET dirty=0
        """)
        """)


Generated by  Doxygen 1.6.0   Back to index