def updatectrlifhosts(self, netidx=0, remove=False):
        ''' Add the IP addresses of control interfaces to the /etc/hosts file.
        '''
        if not self.getcfgitembool('update_etc_hosts', False):
            return

        try:
            ctrlnet = self.getctrlnetobj(netidx)
        except KeyError:
            return
        header = "CORE session %s host entries" % self.sessionid
        if remove:
            if self.getcfgitembool('verbose', False):
                self.info("Removing /etc/hosts file entries.")
            filedemunge('/etc/hosts', header)
            return
        entries = []
        for ifc in ctrlnet.netifs():
            name = ifc.node.name
            for addr in ifc.addrlist:
                entries.append("%s %s" % (addr.split('/')[0], ifc.node.name))
        if self.getcfgitembool('verbose', False):
            self.info("Adding %d /etc/hosts file entries." % len(entries))
        filemunge('/etc/hosts', header, '\n'.join(entries) + '\n')
Beispiel #2
0
 def updatectrlifhosts(self, remove=False):
     ''' Add the IP addresses of control interfaces to the /etc/hosts file.
     '''
     if not self.getcfgitembool('update_etc_hosts', False):
         return
     id = "ctrlnet"
     try:
         ctrlnet = self.obj(id)
     except KeyError:
         return
     header = "CORE session %s host entries" % self.sessionid
     if remove:
         if self.getcfgitembool('verbose', False):
             self.info("Removing /etc/hosts file entries.")
         filedemunge('/etc/hosts', header)
         return
     entries = []
     for ifc in ctrlnet.netifs():
         name = ifc.node.name
         for addr in ifc.addrlist:
             entries.append("%s %s" % (addr.split('/')[0], ifc.node.name))
     if self.getcfgitembool('verbose', False):
         self.info("Adding %d /etc/hosts file entries." % len(entries))
     filemunge('/etc/hosts', header, '\n'.join(entries) + '\n')