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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
slapos.package
Commits
4a7af070
Commit
4a7af070
authored
Jun 30, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prepare: further cleanup
parent
f1b623c2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
49 deletions
+48
-49
slapprepare/slapprepare/slapprepare.py
slapprepare/slapprepare/slapprepare.py
+48
-49
No files found.
slapprepare/slapprepare/slapprepare.py
View file @
4a7af070
...
@@ -106,8 +106,10 @@ def _call(cmd_args, stdout=None, stderr=None, dry_run=False):
...
@@ -106,8 +106,10 @@ def _call(cmd_args, stdout=None, stderr=None, dry_run=False):
(
e
,
' '
.
join
(
cmd_args
)))
(
e
,
' '
.
join
(
cmd_args
)))
# Utility function to get yes/no answers
def
get_yes_no
(
prompt
,
default
=
None
):
def
get_yes_no
(
prompt
,
default
=
None
):
"""
Utility function to get yes/no answers
"""
if
default
:
if
default
:
def_value
=
'/ Default yes'
def_value
=
'/ Default yes'
elif
default
is
False
:
elif
default
is
False
:
...
@@ -136,19 +138,22 @@ def getSlaposConfiguration(slapos_configuration_file_path=None):
...
@@ -136,19 +138,22 @@ def getSlaposConfiguration(slapos_configuration_file_path=None):
return
{}
return
{}
# Return OpenSUSE version if it is SuSE
def
suse_version
():
def
suse_version
():
"""
Return OpenSUSE version if it is SuSE
"""
if
not
os
.
path
.
exists
(
'/etc/SuSE-release'
):
if
not
os
.
path
.
exists
(
'/etc/SuSE-release'
):
return
0
return
0
with
open
(
'/etc/SuSE-release'
)
as
f
:
for
line
in
open
(
'/etc/SuSE-release'
):
for
line
in
f
:
if
'VERSION'
in
line
:
if
"VERSION"
in
line
:
dist
=
line
.
split
()
dist
=
line
.
split
()
return
float
(
dist
[
2
])
return
float
(
dist
[
2
])
# Parse certificate to get computer name and return it
def
get_computer_name
(
slapos_configuration
):
def
get_computer_name
(
slapos_configuration
):
"""
Parse certificate to get computer name and return it
"""
try
:
try
:
return
getSlaposConfiguration
(
slapos_configuration
).
get
(
'slapos'
,
return
getSlaposConfiguration
(
slapos_configuration
).
get
(
'slapos'
,
'computer_id'
)
'computer_id'
)
...
@@ -169,9 +174,7 @@ def setup_bridge(slapos_configuration, create_tap):
...
@@ -169,9 +174,7 @@ def setup_bridge(slapos_configuration, create_tap):
slapos_cfg
.
write
(
fout
)
slapos_cfg
.
write
(
fout
)
# Function to get ssh key
def
get_ssh_keys
(
temp_dir
):
def
get_ssh
(
temp_dir
):
# Downloading ssh_key
count
=
10
count
=
10
gotten
=
True
gotten
=
True
while
count
:
while
count
:
...
@@ -196,9 +199,8 @@ def get_ssh(temp_dir):
...
@@ -196,9 +199,8 @@ def get_ssh(temp_dir):
break
break
else
:
else
:
count
-=
1
count
-=
1
ssh_file
=
open
(
os
.
path
.
join
(
temp_dir
,
"authorized_keys"
),
"w"
)
with
open
(
os
.
path
.
join
(
temp_dir
,
'authorized_keys'
),
'w'
)
as
ssh_file
:
ssh_file
.
write
(
''
.
join
(
ssh_pub_key
))
ssh_file
.
write
(
ssh_pub_key
)
ssh_file
.
close
()
return
0
return
0
...
@@ -225,15 +227,13 @@ def slapserver(config):
...
@@ -225,15 +227,13 @@ def slapserver(config):
mount_dir_path
=
config
.
mount_dir_path
mount_dir_path
=
config
.
mount_dir_path
try
:
try
:
# Setting hostname
# Setting hostname
hostname_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
hostname_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
mount_dir_path
,
config
.
hostname_path
))
config
.
hostname_path
]))
print
"Setting hostname in : %s"
%
hostname_path
print
"Setting hostname in : %s"
%
hostname_path
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
(
os
.
path
.
join
(
mount_dir_path
,
config
.
host_path
))
config
.
host_path
]))
print
"Creating %r"
%
host_path
print
"Creating %r"
%
host_path
if
not
dry_run
:
if
not
dry_run
:
open
(
host_path
,
'w'
).
write
(
open
(
host_path
,
'w'
).
write
(
...
@@ -243,8 +243,7 @@ def slapserver(config):
...
@@ -243,8 +243,7 @@ def slapserver(config):
})
})
# Creating safe sshd_config
# Creating safe sshd_config
sshd_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
'etc'
,
'ssh'
,
sshd_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'ssh'
,
'sshd_config'
))
'sshd_config'
]))
print
"Creating %r"
%
sshd_path
print
"Creating %r"
%
sshd_path
if
not
dry_run
:
if
not
dry_run
:
open
(
sshd_path
,
'w'
).
write
(
open
(
sshd_path
,
'w'
).
write
(
...
@@ -253,8 +252,7 @@ def slapserver(config):
...
@@ -253,8 +252,7 @@ def slapserver(config):
os
.
chmod
(
sshd_path
,
0o600
)
os
.
chmod
(
sshd_path
,
0o600
)
# Creating default bridge config
# Creating default bridge config
br0_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
'etc'
,
br0_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'sysconfig'
,
'network'
,
'ifcfg-br0'
))
'sysconfig'
,
'network'
,
'ifcfg-br0'
]))
print
"Creating %r"
%
br0_path
print
"Creating %r"
%
br0_path
if
not
dry_run
:
if
not
dry_run
:
open
(
br0_path
,
'w'
).
write
(
open
(
br0_path
,
'w'
).
write
(
...
@@ -272,10 +270,9 @@ def slapserver(config):
...
@@ -272,10 +270,9 @@ def slapserver(config):
# 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
(
os
.
path
.
join
(
mount_dir_path
,
'root'
))
ssh_key_directory
=
os
.
path
.
normpath
(
'/'
.
join
([
user_path
,
'.ssh'
]))
ssh_key_directory
=
os
.
path
.
normpath
(
os
.
path
.
join
(
user_path
,
'.ssh'
))
ssh_key_path
=
os
.
path
.
normpath
(
'/'
.
join
([
ssh_key_directory
,
ssh_key_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
ssh_key_directory
,
'authorized_keys'
))
'authorized_keys'
]))
stat_info
=
os
.
stat
(
user_path
)
stat_info
=
os
.
stat
(
user_path
)
uid
,
gid
=
stat_info
.
st_uid
,
stat_info
.
st_gid
uid
,
gid
=
stat_info
.
st_uid
,
stat_info
.
st_gid
ssh_key_directory
=
os
.
path
.
dirname
(
ssh_key_path
)
ssh_key_directory
=
os
.
path
.
dirname
(
ssh_key_path
)
...
@@ -290,7 +287,7 @@ def slapserver(config):
...
@@ -290,7 +287,7 @@ def slapserver(config):
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
).
read
()
))
open
(
ssh_key_path
,
'a'
).
write
(
open
(
config
.
key_path
).
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
)
...
@@ -349,7 +346,7 @@ def prepare_scripts(config):
...
@@ -349,7 +346,7 @@ def prepare_scripts(config):
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'
).
read
()
%
{
'script/slapos'
).
read
()
%
{
'slapos_configuration'
:
slapos_configuration
'slapos_configuration'
:
slapos_configuration
})
})
os
.
chmod
(
path
,
0o755
)
os
.
chmod
(
path
,
0o755
)
...
@@ -359,7 +356,7 @@ def prepare_scripts(config):
...
@@ -359,7 +356,7 @@ def prepare_scripts(config):
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/slapos.service'
).
read
()
%
{
'slapos_configuration'
:
slapos_configuration
'slapos_configuration'
:
slapos_configuration
})
})
os
.
chmod
(
path
,
0o755
)
os
.
chmod
(
path
,
0o755
)
...
@@ -370,7 +367,7 @@ def prepare_scripts(config):
...
@@ -370,7 +367,7 @@ def prepare_scripts(config):
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__
,
'template/
%s'
%
'
clientipv4.conf.in'
).
read
())
'template/clientipv4.conf.in'
).
read
())
os
.
chmod
(
path
,
0o755
)
os
.
chmod
(
path
,
0o755
)
# Remove old-timers scripts
# Remove old-timers scripts
...
@@ -470,8 +467,8 @@ class Config:
...
@@ -470,8 +467,8 @@ class Config:
print
"Will register a computer on master"
print
"Will register a computer on master"
if
self
.
master_url
:
if
self
.
master_url
:
print
"URL of master: %s"
%
self
.
master_url
print
"URL of master: %s"
%
self
.
master_url
print
"URL
\
"
web
\
"
of master: %s"
%
self
.
master_url_web
print
'URL "web" of master: %s'
%
self
.
master_url_web
print
"Number of partition: %s"
%
(
self
.
partition_amount
)
print
"Number of partition: %s"
%
self
.
partition_amount
print
"Computer name: %s"
%
self
.
computer_name
print
"Computer name: %s"
%
self
.
computer_name
print
"Network bridge for hosted VMs: %s"
%
self
.
need_bridge
print
"Network bridge for hosted VMs: %s"
%
self
.
need_bridge
print
"Ipv6 over VPN: %s"
%
self
.
force_vpn
print
"Ipv6 over VPN: %s"
%
self
.
force_vpn
...
@@ -529,7 +526,7 @@ def prepare_from_scratch(config):
...
@@ -529,7 +526,7 @@ def prepare_from_scratch(config):
else
:
else
:
setup_bridge
(
slapos_configuration
,
False
)
setup_bridge
(
slapos_configuration
,
False
)
else
:
else
:
print
'Warning: impossible to set up bridge because slapos configuration doesn
\
'
t exist.'
print
"Warning: impossible to set up bridge because slapos configuration doesn't exist."
computer_id
=
get_computer_name
(
computer_id
=
get_computer_name
(
os
.
path
.
join
(
slapos_configuration
,
'slapos.cfg'
))
os
.
path
.
join
(
slapos_configuration
,
'slapos.cfg'
))
...
@@ -547,7 +544,7 @@ def prepare_from_scratch(config):
...
@@ -547,7 +544,7 @@ def prepare_from_scratch(config):
# Prepare SlapOS Suse Server confuguration
# Prepare SlapOS Suse Server confuguration
if
config
.
need_ssh
:
if
config
.
need_ssh
:
get_ssh
(
temp_directory
)
get_ssh
_keys
(
temp_directory
)
slapserver
(
config
)
slapserver
(
config
)
...
@@ -593,21 +590,23 @@ def chownSlaposDirectory():
...
@@ -593,21 +590,23 @@ 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
=
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
))[
2
]
user
=
'%s%s'
%
(
slapformat_user_base_name
,
i
)
gid
=
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
))[
3
]
uid
=
pwd
.
getpwnam
(
user
).
pw_uid
item
=
'%s%s'
%
(
slapformat_partition_base_name
,
i
)
gid
=
pwd
.
getpwnam
(
user
).
pw_gid
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
path
,
item
)):
partition
=
'%s%s'
%
(
slapformat_partition_base_name
,
i
)
os
.
chown
(
os
.
path
.
join
(
path
,
item
),
uid
,
gid
)
if
not
os
.
path
.
islink
(
os
.
path
.
join
(
path
,
partition
)):
os
.
chown
(
os
.
path
.
join
(
path
,
partition
),
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
)
user
=
'%s%s'
%
(
slapformat_user_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
),
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
))[
2
]
,
pwd
.
getpwnam
(
user
).
pw_uid
,
pwd
.
getpwnam
(
'%s%s'
%
(
slapformat_user_base_name
,
i
))[
3
]
)
pwd
.
getpwnam
(
user
).
pw_gid
)
# 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
):
...
@@ -615,8 +614,8 @@ def chownSlaposDirectory():
...
@@ -615,8 +614,8 @@ def chownSlaposDirectory():
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
),
os
.
chown
(
os
.
path
.
join
(
root
,
item
),
pwd
.
getpwnam
(
'slapsoft'
)
[
2
]
,
pwd
.
getpwnam
(
'slapsoft'
)
.
pw_uid
,
pwd
.
getpwnam
(
'slapsoft'
)
[
3
]
)
pwd
.
getpwnam
(
'slapsoft'
)
.
pw_gid
)
def
slapprepare
():
def
slapprepare
():
...
...
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