Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Commit

Permalink
Move atomic ps to atomic containers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rhatdan authored and rh-atomic-bot committed Sep 2, 2016
1 parent 4c0b919 commit 29e7829
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 37 deletions.
16 changes: 10 additions & 6 deletions Atomic/ps.py → Atomic/containers.py
Expand Up @@ -6,11 +6,15 @@
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",
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions atomic
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions docs/atomic-ps.1.md → atomic-containers.1.md
Expand Up @@ -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**]
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions atomic_dbus.py
Expand Up @@ -14,7 +14,7 @@
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"
Expand Down Expand Up @@ -267,11 +267,11 @@ def VulnerableInfo(self):
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)
Expand Down
22 changes: 20 additions & 2 deletions bash/atomic
Expand Up @@ -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
"
Expand Down Expand Up @@ -996,6 +1014,7 @@ _atomic() {

local commands=(
cluster
containers
host
diff
info
Expand All @@ -1004,7 +1023,6 @@ _atomic() {
storage
mount
pull
ps
rhost
run
scan
Expand Down
58 changes: 58 additions & 0 deletions docs/atomic-containers.1.md
@@ -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)
Expand Up @@ -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

26 changes: 13 additions & 13 deletions tests/integration/test_system_containers.sh
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 29e7829

Please sign in to comment.