Beispiel #1
0
 def write_dhcp_lease(self,port,host,ip,mac):
     """
     Use DHCP's API to create a DHCP entry in the
     /var/lib/dhcpd/dhcpd.leases file
     #Code from http://svn.osgdc.org/browse/kusu/kusu
     # /trunk/src/kits/base/packages/kusu-base-installer/lib/kusu/nodefun.py?r=3025
     # FIXME: should use subprocess
     """
     if ip.find("/") != -1:
         return
     try:
         fromchild, tochild = popen2([self.settings.omshell_bin])
         tochild.write("port %s\n" % port)
         tochild.flush()
         tochild.write("connect\n")
         tochild.flush()
         tochild.write("new host\n")
         tochild.flush()
         tochild.write('set name = \"%s\"\n' % host)
         tochild.flush()
         tochild.write("set ip-address = %s\n" % ip)
         tochild.flush()
         tochild.write("set hardware-address = %s\n" % mac.lower())
         tochild.flush()
         tochild.write("set hardware-type = 1\n")
         tochild.flush()
         tochild.write("create\n")
         tochild.flush()
         tochild.close()
         fromchild.close()
     except IOError:
         # FIXME: just catch 32 (broken pipe) and show a warning
         pass
Beispiel #2
0
 def remove_dhcp_lease(self,port,host):
     """
     Use DHCP's API to delete a DHCP entry in
     the /var/lib/dhcpd/dhcpd.leases file
     """
     fromchild, tochild = popen2([self.settings.omshell_bin])
     try:
         tochild.write("port %s\n" % port)
         tochild.flush()
         tochild.write("connect\n")
         tochild.flush()
         tochild.write("new host\n")
         tochild.flush()
         tochild.write('set name = \"%s\"\n' % host)
         tochild.flush()
         tochild.write("open\n")   # opens register with host information
         tochild.flush()
         tochild.write("remove\n")
         tochild.flush()
         tochild.close()
         fromchild.close()
     except IOError:
         # FIXME: convert this to subprocess.
         # FIXME: catch specific errors only (32/broken pipe)
         pass