2
# Copyright 2014 Microsoft Corporation
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
16
# Requires Python 2.4+ and Openssl 1.0+
28
import azurelinuxagent.logger as logger
29
import azurelinuxagent.utils.fileutil as fileutil
30
import azurelinuxagent.utils.shellutil as shellutil
31
import azurelinuxagent.utils.textutil as textutil
32
from azurelinuxagent.metadata import DISTRO_NAME, DISTRO_VERSION, DISTRO_FULL_NAME
33
from azurelinuxagent.distro.default.osutil import DefaultOSUtil
35
class SUSE11OSUtil(DefaultOSUtil):
37
super(SUSE11OSUtil, self).__init__()
38
self.dhclient_name='dhcpcd'
40
def set_hostname(self, hostname):
41
fileutil.write_file('/etc/HOSTNAME', hostname)
42
shellutil.run("hostname {0}".format(hostname), chk_err=False)
44
def get_dhcp_pid(self):
45
ret= shellutil.run_get_output("pidof {0}".format(self.dhclient_name))
46
return ret[1] if ret[0] == 0 else None
48
def is_dhcp_enabled(self):
51
def stop_dhcp_service(self):
52
cmd = "/sbin/service {0} stop".format(self.dhclient_name)
53
return shellutil.run(cmd, chk_err=False)
55
def start_dhcp_service(self):
56
cmd = "/sbin/service {0} start".format(self.dhclient_name)
57
return shellutil.run(cmd, chk_err=False)
59
def start_network(self) :
60
return shellutil.run("/sbin/service start network", chk_err=False)
62
def restart_ssh_service(self):
63
return shellutil.run("/sbin/service sshd restart", chk_err=False)
65
def stop_agent_service(self):
66
return shellutil.run("/sbin/service waagent stop", chk_err=False)
68
def start_agent_service(self):
69
return shellutil.run("/sbin/service waagent start", chk_err=False)
71
def register_agent_service(self):
72
return shellutil.run("/sbin/insserv waagent", chk_err=False)
74
def unregister_agent_service(self):
75
return shellutil.run("/sbin/insserv -r waagent", chk_err=False)
77
class SUSEOSUtil(SUSE11OSUtil):
79
super(SUSEOSUtil, self).__init__()
80
self.dhclient_name = 'wickedd-dhcp4'
82
def stop_dhcp_service(self):
83
cmd = "systemctl stop {0}".format(self.dhclient_name)
84
return shellutil.run(cmd, chk_err=False)
86
def start_dhcp_service(self):
87
cmd = "systemctl start {0}".format(self.dhclient_name)
88
return shellutil.run(cmd, chk_err=False)
90
def start_network(self) :
91
return shellutil.run("systemctl start network", chk_err=False)
93
def restart_ssh_service(self):
94
return shellutil.run("systemctl restart sshd", chk_err=False)
96
def stop_agent_service(self):
97
return shellutil.run("systemctl stop waagent", chk_err=False)
99
def start_agent_service(self):
100
return shellutil.run("systemctl start waagent", chk_err=False)
102
def register_agent_service(self):
103
return shellutil.run("systemctl enable waagent", chk_err=False)
105
def unregister_agent_service(self):
106
return shellutil.run("systemctl disable waagent", chk_err=False)