~ubuntu-branches/debian/stretch/waagent/stretch

« back to all changes in this revision

Viewing changes to azurelinuxagent/common/osutil/coreos.py

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2016-08-24 16:48:22 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20160824164822-vdf8m5xy5gycm1cz
Tags: 2.1.6-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright 2014 Microsoft Corporation
 
3
#
 
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
 
7
#
 
8
#     http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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.
 
15
#
 
16
# Requires Python 2.4+ and Openssl 1.0+
 
17
#
 
18
 
 
19
import os
 
20
import re
 
21
import pwd
 
22
import shutil
 
23
import socket
 
24
import array
 
25
import struct
 
26
import fcntl
 
27
import time
 
28
import base64
 
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
 
34
 
 
35
class CoreOSUtil(DefaultOSUtil):
 
36
    def __init__(self):
 
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)
 
43
        else:
 
44
            path = self.python_path
 
45
        os.environ['PATH'] = path
 
46
 
 
47
        if 'PYTHONPATH' in os.environ:
 
48
            py_path = os.environ['PYTHONPATH']
 
49
            py_path = "{0}:{1}".format(py_path, self.waagent_path)
 
50
        else:
 
51
            py_path = self.waagent_path
 
52
        os.environ['PYTHONPATH'] = py_path
 
53
 
 
54
    def is_sys_user(self, username):
 
55
       #User 'core' is not a sysuser
 
56
       if username == 'core':
 
57
           return False
 
58
       return super(CoreOSUtil, self).is_sys_user(username)
 
59
 
 
60
    def is_dhcp_enabled(self):
 
61
        return True
 
62
 
 
63
    def start_network(self) :
 
64
        return shellutil.run("systemctl start systemd-networkd", chk_err=False)
 
65
 
 
66
    def restart_if(self, iface):
 
67
        shellutil.run("systemctl restart systemd-networkd")
 
68
 
 
69
    def restart_ssh_service(self):
 
70
        # SSH is socket activated on CoreOS. No need to restart it.
 
71
        pass
 
72
 
 
73
    def stop_dhcp_service(self):
 
74
        return shellutil.run("systemctl stop systemd-networkd", chk_err=False)
 
75
 
 
76
    def start_dhcp_service(self):
 
77
        return shellutil.run("systemctl start systemd-networkd", chk_err=False)
 
78
 
 
79
    def start_agent_service(self):
 
80
        return shellutil.run("systemctl start wagent", chk_err=False)
 
81
 
 
82
    def stop_agent_service(self):
 
83
        return shellutil.run("systemctl stop wagent", chk_err=False)
 
84
 
 
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
 
88
 
 
89
    def conf_sshd(self, disable_password):
 
90
        #In CoreOS, /etc/sshd_config is mount readonly. Skip the setting
 
91
        pass
 
92