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
Hardik Juneja
slapos.toolbox
Commits
87c12a30
Commit
87c12a30
authored
Jul 31, 2012
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some logs
parent
20a04993
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
slapos/container/prepare.py
slapos/container/prepare.py
+14
-5
No files found.
slapos/container/prepare.py
View file @
87c12a30
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
ConfigParser
import
ConfigParser
import
os
import
os
import
subprocess
import
subprocess
import
logging
import
lockfile
import
lockfile
...
@@ -17,6 +18,8 @@ class SlapContainerError(Exception):
...
@@ -17,6 +18,8 @@ class SlapContainerError(Exception):
def
main
(
sr_directory
,
partition_list
,
bridge_name
):
def
main
(
sr_directory
,
partition_list
,
bridge_name
):
logger
=
logging
.
getLogger
()
to_start
=
set
()
to_start
=
set
()
for
partition_path
in
partition_list
:
for
partition_path
in
partition_list
:
slapcontainer_filename
=
os
.
path
.
join
(
partition_path
,
slapcontainer_filename
=
os
.
path
.
join
(
partition_path
,
...
@@ -51,25 +54,30 @@ def main(sr_directory, partition_list, bridge_name):
...
@@ -51,25 +54,30 @@ def main(sr_directory, partition_list, bridge_name):
finally
:
finally
:
lock
.
release
()
lock
.
release
()
logger
.
debug
(
'Container to start %s.'
,
', '
.
join
(
to_start
))
try
:
try
:
active_containers
=
set
(
call
(
active_containers
=
set
(
call
(
[
os
.
path
.
join
(
sr_directory
,
'parts/lxc/bin/lxc-ls'
),
[
os
.
path
.
join
(
sr_directory
,
'parts/lxc/bin/lxc-ls'
),
'--active'
]
'--active'
]
).
split
(
'
\
n
'
))
).
split
(
'
\
n
'
))
logger
.
debug
(
'Active containers are %s.'
,
', '
.
join
(
active_containers
))
except
SlapContainerError
:
except
SlapContainerError
:
active_containers
=
set
()
active_containers
=
set
()
to_stop
=
active_containers
-
to_start
to_stop
=
active_containers
-
to_start
if
to_stop
:
logger
.
debug
(
'Stopping containers %s.'
,
', '
.
join
(
to_stop
))
for
container
in
to_stop
:
for
container
in
to_stop
:
try
:
try
:
logger
.
info
(
'Stopping container %s.'
,
container
)
call
(
call
(
[
os
.
path
.
join
(
sr_directory
,
'parts/lxc/bin/lxc-stop'
),
[
os
.
path
.
join
(
sr_directory
,
'parts/lxc/bin/lxc-stop'
),
'-n'
,
container
'-n'
,
container
]
]
)
)
except
SlapContainerError
:
except
SlapContainerError
:
pass
# TODO : put some log
logger
.
fatal
(
'Impossible to stop %s.'
,
container
)
...
@@ -142,8 +150,9 @@ def status(sr_directory, partition_path, conf):
...
@@ -142,8 +150,9 @@ def status(sr_directory, partition_path, conf):
def
call
(
command_line
,
override_environ
=
{}):
def
call
(
command_line
,
override_environ
=
{}):
# for debug :
logger
=
logging
.
getLogger
()
# print ' '.join(command_line)
logger
.
debug
(
'Call %s'
,
' '
.
join
(
command_line
))
environ
=
dict
(
os
.
environ
)
environ
=
dict
(
os
.
environ
)
environ
.
update
(
override_environ
)
environ
.
update
(
override_environ
)
process
=
subprocess
.
Popen
(
command_line
,
stdin
=
subprocess
.
PIPE
,
process
=
subprocess
.
Popen
(
command_line
,
stdin
=
subprocess
.
PIPE
,
...
@@ -152,9 +161,9 @@ def call(command_line, override_environ={}):
...
@@ -152,9 +161,9 @@ def call(command_line, override_environ={}):
process
.
stdin
.
close
()
process
.
stdin
.
close
()
if
process
.
wait
()
!=
0
:
if
process
.
wait
()
!=
0
:
logger
.
debug
(
'Failed'
)
raise
SlapContainerError
(
"Subprocess call failed"
)
raise
SlapContainerError
(
"Subprocess call failed"
)
out
=
process
.
stdout
.
read
()
out
=
process
.
stdout
.
read
()
# for debug :
logger
.
debug
(
'Output : %s.'
,
out
)
# print out
return
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