]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdownaddons/dhclient.py
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
7 from ifupdown
.utils
import utils
8 from utilsbase
import *
12 class dhclient(utilsBase
):
13 """ This class contains helper methods to interact with the dhclient
16 def _pid_exists(self
, pidfilename
):
17 if os
.path
.exists(pidfilename
):
18 pid
= self
.read_file_oneline(pidfilename
)
19 if not os
.path
.exists('/proc/%s' %pid
):
25 def is_running(self
, ifacename
):
26 return self
._pid
_exists
('/run/dhclient.%s.pid' %ifacename
)
28 def is_running6(self
, ifacename
):
29 return self
._pid
_exists
('/run/dhclient6.%s.pid' %ifacename
)
31 def _run_dhclient_cmd(self
, cmd
, cmd_prefix
=None):
35 cmd_aslist
= cmd_prefix
.split()
37 cmd_aslist
.extend(cmd
)
40 utils
.exec_commandl(cmd_aslist
, stdout
=None, stderr
=None)
42 def stop(self
, ifacename
, cmd_prefix
=None):
43 if os
.path
.exists('/sbin/dhclient3'):
44 cmd
= ['/sbin/dhclient3', '-x', '-pf',
45 '/run/dhclient.%s.pid' %ifacename
, '-lf',
46 '/var/lib/dhcp3/dhclient.%s.leases' %ifacename
,
49 cmd
= ['/sbin/dhclient', '-x', '-pf',
50 '/run/dhclient.%s.pid' %ifacename
,
51 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename
,
53 self
._run
_dhclient
_cmd
(cmd
, cmd_prefix
)
55 def start(self
, ifacename
, wait
=True, cmd_prefix
=None):
56 if os
.path
.exists('/sbin/dhclient3'):
57 cmd
= ['/sbin/dhclient3', '-pf',
58 '/run/dhclient.%s.pid' %ifacename
,
59 '-lf', '/var/lib/dhcp3/dhclient.%s.leases' %ifacename
,
62 cmd
= ['/sbin/dhclient', '-pf',
63 '/run/dhclient.%s.pid' %ifacename
, '-lf',
64 '/var/lib/dhcp/dhclient.%s.leases' %ifacename
,
68 self
._run
_dhclient
_cmd
(cmd
, cmd_prefix
)
70 def release(self
, ifacename
, cmd_prefix
=None):
71 if os
.path
.exists('/sbin/dhclient3'):
72 cmd
= ['/sbin/dhclient3', '-r', '-pf',
73 '/run/dhclient.%s.pid' %ifacename
, '-lf',
74 '/var/lib/dhcp3/dhclient.%s.leases' %ifacename
,
77 cmd
= ['/sbin/dhclient', '-r', '-pf',
78 '/run/dhclient.%s.pid' %ifacename
,
79 '-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename
,
81 self
._run
_dhclient
_cmd
(cmd
, cmd_prefix
)
83 def start6(self
, ifacename
, wait
=True, cmd_prefix
=None):
84 cmd
= ['/sbin/dhclient', '-6', '-pf',
85 '/run/dhclient6.%s.pid' %ifacename
, '-lf',
86 '/var/lib/dhcp/dhclient6.%s.leases' % ifacename
,
90 self
._run
_dhclient
_cmd
(cmd
, cmd_prefix
)
92 def stop6(self
, ifacename
, cmd_prefix
=None):
93 cmd
= ['/sbin/dhclient', '-6', '-x', '-pf',
94 '/run/dhclient6.%s.pid' % ifacename
, '-lf',
95 '/var/lib/dhcp/dhclient6.%s.leases' % ifacename
,
97 self
._run
_dhclient
_cmd
(cmd
, cmd_prefix
)
99 def release6(self
, ifacename
, cmd_prefix
=None):
100 cmd
= ['/sbin/dhclient', '-6', '-r', '-pf',
101 '/run/dhclient6.%s.pid' %ifacename
,
102 '-lf', '/var/lib/dhcp/dhclient6.%s.leases' % ifacename
,
104 self
._run
_dhclient
_cmd
(cmd
, cmd_prefix
)