]> git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/ifupdownaddons/dhclient.py
Fixed new file addition breakage with 0b762139
[mirror_ifupdown2.git] / ifupdown2 / ifupdownaddons / dhclient.py
1 #!/usr/bin/python
2 #
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
5 #
6
7 from utilsbase import *
8 import subprocess
9 import os
10
11 FNULL = open(os.devnull, 'w')
12
13 class dhclient(utilsBase):
14 """ This class contains helper methods to interact with the dhclient
15 utility """
16
17 def _pid_exists(self, pidfilename):
18 if os.path.exists(pidfilename):
19 pid = self.read_file_oneline(pidfilename)
20 if not os.path.exists('/proc/%s' %pid):
21 return False
22 else:
23 return False
24 return True
25
26 def is_running(self, ifacename):
27 return self._pid_exists('/run/dhclient.%s.pid' %ifacename)
28
29 def is_running6(self, ifacename):
30 return self._pid_exists('/run/dhclient6.%s.pid' %ifacename)
31
32 def stop(self, ifacename):
33 if os.path.exists('/sbin/dhclient3'):
34 cmd = ['/sbin/dhclient3', '-x', '-pf',
35 '/run/dhclient.%s.pid' %ifacename, '-lf',
36 '/var/lib/dhcp3/dhclient.%s.leases' %ifacename,
37 '%s' %ifacename]
38 else:
39 cmd = ['/sbin/dhclient', '-x', '-pf',
40 '/run/dhclient.%s.pid' %ifacename,
41 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename,
42 '%s' %ifacename]
43 self.subprocess_check_call(cmd)
44
45 def start(self, ifacename):
46 if os.path.exists('/sbin/dhclient3'):
47 cmd = ['/sbin/dhclient3', '-pf',
48 '/run/dhclient.%s.pid' %ifacename,
49 '-lf', '/var/lib/dhcp3/dhclient.%s.leases' %ifacename,
50 '%s' %ifacename]
51 else:
52 cmd = ['/sbin/dhclient', '-pf', '/run/dhclient.%s.pid' %ifacename,
53 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename,
54 '%s' %ifacename]
55 self.subprocess_check_call(cmd)
56
57 def release(self, ifacename):
58 if os.path.exists('/sbin/dhclient3'):
59 cmd = ['/sbin/dhclient3', '-r', '-pf',
60 '/run/dhclient.%s.pid' %ifacename, '-lf',
61 '/var/lib/dhcp3/dhclient.%s.leases' %ifacename,
62 '%s' %ifacename]
63 else:
64 cmd = ['/sbin/dhclient', '-r', '-pf',
65 '/run/dhclient.%s.pid' %ifacename,
66 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename,
67 '%s' %ifacename]
68 self.subprocess_check_call(cmd)
69
70 def start6(self, ifacename):
71 self.subprocess_check_call(['dhclient', '-6', '-pf',
72 '/run/dhclient6.%s.pid' %ifacename, '-lf',
73 '/var/lib/dhcp/dhclient.%s.leases ' %ifacename,
74 '%s' %ifacename])
75
76 def stop6(self, ifacename):
77 self.subprocess_check_call(['dhclient', '-6', '-x', '-pf',
78 '/run/dhclient.%s.pid' %ifacename, '-lf',
79 '/var/lib/dhcp/dhclient.%s.leases ' %ifacename,
80 '%s' %ifacename])
81
82 def release6(self, ifacename):
83 self.subprocess_check_call(['dhclient', '-6', '-r', '-pf',
84 '/run/dhclient6.%s.pid' %ifacename, '-lf',
85 '/var/lib/dhcp/dhclient6.%s.leases' %ifacename,
86 '%s' %ifacename])