Move autostart flag from containers to apps
This commit is contained in:
parent
6df8bf0616
commit
86a845a92d
@ -73,6 +73,10 @@ def publish(filename, force):
|
|||||||
def unpublish(app_name):
|
def unpublish(app_name):
|
||||||
App(app_name, False).unpublish()
|
App(app_name, False).unpublish()
|
||||||
|
|
||||||
|
def autostart(value):
|
||||||
|
value = value.lower() in ('1', 'on', 'enable', 'true')
|
||||||
|
App(app_name, False).set_autostart(value)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='SPOC application manager')
|
parser = argparse.ArgumentParser(description='SPOC application manager')
|
||||||
parser.set_defaults(action=None)
|
parser.set_defaults(action=None)
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
@ -114,6 +118,10 @@ parser_unpublish = subparsers.add_parser('unpublish')
|
|||||||
parser_unpublish.set_defaults(action=unpublish)
|
parser_unpublish.set_defaults(action=unpublish)
|
||||||
parser_unpublish.add_argument('app')
|
parser_unpublish.add_argument('app')
|
||||||
|
|
||||||
|
parser_autostart = subparsers.add_parser('autostart')
|
||||||
|
parser_autostart.set_defaults(action=autostart)
|
||||||
|
parser_autostart.add_argument('value', choices=('1', 'on', 'enable', 'true', '0', 'off', 'disable', 'false'), help='Sets the applications to be automatically started after the host boots up')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.action is listing:
|
if args.action is listing:
|
||||||
@ -134,5 +142,7 @@ elif args.action is publish:
|
|||||||
publish(args.filename, args.force)
|
publish(args.filename, args.force)
|
||||||
elif args.action is unpublish:
|
elif args.action is unpublish:
|
||||||
unpublish(args.app)
|
unpublish(args.app)
|
||||||
|
elif args.action is autostart:
|
||||||
|
autostart(args.value)
|
||||||
else:
|
else:
|
||||||
parser.print_usage()
|
parser.print_usage()
|
||||||
|
@ -52,31 +52,30 @@ def modify_env(container, env):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def modify_container(container, depends, mounts, envs, uid, gid, cmd, cwd, ready, halt, autostart):
|
def modify_container(container, depends, mounts, envs, uid, gid, cmd, cwd, ready, halt):
|
||||||
for depend in depends:
|
for depend in depends:
|
||||||
modify_depend(container, depend)
|
modify_depend(container, depend)
|
||||||
for mount in mounts:
|
for mount in mounts:
|
||||||
modify_mount(container, mount)
|
modify_mount(container, mount)
|
||||||
for env in envs:
|
for env in envs:
|
||||||
modify_env(container, env)
|
modify_env(container, env)
|
||||||
autostart = autostart == 'on'
|
|
||||||
args = locals()
|
args = locals()
|
||||||
for member in ('uid', 'gid', 'cmd', 'cwd', 'ready', 'halt', 'autostart'):
|
for member in ('uid', 'gid', 'cmd', 'cwd', 'ready', 'halt'):
|
||||||
value = args[member]
|
value = args[member]
|
||||||
if value:
|
if value:
|
||||||
setattr(container, member, value)
|
setattr(container, member, value)
|
||||||
|
|
||||||
def create(container_name, image_name, depends, mounts, env, uid, gid, cmd, cwd, ready, halt, autostart):
|
def create(container_name, image_name, depends, mounts, env, uid, gid, cmd, cwd, ready, halt):
|
||||||
# Create container based on image definition and extrea fields
|
# Create container based on image definition and extrea fields
|
||||||
container = Container(container_name, False)
|
container = Container(container_name, False)
|
||||||
container.set_definition(Image(image_name).get_definition())
|
container.set_definition(Image(image_name).get_definition())
|
||||||
modify_container(container, depends, mounts, env, uid, gid, cmd, cwd, ready, halt, autostart)
|
modify_container(container, depends, mounts, env, uid, gid, cmd, cwd, ready, halt)
|
||||||
container.create()
|
container.create()
|
||||||
|
|
||||||
def modify(container_name, depends, mounts, env, uid, gid, cmd, cwd, ready, halt, autostart):
|
def modify(container_name, depends, mounts, env, uid, gid, cmd, cwd, ready, halt):
|
||||||
# Change configuration of an existing container
|
# Change configuration of an existing container
|
||||||
container = Container(container_name)
|
container = Container(container_name)
|
||||||
modify_container(container, depends, mounts, env, uid, gid, cmd, cwd, ready, halt, autostart)
|
modify_container(container, depends, mounts, env, uid, gid, cmd, cwd, ready, halt)
|
||||||
container.create()
|
container.create()
|
||||||
|
|
||||||
def destroy(container_name):
|
def destroy(container_name):
|
||||||
@ -120,7 +119,6 @@ parser_create.add_argument('-c', '--cmd', help='Sets the container init command'
|
|||||||
parser_create.add_argument('-w', '--workdir', help='Sets the container init working directory')
|
parser_create.add_argument('-w', '--workdir', help='Sets the container init working directory')
|
||||||
parser_create.add_argument('-r', '--ready', help='Sets the container ready command')
|
parser_create.add_argument('-r', '--ready', help='Sets the container ready command')
|
||||||
parser_create.add_argument('-s', '--stopsig', help='Sets the signal to be sent to init on container shutdown')
|
parser_create.add_argument('-s', '--stopsig', help='Sets the signal to be sent to init on container shutdown')
|
||||||
parser_create.add_argument('-a', '--autostart', choices=('on', 'off'), help='Sets the container to be automatically started after the host boots up')
|
|
||||||
parser_create.add_argument('container')
|
parser_create.add_argument('container')
|
||||||
parser_create.add_argument('image')
|
parser_create.add_argument('image')
|
||||||
|
|
||||||
@ -135,7 +133,6 @@ parser_modify.add_argument('-c', '--cmd', help='Sets the container init command'
|
|||||||
parser_modify.add_argument('-w', '--workdir', help='Sets the container init working directory')
|
parser_modify.add_argument('-w', '--workdir', help='Sets the container init working directory')
|
||||||
parser_modify.add_argument('-r', '--ready', help='Sets the container ready command')
|
parser_modify.add_argument('-r', '--ready', help='Sets the container ready command')
|
||||||
parser_modify.add_argument('-s', '--stopsig', help='Sets the signal to be sent to init on container shutdown')
|
parser_modify.add_argument('-s', '--stopsig', help='Sets the signal to be sent to init on container shutdown')
|
||||||
parser_modify.add_argument('-a', '--autostart', choices=('on', 'off'), help='Sets the container to be automatically started after the host boots up')
|
|
||||||
parser_modify.add_argument('container')
|
parser_modify.add_argument('container')
|
||||||
|
|
||||||
parser_destroy = subparsers.add_parser('destroy')
|
parser_destroy = subparsers.add_parser('destroy')
|
||||||
@ -166,9 +163,9 @@ args = parser.parse_args()
|
|||||||
if args.action is listing:
|
if args.action is listing:
|
||||||
listing(args.type)
|
listing(args.type)
|
||||||
elif args.action is create:
|
elif args.action is 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)
|
create(args.container, args.image, args.depends, args.mount, args.env, args.uid, args.gid, args.cmd, args.workdir, args.ready, args.stopsig)
|
||||||
elif args.action is modify:
|
elif args.action is modify:
|
||||||
modify(args.container, args.depends, args.mount, args.env, args.uid, args.gid, args.cmd, args.workdir, args.ready, args.stopsig, args.autostart)
|
modify(args.container, args.depends, args.mount, args.env, args.uid, args.gid, args.cmd, args.workdir, args.ready, args.stopsig)
|
||||||
elif args.action is destroy:
|
elif args.action is destroy:
|
||||||
destroy(args.container)
|
destroy(args.container)
|
||||||
elif args.action is start:
|
elif args.action is start:
|
||||||
|
@ -20,6 +20,7 @@ class App:
|
|||||||
self.version = None
|
self.version = None
|
||||||
self.app_dir = os.path.join(APPS_DIR, name)
|
self.app_dir = os.path.join(APPS_DIR, name)
|
||||||
self.meta = {}
|
self.meta = {}
|
||||||
|
self.autostart = False
|
||||||
self.containers = []
|
self.containers = []
|
||||||
if load_from_repo:
|
if load_from_repo:
|
||||||
self.set_definition(repo_local.get_app(name))
|
self.set_definition(repo_local.get_app(name))
|
||||||
@ -27,12 +28,14 @@ class App:
|
|||||||
def set_definition(self, definition):
|
def set_definition(self, definition):
|
||||||
self.version = definition['version']
|
self.version = definition['version']
|
||||||
self.meta = definition['meta']
|
self.meta = definition['meta']
|
||||||
|
self.autostart = definition['autostart']
|
||||||
self.containers = [Container(container) for container in definition['containers']]
|
self.containers = [Container(container) for container in definition['containers']]
|
||||||
|
|
||||||
def get_definition(self):
|
def get_definition(self):
|
||||||
return {
|
return {
|
||||||
'version': self.version,
|
'version': self.version,
|
||||||
'meta': self.meta.copy(),
|
'meta': self.meta.copy(),
|
||||||
|
'autostart': self.autostart,
|
||||||
'containers': [container.name for container in self.containers]
|
'containers': [container.name for container in self.containers]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,3 +161,7 @@ class App:
|
|||||||
os.unlink(archive_path)
|
os.unlink(archive_path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_autostart(self, autostart):
|
||||||
|
self.autostart = autostart
|
||||||
|
repo_local.register_app(self.name, self.get_definition())
|
||||||
|
@ -27,7 +27,7 @@ class State(enum.Enum):
|
|||||||
FROZEN = 'FROZEN'
|
FROZEN = 'FROZEN'
|
||||||
THAWED = 'THAWED'
|
THAWED = 'THAWED'
|
||||||
|
|
||||||
DEFINITION_MEMBERS = {'build', 'depends', 'layers', 'mounts', 'env', 'uid', 'gid', 'cmd', 'cwd', 'ready', 'halt', 'autostart'}
|
DEFINITION_MEMBERS = {'build', 'depends', 'layers', 'mounts', 'env', 'uid', 'gid', 'cmd', 'cwd', 'ready', 'halt'}
|
||||||
|
|
||||||
class Container:
|
class Container:
|
||||||
def __init__(self, name, load_from_repo=True):
|
def __init__(self, name, load_from_repo=True):
|
||||||
@ -43,7 +43,6 @@ class Container:
|
|||||||
self.cwd = None
|
self.cwd = None
|
||||||
self.ready = None
|
self.ready = None
|
||||||
self.halt = None
|
self.halt = None
|
||||||
self.autostart = False
|
|
||||||
self.container_path = os.path.join(CONTAINERS_DIR, name)
|
self.container_path = os.path.join(CONTAINERS_DIR, name)
|
||||||
self.config_path = os.path.join(self.container_path, 'config')
|
self.config_path = os.path.join(self.container_path, 'config')
|
||||||
self.rootfs_path = os.path.join(self.container_path, 'rootfs')
|
self.rootfs_path = os.path.join(self.container_path, 'rootfs')
|
||||||
|
Loading…
Reference in New Issue
Block a user