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
7f8c4031
Commit
7f8c4031
authored
Dec 16, 2013
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc-ls: Add lxc.start.auto and lxc.group support
Signed-off-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
Acked-by:
Serge E. Hallyn
<
serge.hallyn@ubuntu.com
>
parent
ee1e7aa0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
lxc-ls
src/lxc/lxc-ls
+22
-3
No files found.
src/lxc/lxc-ls
View file @
7f8c4031
...
...
@@ -110,6 +110,8 @@ def getSubContainers(container, lxcpath):
return
json
.
loads
(
out
)
return
None
# Constants
FIELDS
=
(
"name"
,
"state"
,
"ipv4"
,
"ipv6"
,
"autostart"
,
"pid"
)
# Begin parsing the command line
parser
=
argparse
.
ArgumentParser
(
description
=
_
(
"LXC: List containers"
),
...
...
@@ -137,7 +139,8 @@ parser.add_argument("--stopped", dest="state", action="append_const",
parser
.
add_argument
(
"--fancy"
,
action
=
"store_true"
,
help
=
_
(
"use fancy output"
))
parser
.
add_argument
(
"--fancy-format"
,
type
=
str
,
default
=
"name,state,ipv4,ipv6"
,
parser
.
add_argument
(
"--fancy-format"
,
type
=
str
,
default
=
"name,state,ipv4,ipv6,autostart"
,
help
=
_
(
"comma separated list of fields to show"
))
parser
.
add_argument
(
"--nesting"
,
dest
=
"nesting"
,
action
=
"store_true"
,
...
...
@@ -164,6 +167,10 @@ lxcpath = os.environ.get('NESTED', args.lxcpath)
# Turn args.fancy_format into a list
args
.
fancy_format
=
args
.
fancy_format
.
strip
()
.
split
(
","
)
if
set
(
args
.
fancy_format
)
-
set
(
FIELDS
):
parser
.
error
(
_
(
"Invalid field(s):
%
s"
%
", "
.
join
(
list
(
set
(
args
.
fancy_format
)
-
set
(
FIELDS
)))))
# Basic checks
## Check for setns
SUPPORT_SETNS
=
os
.
path
.
exists
(
"/proc/self/ns"
)
...
...
@@ -229,6 +236,18 @@ for container_name in lxc.list_containers(config_path=lxcpath):
elif
container
.
init_pid
!=
-
1
:
entry
[
'pid'
]
=
str
(
container
.
init_pid
)
if
'autostart'
in
args
.
fancy_format
or
args
.
nesting
:
entry
[
'autostart'
]
=
"NO"
try
:
if
container
.
get_config_item
(
"lxc.start.auto"
)
==
"1"
:
entry
[
'autostart'
]
=
"YES"
groups
=
container
.
get_config_item
(
"lxc.group"
)
if
len
(
groups
)
>
0
:
entry
[
'autostart'
]
=
"YES (
%
s)"
%
", "
.
join
(
groups
)
except
KeyError
:
pass
# Get the IPs
for
family
,
protocol
in
{
'inet'
:
'ipv4'
,
'inet6'
:
'ipv6'
}
.
items
():
if
protocol
in
args
.
fancy_format
or
args
.
nesting
:
...
...
@@ -239,8 +258,8 @@ for container_name in lxc.list_containers(config_path=lxcpath):
continue
# FIXME: We should get get_ips working as non-root
if
container
.
running
and
(
not
SUPPORT_SETNS_NET
\
or
os
.
geteuid
()
!=
0
):
if
container
.
running
and
(
not
SUPPORT_SETNS_NET
or
os
.
geteuid
()
!=
0
):
entry
[
protocol
]
=
'UNKNOWN'
continue
...
...
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