Extracting common code to trellis library
Change-Id: Iaa3170bb7679a273473bb3459082121e465907ea
diff --git a/trellis/trellis_remote_dhcp.py b/trellis/trellis_remote_dhcp.py
index 73bc8f3..606935e 100755
--- a/trellis/trellis_remote_dhcp.py
+++ b/trellis/trellis_remote_dhcp.py
@@ -11,6 +11,7 @@
from ipaddress import ip_network
from routinglib import BgpRouter
from routinglib import RoutedHost
+from trellislib import DhcpClient, DhcpServer
class Trellis( Topo ):
"Trellis basic topology"
@@ -100,35 +101,6 @@
topos = { 'trellis' : Trellis }
-class DhcpClient(Host):
- def __init__(self, name, *args, **kwargs):
- super(DhcpClient, self).__init__(name, **kwargs)
- self.pidFile = '/run/dhclient-%s.pid' % self.name
-
- def config(self, **kwargs):
- super(DhcpClient, self).config(**kwargs)
- self.cmd('ip addr flush dev %s' % self.defaultIntf())
- self.cmd('dhclient -q -4 -nw -pf %s %s' % (self.pidFile, self.defaultIntf()))
-
- def terminate(self, **kwargs):
- self.cmd('kill -9 `cat %s`' % self.pidFile)
- self.cmd('rm -rf %s' % self.pidFile)
- super(DhcpClient, self).terminate()
-
-class DhcpServer(RoutedHost):
- binFile = '/usr/sbin/dhcpd'
- pidFile = '/run/dhcp-server/dhcpd.pid'
- configFile = './dhcpd.conf'
-
- def config(self, **kwargs):
- super(DhcpServer, self).config(**kwargs)
- self.cmd('%s -q -4 -pf %s -cf %s %s' % (self.binFile, self.pidFile, self.configFile, self.defaultIntf()))
-
- def terminate(self, **kwargs):
- self.cmd('kill -9 `cat %s`' % self.pidFile)
- self.cmd('rm -rf %s' % self.pidFile)
- super(DhcpServer, self).terminate()
-
if __name__ == "__main__":
setLogLevel('debug')
topo = Trellis()