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
b02015aa
Commit
b02015aa
authored
Jul 24, 2012
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch from config file to promise based container status
parent
fd20a6d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
39 deletions
+52
-39
slapos/container/prepare.py
slapos/container/prepare.py
+52
-39
No files found.
slapos/container/prepare.py
View file @
b02015aa
...
@@ -22,7 +22,6 @@ def main(sr_directory, partition_list):
...
@@ -22,7 +22,6 @@ def main(sr_directory, partition_list):
'.slapcontainer'
)
'.slapcontainer'
)
if
os
.
path
.
isfile
(
slapcontainer_filename
):
if
os
.
path
.
isfile
(
slapcontainer_filename
):
lock
=
lockfile
.
FileLock
(
slapcontainer_filename
)
lock
=
lockfile
.
FileLock
(
slapcontainer_filename
)
try
:
lock
.
acquire
(
timeout
=
0
)
lock
.
acquire
(
timeout
=
0
)
slapcontainer_conf
=
ConfigParser
.
ConfigParser
()
slapcontainer_conf
=
ConfigParser
.
ConfigParser
()
slapcontainer_conf
.
read
(
slapcontainer_filename
)
slapcontainer_conf
.
read
(
slapcontainer_filename
)
...
@@ -31,25 +30,15 @@ def main(sr_directory, partition_list):
...
@@ -31,25 +30,15 @@ def main(sr_directory, partition_list):
requested_status
=
slapcontainer_conf
.
get
(
'requested'
,
requested_status
=
slapcontainer_conf
.
get
(
'requested'
,
'status'
)
'status'
)
if
not
slapcontainer_conf
.
has_section
(
'current'
):
slapcontainer_conf
.
add_section
(
'current'
)
if
not
slapcontainer_conf
.
has_option
(
'current'
,
'created'
):
slapcontainer_conf
.
set
(
'current'
,
'created'
,
'no'
)
if
not
slapcontainer_conf
.
has_option
(
'current'
,
'status'
):
slapcontainer_conf
.
set
(
'current'
,
'status'
,
'stopped'
)
if
requested_status
==
'started'
:
if
requested_status
==
'started'
:
if
slapcontainer_conf
.
get
(
'current'
,
'created'
)
==
'no'
:
if
not
created
(
partition_path
):
create
(
sr_directory
,
partition_path
,
slapcontainer_conf
)
create
(
sr_directory
,
partition_path
,
slapcontainer_conf
.
set
(
'current'
,
'created'
,
'yes'
)
start
(
sr_directory
,
partition_path
,
slapcontainer_conf
)
slapcontainer_conf
)
if
status
(
sr_directory
,
partition_path
)
==
'stopped'
:
start
(
sr_directory
,
partition_path
)
else
:
else
:
stop
(
sr_directory
,
partition_path
,
if
status
(
sr_directory
,
partition_path
)
==
'started'
:
slapcontainer_conf
)
stop
(
sr_directory
,
partition_path
)
finally
:
with
open
(
slapcontainer_filename
,
'w'
)
as
slapcontainer_fp
:
slapcontainer_conf
.
write
(
slapcontainer_fp
)
except
lockfile
.
LockTimeout
:
except
lockfile
.
LockTimeout
:
# Can't do anything, we'll see on the next run
# Can't do anything, we'll see on the next run
pass
pass
...
@@ -58,26 +47,30 @@ def main(sr_directory, partition_list):
...
@@ -58,26 +47,30 @@ def main(sr_directory, partition_list):
def
start
(
sr_directory
,
partition_path
,
conf
):
def
start
(
sr_directory
,
partition_path
):
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'
)
call
([
lxc_start
,
'-f'
,
config_filename
])
call
([
lxc_start
,
'-f'
,
config_filename
,
# TODO: Check if container is started
,
'-n'
,
os
.
path
.
basename
(
partition_path
)
,
# Start container
'-d'
])
conf
.
set
(
'current'
,
'status'
,
'started'
)
def
stop
(
sr_directory
,
partition_path
):
def
stop
(
sr_directory
,
partition_path
,
conf
):
# TODO : Check if container is stopped
# TODO : Check if container is stopped
# Stop container
# Stop container
pass
if
conf
.
get
(
'current'
,
'created'
)
==
'yes'
:
def
created
(
partition_path
):
destroy
(
partition_path
,
conf
)
# XXX: Hardcoded
should_exists
=
[
'config'
,
'rootfs'
]
return
all
((
os
.
path
.
exists
(
os
.
path
.
join
(
partition_path
,
f
))
for
f
in
should_exists
))
...
@@ -89,7 +82,7 @@ def create(sr_directory, partition_path, conf):
...
@@ -89,7 +82,7 @@ def create(sr_directory, 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_filename
)
lxc
.
utsname
=
os
.
path
.
basename
(
partition_path
)
lxc
.
utsname
=
os
.
path
.
basename
(
partition_path
)
lxc
.
network
.
vlan
.
type
=
'vlan'
lxc
.
network
.
type
=
'vlan'
lxc
.
network
.
link
=
conf
.
get
(
'information'
,
'interface'
)
lxc
.
network
.
link
=
conf
.
get
(
'information'
,
'interface'
)
lxc
.
network
.
name
=
'eth0'
lxc
.
network
.
name
=
'eth0'
# XXX: Hardcoded netmasks
# XXX: Hardcoded netmasks
...
@@ -101,15 +94,35 @@ def create(sr_directory, partition_path, conf):
...
@@ -101,15 +94,35 @@ def create(sr_directory, partition_path, conf):
lxc_file
.
write
(
str
(
lxc
))
lxc_file
.
write
(
str
(
lxc
))
def
destroy
(
partition_path
,
conf
):
def
destroy
(
partition_path
):
# TODO: Destroy container
# TODO: Destroy container
pass
pass
def
status
(
sr_directory
,
partition_path
):
lxc_info
=
call
([
os
.
path
.
join
(
sr_directory
,
'parts/lxc/bin/lxc-info'
),
'-n'
,
os
.
path
.
basename
(
partition_path
)])
if
'RUNNING'
in
lxc_info
:
return
'started'
else
:
return
'stopped'
def
call
(
command_line
):
def
call
(
command_line
):
process
=
subprocess
.
Popen
(
command_line
,
stdin
=
subprocess
.
PIPE
)
# for debug :
# print ' '.join(command_line)
process
=
subprocess
.
Popen
(
command_line
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
process
.
stdin
.
flush
()
process
.
stdin
.
flush
()
process
.
stdin
.
close
()
process
.
stdin
.
close
()
if
process
.
wait
()
!=
0
:
if
process
.
wait
()
!=
0
:
raise
SlapContainerError
(
"Subprocess call failed"
)
raise
SlapContainerError
(
"Subprocess call failed"
)
out
=
process
.
stdout
.
read
()
# for debug :
# print out
return
out
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