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

« back to all changes in this revision

Viewing changes to azurelinuxagent/distro/suse/osutil.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 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
34
 
 
35
 
class SUSE11OSUtil(DefaultOSUtil):
36
 
    def __init__(self):
37
 
        super(SUSE11OSUtil, self).__init__()
38
 
        self.dhclient_name='dhcpcd'
39
 
 
40
 
    def set_hostname(self, hostname):
41
 
        fileutil.write_file('/etc/HOSTNAME', hostname)
42
 
        shellutil.run("hostname {0}".format(hostname), chk_err=False)
43
 
 
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
47
 
 
48
 
    def is_dhcp_enabled(self):
49
 
        return True
50
 
 
51
 
    def stop_dhcp_service(self):
52
 
        cmd = "/sbin/service {0} stop".format(self.dhclient_name)
53
 
        return shellutil.run(cmd, chk_err=False)
54
 
 
55
 
    def start_dhcp_service(self):
56
 
        cmd = "/sbin/service {0} start".format(self.dhclient_name)
57
 
        return shellutil.run(cmd, chk_err=False)
58
 
 
59
 
    def start_network(self) :
60
 
        return shellutil.run("/sbin/service start network", chk_err=False)
61
 
 
62
 
    def restart_ssh_service(self):
63
 
        return shellutil.run("/sbin/service sshd restart", chk_err=False)
64
 
 
65
 
    def stop_agent_service(self):
66
 
        return shellutil.run("/sbin/service waagent stop", chk_err=False)
67
 
 
68
 
    def start_agent_service(self):
69
 
        return shellutil.run("/sbin/service waagent start", chk_err=False)
70
 
 
71
 
    def register_agent_service(self):
72
 
        return shellutil.run("/sbin/insserv waagent", chk_err=False)
73
 
 
74
 
    def unregister_agent_service(self):
75
 
        return shellutil.run("/sbin/insserv -r waagent", chk_err=False)
76
 
 
77
 
class SUSEOSUtil(SUSE11OSUtil):
78
 
    def __init__(self):
79
 
        super(SUSEOSUtil, self).__init__()
80
 
        self.dhclient_name = 'wickedd-dhcp4'
81
 
 
82
 
    def stop_dhcp_service(self):
83
 
        cmd = "systemctl stop {0}".format(self.dhclient_name)
84
 
        return shellutil.run(cmd, chk_err=False)
85
 
 
86
 
    def start_dhcp_service(self):
87
 
        cmd = "systemctl start {0}".format(self.dhclient_name)
88
 
        return shellutil.run(cmd, chk_err=False)
89
 
 
90
 
    def start_network(self) :
91
 
        return shellutil.run("systemctl start network", chk_err=False)
92
 
 
93
 
    def restart_ssh_service(self):
94
 
        return shellutil.run("systemctl restart sshd", chk_err=False)
95
 
 
96
 
    def stop_agent_service(self):
97
 
        return shellutil.run("systemctl stop waagent", chk_err=False)
98
 
 
99
 
    def start_agent_service(self):
100
 
        return shellutil.run("systemctl start waagent", chk_err=False)
101
 
 
102
 
    def register_agent_service(self):
103
 
        return shellutil.run("systemctl enable waagent", chk_err=False)
104
 
 
105
 
    def unregister_agent_service(self):
106
 
        return shellutil.run("systemctl disable waagent", chk_err=False)
107
 
 
108