FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cloudstack/python/lib/cloudutils/syscfg.py at feature_bigswitch · kwanggithub/cloudstack · GitHub
This repository was archived by the owner on Jan 15, 2020. It is now read-only.
kwanggithub
/
cloudstack
Public archive
forked from
apache/cloudstack
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cloudstack
/
python
/
lib
/
cloudutils
/
syscfg.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
217 lines (186 loc) · 8.33 KB
Breadcrumbs
cloudstack
/
python
/
lib
/
cloudutils
/
syscfg.py
Copy path
File metadata and controls
executable file
·
217 lines (186 loc) · 8.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from
utilities
import
Distribution
,
serviceOpsRedhat
,
serviceOpsUbuntu
,
serviceOpsRedhat7
from
serviceConfig
import
*
class
sysConfigFactory
:
@
staticmethod
def
getSysConfigFactory
(
glbEnv
):
if
glbEnv
.
mode
==
"Agent"
:
return
sysConfigAgentFactory
.
getAgent
(
glbEnv
)
elif
glbEnv
.
mode
==
"Server"
:
return
sysConfigServerFactory
.
getServer
(
glbEnv
)
elif
glbEnv
.
mode
==
"HttpsServer"
:
return
sysConfigServerFactory
.
getServer
(
glbEnv
)
elif
glbEnv
.
mode
==
"Db"
:
return
sysConfigDbFactory
.
getDb
(
glbEnv
)
else
:
raise
CloudInternalException
(
"Need to specify which mode are u running: Agent/Server/Db"
)
class
sysConfigAgentFactory
:
@
staticmethod
def
getAgent
(
glbEnv
):
glbEnv
.
distribution
=
Distribution
()
distribution
=
glbEnv
.
distribution
.
getVersion
()
if
distribution
==
"Ubuntu"
:
return
sysConfigAgentUbuntu
(
glbEnv
)
elif
distribution
==
"Fedora"
or
distribution
==
"RHEL6"
:
return
sysConfigRedhat6
(
glbEnv
)
elif
distribution
==
"CentOS"
or
distribution
==
"RHEL5"
:
return
sysConfigRedhat5
(
glbEnv
)
elif
distribution
==
"RHEL7"
:
return
sysConfigRedhat7
(
glbEnv
)
else
:
print
"Can't find the distribution version"
return
sysConfig
()
class
sysConfigServerFactory
:
@
staticmethod
def
getServer
(
glbEnv
):
glbEnv
.
distribution
=
Distribution
()
distribution
=
glbEnv
.
distribution
.
getVersion
()
if
distribution
==
"Ubuntu"
:
return
sysConfigServerUbuntu
(
glbEnv
)
elif
distribution
!=
"Unknown"
:
return
sysConfigServerRedhat
(
glbEnv
)
else
:
print
"Can't find the distribution version"
return
sysConfig
()
class
sysConfigDbFactory
:
@
staticmethod
def
getDb
(
glbEnv
):
pass
class
sysConfig
(
object
):
def
__init__
(
self
,
env
):
self
.
env
=
env
self
.
services
=
[]
def
registerService
(
self
,
service
):
self
.
services
.
append
(
service
(
self
))
def
config
(
self
):
if
not
self
.
check
():
return
False
for
service
in
self
.
services
:
if
not
service
.
configration
():
raise
CloudInternalException
(
"Configuration failed for service %s"
%
service
.
serviceName
)
def
restore
(
self
):
for
service
in
self
.
services
:
service
.
backup
()
def
check
(
self
):
return
True
class
sysConfigAgent
(
sysConfig
):
def
__init__
(
self
,
env
):
super
(
sysConfigAgent
,
self
).
__init__
(
env
)
def
check
(
self
):
if
self
.
env
.
debug
:
return
True
if
self
.
env
.
agentMode
==
"myCloud"
:
if
self
.
env
.
distribution
.
getVersion
()
!=
"Ubuntu"
:
raise
CloudInternalException
(
"Need to run myCloud agent on an Ubuntu machine
\n
"
)
elif
self
.
env
.
distribution
.
getArch
()
!=
"x86_64"
:
raise
CloudInternalException
(
"Need to run myCloud agent on an 64bit machine
\n
"
)
#check free disk space on the local disk
if
os
.
path
.
exists
(
"/var/lib/libvirt/images"
):
size
=
-
1
try
:
size
=
int
(
bash
(
"df -P /var/lib/libvirt/images | tail -1 |awk '{print $4}'"
).
getStdout
())
except
:
pass
if
size
!=
-
1
and
size
<
(
30
*
1024
*
1024
):
raise
CloudRuntimeException
(
"Need at least 30G free disk space under /var/lib/libvirt/images"
)
#check memory
mem
=
-
1
try
:
mem
=
int
(
bash
(
"free -g|grep Mem|awk '{print $2}'"
).
getStdout
())
except
:
pass
if
mem
!=
-
1
and
mem
<
1
:
raise
CloudRuntimeException
(
"Need at least 1G memory"
)
if
os
.
geteuid
()
!=
0
:
raise
CloudInternalException
(
"Need to execute with root permission
\n
"
)
hostname
=
bash
(
"hostname -f"
)
if
not
hostname
.
isSuccess
():
raise
CloudInternalException
(
"Checking hostname ... [Failed]
\n
Please edit /etc/hosts, add a Fully Qualified Domain Name as your hostname
\n
"
)
kvmEnabled
=
self
.
svo
.
isKVMEnabled
()
if
not
kvmEnabled
:
raise
CloudInternalException
(
"Checking KVM...[Failed]
\n
Please enable KVM on this machine
\n
"
)
return
True
class
sysConfigAgentRedhatBase
(
sysConfigAgent
):
def
__init__
(
self
,
env
):
self
.
svo
=
serviceOpsRedhat
()
super
(
sysConfigAgentRedhatBase
,
self
).
__init__
(
env
)
class
sysConfigAgentRedhat7Base
(
sysConfigAgent
):
def
__init__
(
self
,
env
):
self
.
svo
=
serviceOpsRedhat7
()
super
(
sysConfigAgentRedhat7Base
,
self
).
__init__
(
env
)
class
sysConfigAgentUbuntu
(
sysConfigAgent
):
def
__init__
(
self
,
glbEnv
):
super
(
sysConfigAgentUbuntu
,
self
).
__init__
(
glbEnv
)
self
.
svo
=
serviceOpsUbuntu
()
self
.
services
=
[
securityPolicyConfigUbuntu
(
self
),
networkConfigUbuntu
(
self
),
libvirtConfigUbuntu
(
self
),
firewallConfigUbuntu
(
self
),
nfsConfig
(
self
),
cloudAgentConfig
(
self
)]
#it covers RHEL6/Fedora13/Fedora14
class
sysConfigRedhat6
(
sysConfigAgentRedhatBase
):
def
__init__
(
self
,
glbEnv
):
super
(
sysConfigRedhat6
,
self
).
__init__
(
glbEnv
)
self
.
services
=
[
cgroupConfig
(
self
),
securityPolicyConfigRedhat
(
self
),
networkConfigRedhat
(
self
),
libvirtConfigRedhat
(
self
),
firewallConfigAgent
(
self
),
nfsConfig
(
self
),
cloudAgentConfig
(
self
)]
#It covers RHEL5/CentOS5, the mainly difference is that there is no cgroup
class
sysConfigRedhat5
(
sysConfigAgentRedhatBase
):
def
__init__
(
self
,
glbEnv
):
super
(
sysConfigRedhat5
,
self
).
__init__
(
glbEnv
)
self
.
services
=
[
securityPolicyConfigRedhat
(
self
),
networkConfigRedhat
(
self
),
libvirtConfigRedhat
(
self
),
firewallConfigAgent
(
self
),
cloudAgentConfig
(
self
)]
#it covers RHEL7
class
sysConfigRedhat7
(
sysConfigAgentRedhat7Base
):
def
__init__
(
self
,
glbEnv
):
super
(
sysConfigRedhat7
,
self
).
__init__
(
glbEnv
)
self
.
services
=
[
securityPolicyConfigRedhat
(
self
),
networkConfigRedhat
(
self
),
libvirtConfigRedhat
(
self
),
firewallConfigAgent
(
self
),
nfsConfig
(
self
),
cloudAgentConfig
(
self
)]
class
sysConfigServer
(
sysConfig
):
def
check
(
self
):
if
os
.
geteuid
()
!=
0
:
raise
CloudInternalException
(
"Need to execute with root permission"
)
hostname
=
bash
(
"hostname -f"
)
if
not
hostname
.
isSuccess
():
raise
CloudInternalException
(
"Checking hostname ... [Failed]
\n
Please edit /etc/hosts, add a Fully Qualified Domain Name as your hostname
\n
"
)
return
True
class
sysConfigServerRedhat
(
sysConfigServer
):
def
__init__
(
self
,
glbEnv
):
super
(
sysConfigServerRedhat
,
self
).
__init__
(
glbEnv
)
self
.
svo
=
serviceOpsRedhat
()
self
.
services
=
[
sudoersConfig
(
self
),
firewallConfigServer
(
self
)]
class
sysConfigServerUbuntu
(
sysConfigServer
):
def
__init__
(
self
,
glbEnv
):
super
(
sysConfigServerUbuntu
,
self
).
__init__
(
glbEnv
)
self
.
svo
=
serviceOpsUbuntu
()
self
.
services
=
[
sudoersConfig
(
self
),
ubuntuFirewallConfigServer
(
self
)]
Back
|
FazBrowse Home
|
New Git URL