]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/ifupdownaddons/dhclient.py
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
7 from utilsbase
import *
11 FNULL
= open(os
.devnull
, 'w')
13 class dhclient(utilsBase
):
14 """ This class contains helper methods to interact with the dhclient
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
):
26 def is_running(self
, ifacename
):
27 return self
._pid
_exists
('/run/dhclient.%s.pid' %ifacename
)
29 def is_running6(self
, ifacename
):
30 return self
._pid
_exists
('/run/dhclient6.%s.pid' %ifacename
)
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
,
39 cmd
= ['/sbin/dhclient', '-x', '-pf',
40 '/run/dhclient.%s.pid' %ifacename
,
41 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename
,
43 self
.subprocess_check_call(cmd
)
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
,
52 cmd
= ['/sbin/dhclient', '-pf', '/run/dhclient.%s.pid' %ifacename
,
53 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename
,
55 self
.subprocess_check_call(cmd
)
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
,
64 cmd
= ['/sbin/dhclient', '-r', '-pf',
65 '/run/dhclient.%s.pid' %ifacename
,
66 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename
,
68 self
.subprocess_check_call(cmd
)
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
,
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
,
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
,