diff --git a/walinuxagent/agent.py b/walinuxagent/agent.py index 8fc5d37..05815b8 100644 --- a/walinuxagent/agent.py +++ b/walinuxagent/agent.py @@ -200,8 +200,8 @@ def Deprovision(force=False, deluser=False): protocol = proto.GetDefaultProtocol() ovf = protocol.getOvf() if ovf is not None and deluser: - print("WARNING! {0} account and entire home directory will be deleted.", - ovf.getUserName()) + print ("WARNING! {0} account and entire home directory " + "will be deleted.").format(ovf.getUserName()) if not force: confirm = raw_input("Do you want to proceed (y/n)") diff --git a/walinuxagent/utils/osutil.py b/walinuxagent/utils/osutil.py index 0399835..dd77092 100644 --- a/walinuxagent/utils/osutil.py +++ b/walinuxagent/utils/osutil.py @@ -543,7 +543,8 @@ class DefaultDistro(object): return shellutil.Run(cmd, chk_err=False) def GetDhcpProcessId(self): - raise NotImplementedError('GetDhcpProcessId method missing') + ret= shellutil.RunGetOutput("pidof dhclient") + return ret[1] if ret[0] == 0 else None def SetHostname(self, hostname): fileutil.SetFileContents('/etc/hostname', hostname) @@ -718,10 +719,6 @@ class UbuntuDistro(DebianDistro): def StartNetwork(self): return shellutil.Run("service networking start", chk_err=False) - def GetDhcpProcessId(self): - ret= shellutil.RunGetOutput("pidof dhclient") - return ret[1] if ret[0] == 0 else None - def SetDhcpHostname(self, hostname): pass @@ -744,7 +741,7 @@ class Ubuntu1204Distro(UbuntuDistro): #Override def GetDhcpProcessId(self): - ret= shellutil.RunGetOutput("pidof dhclient") + ret= shellutil.RunGetOutput("pidof dhclient3") return ret[1] if ret[0] == 0 else None class RedhatDistro(DefaultDistro): @@ -834,19 +831,26 @@ class GentooDistro(DefaultDistro): class SUSEDistro(DefaultDistro): def __init__(self): super(SUSEDistro, self).init() + self.dhcpClientName='dhcpcd' def SetHostname(self, hostname): fileutil.SetFileContents('/etc/HOSTNAME', hostname) shellutil.Run("hostname {0}".format(hostname), chk_err=False) + def GetDhcpProcessId(self): + ret= shellutil.RunGetOutput("pidof {0}".format(self.dhcpClientName)) + return ret[1] if ret[0] == 0 else None + def IsDhcpEnabled(self): return True def StopDhcpService(self): - return shellutil.Run("/sbin/service wickedd-dhcp4 stop", chk_err=False) + cmd = "/sbin/service {0} stop".format(self.dhcpClientName) + return shellutil.Run(cmd, chk_err=False) def StartDhcpService(self): - return shellutil.Run("/sbin/service wickedd-dhcp4 start", chk_err=False) + cmd = "/sbin/service {0} start".format(self.dhcpClientName) + return shellutil.Run(cmd, chk_err=False) def StartNetwork(self) : return shellutil.Run("/sbin/service start networking", chk_err=False) @@ -873,6 +877,11 @@ class SUSEDistro(DefaultDistro): return ret return shellutil.Run("insserv -r waagent", chk_err=False) +class SUSE12Distro(SUSE12Distro): + def __init__(self): + super(SUSE12Distro, self).__init__() + self.dhcpClientName = 'wickedd-dhcp4' + class FreeBSDDistro(DefaultDistro): def __init__(self): self.scsiConfigured = False @@ -920,11 +929,13 @@ def GetDistro(distroInfo): elif name == 'gentoo': return CoreOSDistro() elif name == 'suse': - return SUSEDistro() + if version < '1.2': + return SUSEDistro() + else: + return SUSE12Distro() elif name == 'freebsd': return FreeBSDDistro() - else: - return DefaultDistro() + return DefaultDistro() CurrOSInfo = GetDistroInfo() CurrOS = GetDistro(CurrOSInfo)