1
0
mirror of https://github.com/projectatomic/atomic.git synced 2026-02-05 18:45:01 +01:00

Move atomic ps to atomic containers

As we add more commands related to containers, IE Trim, we need to make
containers be a subcommand and add verbs like list, and trim

Closes: #579
Approved by: giuseppe
This commit is contained in:
Dan Walsh
2016-09-01 12:43:09 -04:00
committed by Atomic Bot
parent 4c0b919019
commit 29e7829fd8
8 changed files with 121 additions and 37 deletions

View File

@@ -6,11 +6,15 @@ import datetime
from dateutil.parser import parse as dateparse
def cli(subparser):
# atomic ps
pss = subparser.add_parser("ps",
help=_("list the containers"),
epilog="By default this shows only the running containers.")
pss.set_defaults(_class=Ps, func='ps_tty')
# atomic containers
c = subparser.add_parser("containers")
containers_subparser = c.add_subparsers(title='images subcommands',
description="operate on images",
help='additional help')
pss = containers_subparser.add_parser("list",
help=_("list the containers"),
epilog="By default this shows only the running containers.")
pss.set_defaults(_class=Containers, func='ps_tty')
pss.add_argument("-a", "--all", action='store_true',dest="all", default=False,
help=_("show all containers"))
pss.add_argument("-f", "--filter", metavar='FILTER', action='append', dest="filter",
@@ -27,7 +31,7 @@ def cli(subparser):
util.add_opt(pss)
class Ps(Atomic):
class Containers(Atomic):
def ps_tty(self):
all_container_info = self.ps()

4
atomic
View File

@@ -41,7 +41,7 @@ from Atomic import info
from Atomic import install
from Atomic import help as Help
from Atomic import run
from Atomic import ps
from Atomic import containers
from Atomic import pull
from Atomic import push
from Atomic import stop
@@ -139,7 +139,7 @@ def create_parser(help_text):
install.cli(subparser)
images.cli(subparser)
mount.cli(subparser)
ps.cli(subparser)
containers.cli(subparser)
push.cli(subparser)
pull.cli(subparser)
run.cli(subparser)

View File

@@ -2,10 +2,21 @@
% Giuseppe Scrivano
% June 2016
# NAME
atomic-ps - list locally installed containers
atomic-containers - operations on container
# SYNOPSIS
**atomic ps**
**atomic containers COMMAND [OPTIONS] [CONTAINERS...]**
atomic images allows the user to view and operate on containers
# COMMANDS
**list**
By default, will list all running containers on your system.
Using --all will list all the installed containers.
# list OPTIONS
[**-h|--help**]
[**-a|--all**]
[**-f|--filter**]
@@ -14,12 +25,6 @@ atomic-ps - list locally installed containers
[**--no-trunc**]
[**-q|--quiet**]
# DESCRIPTION
**atomic ps**, by default, will list all running containers on your
system.
Using --all will list all the installed containers.
# OPTIONS:
**-h** **--help**
Print usage statement

View File

@@ -14,7 +14,7 @@ from Atomic.images import Images
from Atomic.storage import Storage
from Atomic.diff import Diff
from Atomic.scan import Scan
from Atomic.ps import Ps
from Atomic.containers import Containers
class atomic_dbus(slip.dbus.service.Object):
default_polkit_auth_required = "org.atomic.readwrite"
@@ -267,11 +267,11 @@ class atomic_dbus(slip.dbus.service.Object):
self.atomic.set_args(args)
return self.atomic.get_all_vulnerable_info()
# The Ps method will list all containers on the system.
# The containers.Ps method will list all containers on the system.
@slip.dbus.polkit.require_auth("org.atomic.read")
@dbus.service.method("org.atomic", in_signature='', out_signature='s')
def Ps(self):
ps = Ps()
ps = Containers()
ps.useTTY = False
args = self.Args()
ps.set_args(args)

View File

@@ -313,7 +313,25 @@ _atomic_pull() {
esac
}
_atomic_ps() {
_atomic_containers() {
local subcommands="
list
"
__atomic_subcommands "$subcommands" && return
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
;;
esac
return 0
}
_atomic_containers_list() {
local options_with_args="
--filter -f
"
@@ -996,6 +1014,7 @@ _atomic() {
local commands=(
cluster
containers
host
diff
info
@@ -1004,7 +1023,6 @@ _atomic() {
storage
mount
pull
ps
rhost
run
scan

View File

@@ -0,0 +1,58 @@
% ATOMIC(1) Atomic Man Pages
% Giuseppe Scrivano
% June 2016
# NAME
atomic-containers - operations on containers
# SYNOPSIS
**atomic containers COMMAND [OPTIONS] [CONTAINERS...]**
atomic containers allows the user to view and operate on containers
# COMMANDS
**list**
list containers on your system.
# list OPTIONS
[**-h|--help**]
[**-a|--all**]
[**-f|--filter**]
[**--json**]
[**-n|--noheading**]
[**--no-trunc**]
[**-q|--quiet**]
# DESCRIPTION
**atomic containers list**, by default, will list all running containers on your
system.
Using --all will list all the installed containers.
# OPTIONS:
**-h** **--help**
Print usage statement
**-a** **--all**
Print all the installed containers
**-f** **--filter**
Filter output based on given filters, example usage: `--filter id=foo` will list all containers that has "foo" as part of their ID.
Filterables: `container (id)`, `image`, `command`, `created`, `status`, `runtime`
**--json**
Print in a machine parsable format
**-n** **--noheading**
Do not print heading when listing the containers
**--no-trunc**
Do not truncate output
**-q** **--quiet**
Only display container IDs
# HISTORY
June 2016, Originally compiled by Giuseppe Scrivano (gscrivan at redhat dot com)
July 2016, Added sub-commands filter, no-trunc and quiet (jerzhang at redhat dot com)

View File

@@ -16,11 +16,10 @@ IFS=$'\n\t'
OUTPUT=$(/bin/true)
${ATOMIC} ps --all -q -f runtime=Docker | sort > atomic.ps.out
${ATOMIC} containers list --all -q -f runtime=Docker | sort > atomic.ps.out
docker ps --all -q | sort > docker.ps.out
diff docker.ps.out atomic.ps.out
${ATOMIC} ps -q -f runtime=Docker | sort > atomic.ps.out
${ATOMIC} containers list -q -f runtime=Docker | sort > atomic.ps.out
docker ps -q | sort > docker.ps.out
diff docker.ps.out atomic.ps.out

View File

@@ -92,35 +92,35 @@ test -e /etc/tmpfiles.d/${NAME}.conf
${ATOMIC} update --container ${NAME} > update.out
assert_matches "Latest version already installed" update.out
${ATOMIC} ps --no-trunc > ps.out
${ATOMIC} containers list --no-trunc > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps --json > ps.out
${ATOMIC} containers list --json > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps --all > ps.out
${ATOMIC} containers list --all > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps --all --no-trunc > ps.out
${ATOMIC} containers list --all --no-trunc > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps --no-trunc --filter id=test-system > ps.out
${ATOMIC} containers list --no-trunc --filter id=test-system > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps --no-trunc > ps.out
${ATOMIC} containers list --no-trunc > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps --no-trunc --quiet > ps.out
${ATOMIC} containers list --no-trunc --quiet > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps -aq --no-trunc --filter id=test-system > ps.out
${ATOMIC} containers list -aq --no-trunc --filter id=test-system > ps.out
assert_matches "test-system" ps.out
${ATOMIC} ps -aq --no-trunc --filter id=non-existing-system > ps.out
${ATOMIC} containers list -aq --no-trunc --filter id=non-existing-system > ps.out
assert_not_matches "test-system" ps.out
${ATOMIC} ps --all --no-trunc --filter id=test-system | grep "test-system" > ps.out
${ATOMIC} containers list --all --no-trunc --filter id=test-system | grep "test-system" > ps.out
# Check the command is included in the output
assert_matches "run.sh" ps.out
systemctl stop ${NAME}
${ATOMIC} ps --all | grep "test-system" > ps.out
${ATOMIC} containers list --all | grep "test-system" > ps.out
assert_matches "exited" ps.out
${ATOMIC} ps --quiet > ps.out
${ATOMIC} containers list --quiet > ps.out
assert_not_matches "test-system" ps.out
test -e /etc/systemd/system/${NAME}.service
@@ -143,7 +143,7 @@ assert_matches 8082 ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1/config.json
# Test if a container with a remote rootfs can be installed/updated
${ATOMIC} --debug install --name=${NAME}-remote --rootfs=${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1 --set=RECEIVER=${SECRET}-remote --system oci:atomic-test-system
${ATOMIC} --debug ps --no-trunc > ps.out
${ATOMIC} --debug containers list --no-trunc > ps.out
assert_matches "remote" ps.out
test -e /etc/systemd/system/${NAME}-remote.service