Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Eric Zheng
slapos.toolbox
Commits
68ef8900
Commit
68ef8900
authored
Jul 25, 2012
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve the container creation process
parent
dd213bf5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
15 deletions
+62
-15
slapos/container/prepare.py
slapos/container/prepare.py
+62
-15
No files found.
slapos/container/prepare.py
View file @
68ef8900
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
ConfigParser
import
ConfigParser
import
os
import
os
import
subprocess
import
subprocess
import
shutil
import
lockfile
import
lockfile
...
@@ -31,7 +32,7 @@ def main(sr_directory, partition_list):
...
@@ -31,7 +32,7 @@ def main(sr_directory, partition_list):
'status'
)
'status'
)
if
requested_status
==
'started'
:
if
requested_status
==
'started'
:
if
not
created
(
partition_path
):
if
not
created
(
partition_path
,
slapcontainer_conf
):
create
(
sr_directory
,
partition_path
,
create
(
sr_directory
,
partition_path
,
slapcontainer_conf
)
slapcontainer_conf
)
if
status
(
sr_directory
,
partition_path
)
==
'stopped'
:
if
status
(
sr_directory
,
partition_path
)
==
'stopped'
:
...
@@ -48,6 +49,7 @@ def main(sr_directory, partition_list):
...
@@ -48,6 +49,7 @@ def main(sr_directory, partition_list):
def
start
(
sr_directory
,
partition_path
):
def
start
(
sr_directory
,
partition_path
):
return
lxc_start
=
os
.
path
.
join
(
sr_directory
,
lxc_start
=
os
.
path
.
join
(
sr_directory
,
'parts/lxc/bin/lxc-start'
)
'parts/lxc/bin/lxc-start'
)
config_filename
=
os
.
path
.
join
(
partition_path
,
'config'
)
config_filename
=
os
.
path
.
join
(
partition_path
,
'config'
)
...
@@ -66,29 +68,72 @@ def stop(sr_directory, partition_path):
...
@@ -66,29 +68,72 @@ def stop(sr_directory, partition_path):
def
created
(
partition_path
):
def
created
(
partition_path
,
conf
):
# XXX: Hardcoded
return
os
.
path
.
exists
(
conf
.
get
(
'rootfs'
,
'directory'
))
and
\
should_exists
=
[
'config'
,
'rootfs'
]
os
.
path
.
exists
(
conf
.
get
(
'config'
,
'file'
))
return
all
((
os
.
path
.
exists
(
os
.
path
.
join
(
partition_path
,
f
))
for
f
in
should_exists
))
def
extract_rootfs
(
partition_path
,
conf
):
tmp_dir
=
conf
.
get
(
'rootfs'
,
'tmp'
)
if
os
.
path
.
exists
(
tmp_dir
):
shutil
.
rmtree
(
tmp_dir
)
os
.
mkdir
(
tmp_dir
)
call
([
conf
.
get
(
'tar'
,
'binary'
),
'-xf'
,
conf
.
get
(
'tar'
,
'archive'
),
'-C'
,
tmp_dir
],
{
'PATH'
:
'%s:%s'
%
(
os
.
environ
,
conf
.
get
(
'tar'
,
'path'
))})
lst_tmp_dir
=
os
.
listdir
(
tmp_dir
)
if
len
(
lst_tmp_dir
)
>
1
:
rootfs
=
tmp_dir
else
:
rootfs
=
os
.
path
.
join
(
tmp_dir
,
lst_tmp_dir
[
0
])
shutil
.
move
(
rootfs
,
conf
.
get
(
'rootfs'
,
'directory'
))
if
os
.
path
.
exists
(
tmp_dir
):
shutil
.
rmtree
(
tmp_dir
)
def
create
(
sr_directory
,
partition_path
,
conf
):
def
create
(
sr_directory
,
partition_path
,
conf
):
lxc_debian
=
os
.
path
.
join
(
sr_directory
,
tmp_dir
=
conf
.
get
(
'rootfs'
,
'tmp'
)
'parts/lxc/lib/lxc/templates/lxc-debian'
)
if
os
.
path
.
exists
(
tmp_dir
):
call
([
lxc_debian
,
'-p'
,
partition_path
])
shutil
.
rmtree
(
tmp_dir
)
extract_rootfs
(
partition_path
,
conf
)
lxc_filename
=
os
.
path
.
join
(
partition_path
,
'config'
)
lxc_filename
=
os
.
path
.
join
(
partition_path
,
'config'
)
lxc
=
LXCConfig
(
lxc_filename
)
lxc
=
LXCConfig
()
lxc
.
utsname
=
os
.
path
.
basename
(
partition_path
)
lxc
.
utsname
=
os
.
path
.
basename
(
partition_path
)
lxc
.
network
.
type
=
'vlan'
lxc
.
network
.
type
=
'vlan'
lxc
.
network
.
link
=
conf
.
get
(
'
information
'
,
'interface'
)
lxc
.
network
.
link
=
conf
.
get
(
'
network
'
,
'interface'
)
lxc
.
network
.
name
=
'eth0'
lxc
.
network
.
name
=
'eth0'
# XXX: Hardcoded netmasks
# XXX: Hardcoded netmasks
lxc
.
network
.
ipv4
=
'%s/32'
%
conf
.
get
(
'
information
'
,
'ipv4'
)
lxc
.
network
.
ipv4
=
'%s/32'
%
conf
.
get
(
'
network
'
,
'ipv4'
)
lxc
.
network
.
ipv6
=
'%s/128'
%
conf
.
get
(
'
information
'
,
'ipv6'
)
lxc
.
network
.
ipv6
=
'%s/128'
%
conf
.
get
(
'
network
'
,
'ipv6'
)
lxc
.
network
.
flags
=
'up'
lxc
.
network
.
flags
=
'up'
# XXX: Hardcoded stuff
lxc
.
tty
=
'4'
lxc
.
pts
=
'1024'
lxc
.
cgroup
.
devices
.
deny
=
'a'
lxc
.
cgroup
.
devices
.
allow
=
[
'c 1:3 rwm'
,
'c 1:5 rwm'
,
'c 5:1 rwm'
,
'c 5:0 rwm'
,
'c 4:0 rwm'
,
'c 4:1 rwm'
,
'c 1:9 rwm'
,
'c 1:8 rwm'
,
'c 136:* rwm'
,
'c 5:2 rwm'
,
'c 254:0 rwm'
,
]
lxc
.
mount
.
entry
=
[
'proc %s proc nodev,noexec,nosuid 0 0'
%
os
.
path
.
join
(
partition_path
,
'proc'
),
'sysfs %s sysfs defaults 0 0'
%
os
.
path
.
join
(
partition_path
,
'sys'
),
]
with
open
(
lxc_filename
,
'w'
)
as
lxc_file
:
with
open
(
lxc_filename
,
'w'
)
as
lxc_file
:
lxc_file
.
write
(
str
(
lxc
))
lxc_file
.
write
(
str
(
lxc
))
...
@@ -111,11 +156,13 @@ def status(sr_directory, partition_path):
...
@@ -111,11 +156,13 @@ def status(sr_directory, partition_path):
def
call
(
command_line
):
def
call
(
command_line
,
override_environ
=
{}
):
# for debug :
# for debug :
# print ' '.join(command_line)
# print ' '.join(command_line)
environ
=
dict
(
os
.
environ
)
environ
.
update
(
override_environ
)
process
=
subprocess
.
Popen
(
command_line
,
stdin
=
subprocess
.
PIPE
,
process
=
subprocess
.
Popen
(
command_line
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
stdout
=
subprocess
.
PIPE
,
env
=
environ
)
process
.
stdin
.
flush
()
process
.
stdin
.
flush
()
process
.
stdin
.
close
()
process
.
stdin
.
close
()
...
...
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