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
Lu Xu
slapos.package
Commits
e945f936
Commit
e945f936
authored
Sep 14, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Former script are removed after adding new ones
parent
2c0a33ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
53 deletions
+33
-53
slapprepare/slapprepare/__init__.py
slapprepare/slapprepare/__init__.py
+33
-53
No files found.
slapprepare/slapprepare/__init__.py
View file @
e945f936
...
@@ -122,7 +122,7 @@ def get_yes_no (prompt,default=None):
...
@@ -122,7 +122,7 @@ def get_yes_no (prompt,default=None):
if
answer
==
''
:
return
default
if
answer
==
''
:
return
default
# Return OpenSUSE version if it is SuSE
# Return OpenSUSE version if it is SuSE
def
suse_version
():
def
suse_version
():
if
os
.
path
.
exists
(
'/etc/SuSE-release'
)
:
if
os
.
path
.
exists
(
'/etc/SuSE-release'
)
:
with
open
(
'/etc/SuSE-release'
)
as
f
:
with
open
(
'/etc/SuSE-release'
)
as
f
:
for
line
in
f
:
for
line
in
f
:
...
@@ -144,7 +144,7 @@ def get_computer_name(slapos_configuration):
...
@@ -144,7 +144,7 @@ def get_computer_name(slapos_configuration):
return
-
1
return
-
1
def
enable_bridge
(
slapos_configuration
):
def
enable_bridge
(
slapos_configuration
):
#Create temp file
#Create temp file
slapos_old_path
=
os
.
path
.
join
(
slapos_configuration
,
'slapos.cfg'
)
slapos_old_path
=
os
.
path
.
join
(
slapos_configuration
,
'slapos.cfg'
)
...
@@ -176,10 +176,10 @@ def get_ssh(temp_dir):
...
@@ -176,10 +176,10 @@ 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
:
print
" URL ERROR"
print
" URL ERROR"
gotten
=
False
gotten
=
False
count
-=
1
count
-=
1
...
@@ -207,7 +207,7 @@ def remove_former_scripts(slapos_configuration):
...
@@ -207,7 +207,7 @@ def remove_former_scripts(slapos_configuration):
pass
pass
_call
([
'rm'
,
'-f'
,
os
.
path
.
join
(
slapos_configuration
,
'slapos'
)])
_call
([
'rm'
,
'-f'
,
os
.
path
.
join
(
slapos_configuration
,
'slapos'
)])
_call
([
'rm'
,
'-f'
,
'/etc/systemd/system/slapos.service'
])
_call
([
'rm'
,
'-f'
,
'/etc/systemd/system/slapos.service'
])
# Specific function to configure SlapOS Image
# Specific function to configure SlapOS Image
...
@@ -222,7 +222,7 @@ def slapserver(config):
...
@@ -222,7 +222,7 @@ def slapserver(config):
if
not
dry_run
:
if
not
dry_run
:
open
(
hostname_path
,
'w'
).
write
(
"%s
\
n
"
%
config
.
computer_id
)
open
(
hostname_path
,
'w'
).
write
(
"%s
\
n
"
%
config
.
computer_id
)
# Adding the hostname as a valid address
# Adding the hostname as a valid address
host_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
host_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
config
.
host_path
]))
config
.
host_path
]))
print
"Creating %r"
%
host_path
print
"Creating %r"
%
host_path
...
@@ -251,7 +251,7 @@ def slapserver(config):
...
@@ -251,7 +251,7 @@ def slapserver(config):
pkg_resources
.
resource_stream
(
__name__
,
pkg_resources
.
resource_stream
(
__name__
,
'template/ifcfg-br0.in'
).
read
())
'template/ifcfg-br0.in'
).
read
())
# Writing ssh key
# Writing ssh key
if
config
.
need_ssh
:
if
config
.
need_ssh
:
user_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
'root'
]))
user_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
'root'
]))
...
@@ -269,11 +269,11 @@ def slapserver(config):
...
@@ -269,11 +269,11 @@ def slapserver(config):
print
"Setting uid:gid of %r to %s:%s"
%
(
ssh_key_directory
,
uid
,
gid
)
print
"Setting uid:gid of %r to %s:%s"
%
(
ssh_key_directory
,
uid
,
gid
)
os
.
chown
(
ssh_key_directory
,
uid
,
gid
)
os
.
chown
(
ssh_key_directory
,
uid
,
gid
)
os
.
chmod
(
ssh_key_directory
,
0700
)
os
.
chmod
(
ssh_key_directory
,
0700
)
print
"Creating file: %s"
%
ssh_key_path
print
"Creating file: %s"
%
ssh_key_path
if
not
dry_run
:
if
not
dry_run
:
open
(
ssh_key_path
,
'a'
).
write
(
''
.
join
(
open
(
config
.
key_path
,
'r'
).
read
()))
open
(
ssh_key_path
,
'a'
).
write
(
''
.
join
(
open
(
config
.
key_path
,
'r'
).
read
()))
if
not
dry_run
:
if
not
dry_run
:
print
"Setting uid:gid of %r to %s:%s"
%
(
ssh_key_path
,
uid
,
gid
)
print
"Setting uid:gid of %r to %s:%s"
%
(
ssh_key_path
,
uid
,
gid
)
os
.
chown
(
ssh_key_path
,
uid
,
gid
)
os
.
chown
(
ssh_key_path
,
uid
,
gid
)
...
@@ -290,14 +290,14 @@ def slapserver(config):
...
@@ -290,14 +290,14 @@ def slapserver(config):
open
(
os
.
path
.
join
(
config
.
slapos_configuration
,
'SlapContainer-needed'
),
'w'
)
open
(
os
.
path
.
join
(
config
.
slapos_configuration
,
'SlapContainer-needed'
),
'w'
)
# Removing line in slapos script activating kvm in virtual
# Removing line in slapos script activating kvm in virtual
if
config
.
virtual
:
if
config
.
virtual
:
if
not
dry_run
:
if
not
dry_run
:
path
=
os
.
path
.
join
(
'/'
,
'usr'
,
'sbin'
,
'slapos-boot-dedicated'
)
path
=
os
.
path
.
join
(
'/'
,
'usr'
,
'sbin'
,
'slapos-boot-dedicated'
)
_call
([
'sed'
,
'-i'
,
"$d"
,
path
],
dry_run
=
dry_run
)
_call
([
'sed'
,
'-i'
,
"$d"
,
path
],
dry_run
=
dry_run
)
_call
([
'sed'
,
'-i'
,
"$d"
,
path
],
dry_run
=
dry_run
)
_call
([
'sed'
,
'-i'
,
"$d"
,
path
],
dry_run
=
dry_run
)
# Adding slapos_firstboot in case of MultiDisk usage
# Adding slapos_firstboot in case of MultiDisk usage
if
not
config
.
one_disk
:
if
not
config
.
one_disk
:
for
script
in
[
'slapos_firstboot'
]:
for
script
in
[
'slapos_firstboot'
]:
path
=
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'init.d'
,
script
)
path
=
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'init.d'
,
script
)
...
@@ -305,7 +305,7 @@ def slapserver(config):
...
@@ -305,7 +305,7 @@ def slapserver(config):
if
not
dry_run
:
if
not
dry_run
:
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'script/%s'
%
script
).
read
())
'script/%s'
%
script
).
read
())
os
.
chmod
(
path
,
0755
)
os
.
chmod
(
path
,
0755
)
else
:
else
:
for
script
in
[
'slapos_firstboot'
]:
for
script
in
[
'slapos_firstboot'
]:
path
=
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'init.d'
,
script
)
path
=
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'init.d'
,
script
)
...
@@ -320,7 +320,7 @@ def slapserver(config):
...
@@ -320,7 +320,7 @@ def slapserver(config):
def
prepare_scripts
(
config
):
def
prepare_scripts
(
config
):
"""
"""
Will prepare script for slapos dedicated computer
Will prepare script for slapos dedicated computer
"""
"""
dry_run
=
config
.
dry_run
dry_run
=
config
.
dry_run
...
@@ -335,8 +335,6 @@ def prepare_scripts (config):
...
@@ -335,8 +335,6 @@ def prepare_scripts (config):
else
:
else
:
slapos_configuration
=
'/etc/opt/slapos/'
slapos_configuration
=
'/etc/opt/slapos/'
remove_former_scripts
(
slapos_configuration
)
# Creating boot script
# Creating boot script
path
=
os
.
path
.
join
(
'/'
,
'usr'
,
'sbin'
,
'slapos-boot-dedicated'
)
path
=
os
.
path
.
join
(
'/'
,
'usr'
,
'sbin'
,
'slapos-boot-dedicated'
)
print
"Creating %r"
%
path
print
"Creating %r"
%
path
...
@@ -347,37 +345,19 @@ def prepare_scripts (config):
...
@@ -347,37 +345,19 @@ def prepare_scripts (config):
%
dict
(
slapos_configuration
=
slapos_configuration
)
)
%
dict
(
slapos_configuration
=
slapos_configuration
)
)
os
.
chmod
(
path
,
0755
)
os
.
chmod
(
path
,
0755
)
path
=
os
.
path
.
join
(
'/'
,
'etc'
,
path
=
os
.
path
.
join
(
'/'
,
'etc'
,
'systemd'
,
'system'
,
'systemd'
,
'system'
,
'slapos-boot-dedicated.service'
)
'slapos-boot-dedicated.service'
)
print
"Creating %r"
%
path
print
"Creating %r"
%
path
if
not
dry_run
:
if
not
dry_run
:
open
(
path
,
'w'
).
write
(
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
pkg_resources
.
resource_stream
(
__name__
,
'script/%s'
%
'slapos.service'
).
read
()
'script/%s'
%
'slapos.service'
).
read
()
%
dict
(
slapos_configuration
=
slapos_configuration
))
%
dict
(
slapos_configuration
=
slapos_configuration
))
os
.
chmod
(
path
,
0755
)
os
.
chmod
(
path
,
0755
)
# Preparing retry slapformat script
# Remove old-timers scripts
path
=
os
.
path
.
join
(
slapos_configuration
,
'run_slapformat'
)
remove_former_scripts
(
slapos_configuration
)
print
"Creating %r"
%
path
if
not
dry_run
:
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'script/%s'
%
'run_slapformat'
).
read
()
%
dict
(
slapos_configuration
=
slapos_configuration
))
os
.
chmod
(
path
,
0755
)
path
=
os
.
path
.
join
(
'/'
,
'etc'
,
'openvpn'
,
'client.conf'
)
print
"Creating %r"
%
path
if
not
dry_run
:
open
(
path
,
'a'
).
write
(
"""script-security 3 system
up-restart
up '/bin/bash %(slapos_configuration)s/run_slapformat & echo foo'
log /var/log/openvpn.log"""
%
dict
(
slapos_configuration
=
slapos_configuration
))
os
.
chmod
(
path
,
0755
)
...
@@ -412,7 +392,7 @@ class Config:
...
@@ -412,7 +392,7 @@ class Config:
def
slaposConfig
(
self
,
mount_dir_path
,
slapos_configuration
,
def
slaposConfig
(
self
,
mount_dir_path
,
slapos_configuration
,
hostname_path
,
host_path
,
hostname_path
,
host_path
,
key_path
,
master_url
,
key_path
,
master_url
,
temp_dir
,
computer_id
):
temp_dir
,
computer_id
):
"""
"""
Set configuration for slapos
Set configuration for slapos
...
@@ -439,11 +419,11 @@ class Config:
...
@@ -439,11 +419,11 @@ class Config:
self
.
one_disk
=
not
get_yes_no
(
"Do you want to use SlapOS with a second disk?"
,
True
)
self
.
one_disk
=
not
get_yes_no
(
"Do you want to use SlapOS with a second disk?"
,
True
)
else
:
else
:
self
.
one_disk
=
True
self
.
one_disk
=
True
self
.
force_vpn
=
get_yes_no
(
"Do you want to force the use of vpn to provide ipv6?"
,
True
)
self
.
force_vpn
=
get_yes_no
(
"Do you want to force the use of vpn to provide ipv6?"
,
True
)
self
.
force_slapcontainer
=
get_yes_no
(
"Do you want to force the use lxc on this computer?"
,
False
)
self
.
force_slapcontainer
=
get_yes_no
(
"Do you want to force the use lxc on this computer?"
,
False
)
if
self
.
force_vpn
:
if
self
.
force_vpn
:
self
.
ipv6_interface
=
"tapVPN"
self
.
ipv6_interface
=
"tapVPN"
else
:
else
:
self
.
ipv6_interface
=
""
self
.
ipv6_interface
=
""
self
.
need_ssh
=
get_yes_no
(
"Do you want a remote ssh access?"
,
True
)
self
.
need_ssh
=
get_yes_no
(
"Do you want a remote ssh access?"
,
True
)
...
@@ -475,8 +455,8 @@ def prepare_from_scratch(config):
...
@@ -475,8 +455,8 @@ def prepare_from_scratch(config):
config
.
displayUserConfig
()
config
.
displayUserConfig
()
if
get_yes_no
(
"
\
n
Do you confirm?"
):
if
get_yes_no
(
"
\
n
Do you confirm?"
):
break
break
if
config
.
certificates
:
if
config
.
certificates
:
slapos_configuration
=
'/etc/opt/slapos/'
slapos_configuration
=
'/etc/opt/slapos/'
else
:
else
:
# Check for config file in /etc/slapos/
# Check for config file in /etc/slapos/
...
@@ -484,21 +464,21 @@ def prepare_from_scratch(config):
...
@@ -484,21 +464,21 @@ def prepare_from_scratch(config):
slapos_configuration
=
'/etc/slapos/'
slapos_configuration
=
'/etc/slapos/'
else
:
else
:
slapos_configuration
=
'/etc/opt/slapos/'
slapos_configuration
=
'/etc/opt/slapos/'
# Prepare Slapos Configuration
# Prepare Slapos Configuration
if
config
.
certificates
:
if
config
.
certificates
:
_call
([
'slapos'
,
'node'
,
'register'
,
config
.
computer_name
_call
([
'slapos'
,
'node'
,
'register'
,
config
.
computer_name
,
'--interface-name'
,
'br0'
,
'--interface-name'
,
'br0'
,
'--ipv6-interface'
,
config
.
ipv6_interface
,
'--ipv6-interface'
,
config
.
ipv6_interface
,
'--partition-number'
,
config
.
partition_amount
])
,
'--partition-number'
,
config
.
partition_amount
])
# Prepare for bridge
# Prepare for bridge
enable_bridge
(
slapos_configuration
)
enable_bridge
(
slapos_configuration
)
computer_id
=
get_computer_name
(
computer_id
=
get_computer_name
(
os
.
path
.
join
(
'/'
,
slapos_configuration
,
'slapos.cfg'
))
os
.
path
.
join
(
'/'
,
slapos_configuration
,
'slapos.cfg'
))
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'
,
...
@@ -507,7 +487,7 @@ def prepare_from_scratch(config):
...
@@ -507,7 +487,7 @@ def prepare_from_scratch(config):
master_url
=
"""https://slap.vifib.com"""
,
master_url
=
"""https://slap.vifib.com"""
,
temp_dir
=
temp_directory
,
temp_dir
=
temp_directory
,
computer_id
=
computer_id
)
computer_id
=
computer_id
)
# Prepare SlapOS Suse Server confuguration
# Prepare SlapOS Suse Server confuguration
if
config
.
need_ssh
:
if
config
.
need_ssh
:
get_ssh
(
temp_directory
)
get_ssh
(
temp_directory
)
...
@@ -531,7 +511,7 @@ def prepare_from_scratch(config):
...
@@ -531,7 +511,7 @@ def prepare_from_scratch(config):
return
return_code
return
return_code
def
slapprepare
():
def
slapprepare
():
"""
"""
Prepare SlapOS dedicated computer
Prepare SlapOS dedicated computer
...
...
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