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+
29
import azurelinuxagent.common.logger as logger
30
import azurelinuxagent.common.utils.fileutil as fileutil
31
import azurelinuxagent.common.utils.shellutil as shellutil
32
import azurelinuxagent.common.utils.textutil as textutil
33
from azurelinuxagent.common.osutil.default import DefaultOSUtil
35
class CoreOSUtil(DefaultOSUtil):
37
super(CoreOSUtil, self).__init__()
38
self.agent_conf_file_path = '/usr/share/oem/waagent.conf'
39
self.waagent_path='/usr/share/oem/bin/waagent'
40
self.python_path='/usr/share/oem/python/bin'
41
if 'PATH' in os.environ:
42
path = "{0}:{1}".format(os.environ['PATH'], self.python_path)
44
path = self.python_path
45
os.environ['PATH'] = path
47
if 'PYTHONPATH' in os.environ:
48
py_path = os.environ['PYTHONPATH']
49
py_path = "{0}:{1}".format(py_path, self.waagent_path)
51
py_path = self.waagent_path
52
os.environ['PYTHONPATH'] = py_path
54
def is_sys_user(self, username):
55
#User 'core' is not a sysuser
56
if username == 'core':
58
return super(CoreOSUtil, self).is_sys_user(username)
60
def is_dhcp_enabled(self):
63
def start_network(self) :
64
return shellutil.run("systemctl start systemd-networkd", chk_err=False)
66
def restart_if(self, iface):
67
shellutil.run("systemctl restart systemd-networkd")
69
def restart_ssh_service(self):
70
# SSH is socket activated on CoreOS. No need to restart it.
73
def stop_dhcp_service(self):
74
return shellutil.run("systemctl stop systemd-networkd", chk_err=False)
76
def start_dhcp_service(self):
77
return shellutil.run("systemctl start systemd-networkd", chk_err=False)
79
def start_agent_service(self):
80
return shellutil.run("systemctl start wagent", chk_err=False)
82
def stop_agent_service(self):
83
return shellutil.run("systemctl stop wagent", chk_err=False)
85
def get_dhcp_pid(self):
86
ret= shellutil.run_get_output("pidof systemd-networkd")
87
return ret[1] if ret[0] == 0 else None
89
def conf_sshd(self, disable_password):
90
#In CoreOS, /etc/sshd_config is mount readonly. Skip the setting