Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
1563f8ef
Commit
1563f8ef
authored
Oct 24, 2013
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc-ls: Rewrite nesting code to use the attach API
Signed-off-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
Acked-by:
Serge E. Hallyn
<
serge.hallyn@ubuntu.com
>
parent
cbef6c52
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
13 deletions
+19
-13
lxc-ls
src/lxc/lxc-ls
+19
-13
No files found.
src/lxc/lxc-ls
View file @
1563f8ef
...
@@ -35,7 +35,7 @@ import json
...
@@ -35,7 +35,7 @@ import json
import
lxc
import
lxc
import
os
import
os
import
re
import
re
import
subprocess
import
tempfile
import
sys
import
sys
_
=
gettext
.
gettext
_
=
gettext
.
gettext
...
@@ -89,17 +89,23 @@ def getTerminalSize():
...
@@ -89,17 +89,23 @@ def getTerminalSize():
def
getSubContainers
(
container
,
lxcpath
):
def
getSubContainers
(
container
,
lxcpath
):
attach
=
[
'lxc-attach'
,
'-P'
,
lxcpath
,
'-R'
,
'-s'
,
'NETWORK|PID'
,
'-n'
,
container
,
'--'
,
sys
.
argv
[
0
],
"--nesting"
]
with
open
(
os
.
devnull
,
"w"
)
as
fd
:
with
open
(
os
.
devnull
,
"w"
)
as
fd
:
newenv
=
dict
(
os
.
environ
)
fdnum
,
path
=
tempfile
.
mkstemp
()
newenv
[
'NESTED'
]
=
"/proc/1/root/
%
s"
%
lxc
.
default_config_path
os
.
remove
(
path
)
sp
=
subprocess
.
Popen
(
attach
,
stderr
=
fd
,
stdout
=
subprocess
.
PIPE
,
env
=
newenv
,
universal_newlines
=
True
)
fd
=
os
.
fdopen
(
fdnum
)
sp
.
wait
()
out
=
sp
.
stdout
.
read
()
container
.
attach_wait
(
lxc
.
attach_run_command
,
[
sys
.
argv
[
0
],
"--nesting"
],
attach_flags
=
(
lxc
.
LXC_ATTACH_REMOUNT_PROC_SYS
),
namespaces
=
(
lxc
.
CLONE_NEWNET
+
lxc
.
CLONE_NEWPID
),
extra_env_vars
=
[
"NESTED=/proc/1/root/
%
s"
%
lxc
.
default_config_path
],
stdout
=
fd
)
fd
.
seek
(
0
)
out
=
fd
.
read
()
fd
.
close
()
if
out
:
if
out
:
return
json
.
loads
(
out
)
return
json
.
loads
(
out
)
return
None
return
None
...
@@ -213,8 +219,8 @@ for container_name in lxc.list_containers(config_path=lxcpath):
...
@@ -213,8 +219,8 @@ for container_name in lxc.list_containers(config_path=lxcpath):
containers
.
append
(
entry
)
containers
.
append
(
entry
)
# Nested containers
# Nested containers
if
args
.
nesting
:
if
args
.
nesting
and
container
.
state
==
"RUNNING"
:
sub
=
getSubContainers
(
container
_name
,
args
.
lxcpath
)
sub
=
getSubContainers
(
container
,
args
.
lxcpath
)
if
sub
:
if
sub
:
for
entry
in
sub
:
for
entry
in
sub
:
if
'nesting_parent'
not
in
entry
:
if
'nesting_parent'
not
in
entry
:
...
...
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