Implement spoc-container list
This commit is contained in:
parent
1c889fcaac
commit
e4088372f4
@ -2,20 +2,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import shlex
|
||||
import os
|
||||
import shlex
|
||||
|
||||
from spoc.container import Container
|
||||
from spoc import repo_local
|
||||
from spoc.container import Container, STATE_RUNNING, STATE_STOPPED
|
||||
from spoc.image import Image
|
||||
from spoc.paths import VOLUME_DIR
|
||||
|
||||
ACTION_CREATE = 1
|
||||
ACTION_MODIFY = 2
|
||||
ACTION_DESTROY = 3
|
||||
ACTION_START = 4
|
||||
ACTION_STOP = 5
|
||||
ACTION_STATUS = 6
|
||||
ACTION_EXEC = 7
|
||||
ACTION_LIST = 1
|
||||
ACTION_CREATE = 2
|
||||
ACTION_MODIFY = 3
|
||||
ACTION_DESTROY = 4
|
||||
ACTION_START = 5
|
||||
ACTION_STOP = 6
|
||||
ACTION_STATUS = 7
|
||||
ACTION_EXEC = 8
|
||||
|
||||
def listing(state):
|
||||
if state == 'all':
|
||||
containers = repo_local.get_containers().keys()
|
||||
elif state == 'running':
|
||||
containers = [c for c in repo_local.get_containers() if Container(c).get_state() == STATE_RUNNING]
|
||||
elif state == 'stopped':
|
||||
containers = [c for c in repo_local.get_containers() if Container(c).get_state() == STATE_STOPPED]
|
||||
for container in containers:
|
||||
print(container)
|
||||
|
||||
def modify_depend(container, depend):
|
||||
if depend.startswith('!'):
|
||||
@ -102,6 +114,10 @@ parser = argparse.ArgumentParser(description='SPOC container manager')
|
||||
parser.set_defaults(action=None)
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
parser_list = subparsers.add_parser('list')
|
||||
parser_list.set_defaults(action=ACTION_LIST)
|
||||
parser_list.add_argument('type', choices=('all', 'running', 'stopped'), default='all', const='all', nargs='?')
|
||||
|
||||
parser_create = subparsers.add_parser('create')
|
||||
parser_create.set_defaults(action=ACTION_CREATE)
|
||||
parser_create.add_argument('-d', '--depends', action='append', default=[], help='Add another container as a start dependency')
|
||||
@ -156,7 +172,9 @@ parser_exec.add_argument('command', nargs=argparse.REMAINDER)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.action == ACTION_CREATE:
|
||||
if args.action == ACTION_LIST:
|
||||
listing(args.type)
|
||||
elif args.action == ACTION_CREATE:
|
||||
create(args.container, args.image, args.depends, args.mount, args.env, args.uid, args.gid, args.cmd, args.workdir, args.ready, args.stopsig, args.autostart)
|
||||
elif args.action == ACTION_MODIFY:
|
||||
modify(args.container, args.depends, args.mount, args.env, args.uid, args.gid, args.cmd, args.workdir, args.ready, args.stopsig, args.autostart)
|
||||
|
Loading…
Reference in New Issue
Block a user