Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos.package
Commits
66c9dd1f
Commit
66c9dd1f
authored
Jun 04, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whitespace, except..as syntax, typos
parent
54ea0de7
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
102 deletions
+98
-102
slapprepare/slapprepare/slapprepare.py
slapprepare/slapprepare/slapprepare.py
+28
-34
slapprepare/slapprepare/slapupdate.py
slapprepare/slapprepare/slapupdate.py
+70
-68
No files found.
slapprepare/slapprepare/slapprepare.py
View file @
66c9dd1f
...
@@ -30,12 +30,12 @@ from optparse import OptionParser, Option
...
@@ -30,12 +30,12 @@ from optparse import OptionParser, Option
import
ConfigParser
import
ConfigParser
import
os
import
os
import
pkg_resources
import
pkg_resources
import
pwd
import
socket
import
socket
import
subprocess
import
subprocess
import
sys
import
sys
import
time
import
time
import
urllib2
import
urllib2
from
pwd
import
getpwnam
import
iniparse
import
iniparse
...
@@ -73,7 +73,6 @@ class Parser(OptionParser):
...
@@ -73,7 +73,6 @@ class Parser(OptionParser):
return
options
return
options
class
SlapError
(
Exception
):
class
SlapError
(
Exception
):
"""
"""
Slap error
Slap error
...
@@ -81,14 +80,15 @@ class SlapError(Exception):
...
@@ -81,14 +80,15 @@ class SlapError(Exception):
def
__init__
(
self
,
message
):
def
__init__
(
self
,
message
):
self
.
msg
=
message
self
.
msg
=
message
class
UsageError
(
SlapError
):
class
UsageError
(
SlapError
):
pass
pass
class
ExecError
(
SlapError
):
class
ExecError
(
SlapError
):
pass
pass
def
_call
(
cmd_args
,
stdout
=
None
,
stderr
=
None
,
dry_run
=
False
):
def
_call
(
cmd_args
,
stdout
=
None
,
stderr
=
None
,
dry_run
=
False
):
"""
"""
Wrapper for subprocess.call() which'll secure the usage of external program's.
Wrapper for subprocess.call() which'll secure the usage of external program's.
...
@@ -103,15 +103,15 @@ def _call(cmd_args, stdout=None, stderr=None, dry_run=False):
...
@@ -103,15 +103,15 @@ def _call(cmd_args, stdout=None, stderr=None, dry_run=False):
if
subprocess
.
call
(
cmd_args
,
stdout
=
stdout
,
stderr
=
stderr
)
!=
0
:
if
subprocess
.
call
(
cmd_args
,
stdout
=
stdout
,
stderr
=
stderr
)
!=
0
:
raise
ValueError
(
'Issues during running %r'
%
cmd_args
)
raise
ValueError
(
'Issues during running %r'
%
cmd_args
)
except
OSError
as
e
:
except
OSError
as
e
:
raise
ExecError
(
'Process respond
:"%s" when calling "%s"'
%
\
raise
ExecError
(
'Process respond
ed: "%s" when calling "%s"'
%
(
str
(
e
)
,
' '
.
join
(
cmd_args
)))
(
e
,
' '
.
join
(
cmd_args
)))
# Utility function to get yes/no answers
# Utility function to get yes/no answers
def
get_yes_no
(
prompt
,
default
=
None
):
def
get_yes_no
(
prompt
,
default
=
None
):
if
default
:
if
default
:
def_value
=
'/ Default yes'
def_value
=
'/ Default yes'
elif
default
==
False
:
elif
default
is
False
:
def_value
=
'/ Default no'
def_value
=
'/ Default no'
else
:
else
:
def_value
=
''
def_value
=
''
...
@@ -190,7 +190,7 @@ def get_ssh(temp_dir):
...
@@ -190,7 +190,7 @@ def get_ssh(temp_dir):
gotten
=
True
gotten
=
True
except
ValueError
:
except
ValueError
:
# add http:// if it is missing (needed by urllib2)
# add http:// if it is missing (needed by urllib2)
ssh_web
=
"""http://"""
+
ssh_web
ssh_web
=
"""http://"""
+
ssh_web
ssh_key_all
=
urllib2
.
urlopen
(
''
.
join
(
ssh_web
))
ssh_key_all
=
urllib2
.
urlopen
(
''
.
join
(
ssh_web
))
gotten
=
True
gotten
=
True
except
urllib2
.
URLError
:
except
urllib2
.
URLError
:
...
@@ -268,7 +268,6 @@ def slapserver(config):
...
@@ -268,7 +268,6 @@ def slapserver(config):
pkg_resources
.
resource_stream
(
__name__
,
pkg_resources
.
resource_stream
(
__name__
,
'template/ifcfg-br0.in'
).
read
())
'template/ifcfg-br0.in'
).
read
())
# Creating default limits config
# Creating default limits config
limits_conf_path
=
os
.
path
.
join
(
mount_dir_path
,
limits_conf_path
=
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'security'
,
'limits.conf'
)
'etc'
,
'security'
,
'limits.conf'
)
...
@@ -335,7 +334,6 @@ def slapserver(config):
...
@@ -335,7 +334,6 @@ def slapserver(config):
return
0
return
0
def
prepare_scripts
(
config
):
def
prepare_scripts
(
config
):
"""
"""
Will prepare script for slapos dedicated computer
Will prepare script for slapos dedicated computer
...
@@ -348,9 +346,9 @@ def prepare_scripts(config):
...
@@ -348,9 +346,9 @@ def prepare_scripts(config):
else
:
else
:
# Check for config file in /etc/slapos/
# Check for config file in /etc/slapos/
if
os
.
path
.
exists
(
'/etc/slapos/slapos.cfg'
):
if
os
.
path
.
exists
(
'/etc/slapos/slapos.cfg'
):
slapos_configuration
=
'/etc/slapos/'
slapos_configuration
=
'/etc/slapos/'
else
:
else
:
slapos_configuration
=
'/etc/opt/slapos/'
slapos_configuration
=
'/etc/opt/slapos/'
# Creating boot script
# Creating boot script
path
=
os
.
path
.
join
(
'/'
,
'usr'
,
'sbin'
,
'slapos-boot-dedicated'
)
path
=
os
.
path
.
join
(
'/'
,
'usr'
,
'sbin'
,
'slapos-boot-dedicated'
)
...
@@ -359,7 +357,7 @@ def prepare_scripts(config):
...
@@ -359,7 +357,7 @@ def prepare_scripts(config):
open
(
path
,
'w'
).
write
(
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
pkg_resources
.
resource_stream
(
__name__
,
'script/%s'
%
'slapos'
).
read
()
'script/%s'
%
'slapos'
).
read
()
%
dict
(
slapos_configuration
=
slapos_configuration
)
)
%
{
'slapos_configuration'
:
slapos_configuration
}
)
os
.
chmod
(
path
,
0755
)
os
.
chmod
(
path
,
0755
)
path
=
os
.
path
.
join
(
'/'
,
'etc'
,
path
=
os
.
path
.
join
(
'/'
,
'etc'
,
...
@@ -396,7 +394,7 @@ def configureNtp():
...
@@ -396,7 +394,7 @@ def configureNtp():
continue
continue
new_ntp
.
write
(
line
)
new_ntp
.
write
(
line
)
new_ntp
.
write
(
SLAPOS_MARK
)
new_ntp
.
write
(
SLAPOS_MARK
)
new_ntp
.
write
(
server
+
'
\
n
'
)
new_ntp
.
write
(
server
+
'
\
n
'
)
new_ntp
.
close
()
new_ntp
.
close
()
_call
([
'chkconfig'
,
'--add'
,
'ntp'
])
_call
([
'chkconfig'
,
'--add'
,
'ntp'
])
_call
([
'chkconfig'
,
'ntp'
,
'on'
])
_call
([
'chkconfig'
,
'ntp'
,
'on'
])
...
@@ -404,8 +402,6 @@ def configureNtp():
...
@@ -404,8 +402,6 @@ def configureNtp():
_call
([
'systemctl'
,
'restart'
,
'ntp.service'
])
_call
([
'systemctl'
,
'restart'
,
'ntp.service'
])
class
Config
:
class
Config
:
def
setConfig
(
self
,
option_dict
):
def
setConfig
(
self
,
option_dict
):
"""
"""
...
@@ -415,7 +411,6 @@ class Config:
...
@@ -415,7 +411,6 @@ class Config:
for
option
,
value
in
option_dict
.
__dict__
.
items
():
for
option
,
value
in
option_dict
.
__dict__
.
items
():
setattr
(
self
,
option
,
value
)
setattr
(
self
,
option
,
value
)
def
slaposConfig
(
self
,
def
slaposConfig
(
self
,
mount_dir_path
,
mount_dir_path
,
slapos_configuration
,
slapos_configuration
,
...
@@ -436,7 +431,6 @@ class Config:
...
@@ -436,7 +431,6 @@ class Config:
self
.
temp_dir
=
temp_dir
self
.
temp_dir
=
temp_dir
self
.
computer_id
=
computer_id
self
.
computer_id
=
computer_id
def
userConfig
(
self
):
def
userConfig
(
self
):
# XXX-Testme: test each possible scenario
# XXX-Testme: test each possible scenario
# XXX don't use self.xx but return a dict so that it is stateless
# XXX don't use self.xx but return a dict so that it is stateless
...
@@ -477,7 +471,6 @@ class Config:
...
@@ -477,7 +471,6 @@ class Config:
return
True
return
True
def
displayUserConfig
(
self
):
def
displayUserConfig
(
self
):
# XXX print everything from configuration, not arbitrary members
# XXX print everything from configuration, not arbitrary members
if
self
.
certificates
:
if
self
.
certificates
:
...
@@ -550,7 +543,7 @@ def prepare_from_scratch(config):
...
@@ -550,7 +543,7 @@ def prepare_from_scratch(config):
print
"Your Computer is : %s"
%
computer_id
print
"Your Computer is : %s"
%
computer_id
config
.
slaposConfig
(
mount_dir_path
=
'/'
,
config
.
slaposConfig
(
mount_dir_path
=
'/'
,
slapos_configuration
=
slapos_configuration
,
slapos_configuration
=
slapos_configuration
,
hostname_path
=
'/etc/HOSTNAME'
,
hostname_path
=
'/etc/HOSTNAME'
,
host_path
=
'/etc/hosts'
,
host_path
=
'/etc/hosts'
,
...
@@ -570,19 +563,17 @@ def prepare_from_scratch(config):
...
@@ -570,19 +563,17 @@ def prepare_from_scratch(config):
_call
([
'zypper'
,
'--gpg-auto-import-keys'
,
'install'
,
'-fy'
,
'slapos.node'
])
_call
([
'zypper'
,
'--gpg-auto-import-keys'
,
'install'
,
'-fy'
,
'slapos.node'
])
_call
([
'systemctl'
,
'stop'
,
'slapos-node.service'
])
_call
([
'systemctl'
,
'stop'
,
'slapos-node.service'
])
return_code
=
0
return_code
=
0
except
ExecError
,
err
:
except
ExecError
as
err
:
print
>>
sys
.
stderr
,
err
.
msg
print
>>
sys
.
stderr
,
err
.
msg
return_code
=
16
return_code
=
16
except
SystemExit
,
err
:
except
SystemExit
as
err
:
# Catch exception raise by optparse
# Catch exception raise by optparse
return_code
=
err
return_code
=
err
if
os
.
path
.
exists
(
temp_directory
):
if
os
.
path
.
exists
(
temp_directory
):
print
"Deleting directory: %s"
%
temp_directory
print
"Deleting directory: %s"
%
temp_directory
_call
([
'rm'
,
'-rf'
,
temp_directory
])
_call
([
'rm'
,
'-rf'
,
temp_directory
])
# Add/remove VPN file forcing/forbidding start of VPN.
# Add/remove VPN file forcing/forbidding start of VPN.
if
not
config
.
dry_run
:
if
not
config
.
dry_run
:
openvpn_needed_file_path
=
os
.
path
.
join
(
slapos_configuration
,
openvpn_needed_file_path
=
os
.
path
.
join
(
slapos_configuration
,
...
@@ -609,26 +600,30 @@ def chownSlaposDirectory():
...
@@ -609,26 +600,30 @@ def chownSlaposDirectory():
path
=
slapos_slapgrid_instance
path
=
slapos_slapgrid_instance
print
"Changing owners of software directory and partitions directories…"
print
"Changing owners of software directory and partitions directories…"
for
i
in
range
(
int
(
slapformat_partition
)):
for
i
in
range
(
int
(
slapformat_partition
)):
uid
=
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
)
)[
2
]
uid
=
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
)
)[
2
]
gid
=
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
)
)[
3
]
gid
=
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
)
)[
3
]
item
=
'%s%s'
%
(
slapformat_partition_base_name
,
i
)
item
=
'%s%s'
%
(
slapformat_partition_base_name
,
i
)
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
path
,
item
)):
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
path
,
item
)):
os
.
chown
(
os
.
path
.
join
(
path
,
item
),
uid
,
gid
)
os
.
chown
(
os
.
path
.
join
(
path
,
item
),
uid
,
gid
)
for
i
in
range
(
int
(
slapformat_partition
)):
for
i
in
range
(
int
(
slapformat_partition
)):
path
=
"%s/%s%s"
%
(
slapos_slapgrid_instance
,
slapformat_partition_base_name
,
i
)
path
=
"%s/%s%s"
%
(
slapos_slapgrid_instance
,
slapformat_partition_base_name
,
i
)
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
for
items
in
dirs
,
files
:
for
items
in
dirs
,
files
:
for
item
in
items
:
for
item
in
items
:
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
root
,
item
)):
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
root
,
item
)):
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
)
)[
2
],
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
)
)[
3
])
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
))[
2
],
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
))[
3
])
# chown of software root (/opt/slapgrid)
# chown of software root (/opt/slapgrid)
for
root
,
dirs
,
files
in
os
.
walk
(
slapos_slapgrid_software
):
for
root
,
dirs
,
files
in
os
.
walk
(
slapos_slapgrid_software
):
for
items
in
dirs
,
files
:
for
items
in
dirs
,
files
:
for
item
in
items
:
for
item
in
items
:
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
root
,
item
)):
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
root
,
item
)):
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
getpwnam
(
'slapsoft'
)[
2
],
getpwnam
(
'slapsoft'
)[
3
])
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
pwd
.
getpwnam
(
'slapsoft'
)[
2
],
pwd
.
getpwnam
(
'slapsoft'
)[
3
])
def
slapprepare
():
def
slapprepare
():
...
@@ -642,8 +637,8 @@ def slapprepare():
...
@@ -642,8 +637,8 @@ def slapprepare():
# Install/update slapos
# Install/update slapos
try
:
try
:
_call
([
'zypper'
,
'addrepo'
,
'-fc'
,
'-n'
,
'"SlapOS Official repo"'
_call
([
'zypper'
,
'addrepo'
,
'-fc'
,
'-n'
,
'"SlapOS Official repo"'
,
,
'http://download.opensuse.org/repositories/home:/VIFIBnexedi/openSUSE_%s/'
%
suse_version
(),
'slapos'
])
'http://download.opensuse.org/repositories/home:/VIFIBnexedi/openSUSE_%s/'
%
suse_version
(),
'slapos'
])
except
:
except
:
pass
pass
_call
([
'zypper'
,
'--gpg-auto-import-keys'
,
'install'
,
'-y'
,
'slapos.node'
])
_call
([
'zypper'
,
'--gpg-auto-import-keys'
,
'install'
,
'-y'
,
'slapos.node'
])
...
@@ -671,14 +666,14 @@ def slapprepare():
...
@@ -671,14 +666,14 @@ def slapprepare():
_call
([
'systemctl'
,
'start'
,
'slapos-boot-dedicated.service'
])
_call
([
'systemctl'
,
'start'
,
'slapos-boot-dedicated.service'
])
return_code
=
0
return_code
=
0
except
UsageError
,
err
:
except
UsageError
as
err
:
print
>>
sys
.
stderr
,
err
.
msg
print
>>
sys
.
stderr
,
err
.
msg
print
>>
sys
.
stderr
,
"For help use --help"
print
>>
sys
.
stderr
,
"For help use --help"
return_code
=
16
return_code
=
16
except
ExecError
,
err
:
except
ExecError
as
err
:
print
>>
sys
.
stderr
,
err
.
msg
print
>>
sys
.
stderr
,
err
.
msg
return_code
=
16
return_code
=
16
except
SystemExit
,
err
:
except
SystemExit
as
err
:
# Catch exception raise by optparse
# Catch exception raise by optparse
return_code
=
err
return_code
=
err
sys
.
exit
(
return_code
)
sys
.
exit
(
return_code
)
...
@@ -686,4 +681,3 @@ def slapprepare():
...
@@ -686,4 +681,3 @@ def slapprepare():
def
main
():
def
main
():
slapprepare
()
slapprepare
()
slapprepare/slapprepare/slapupdate.py
View file @
66c9dd1f
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment