2018-08-02 10:41:40 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import sys
|
2018-09-03 17:24:48 +02:00
|
|
|
sys.path.append('/srv/vm')
|
2018-08-02 10:41:40 +02:00
|
|
|
|
2018-09-04 21:42:26 +02:00
|
|
|
from mgr import VMMgr
|
2018-08-02 10:41:40 +02:00
|
|
|
|
2018-09-03 17:24:48 +02:00
|
|
|
parser = argparse.ArgumentParser(description='VM application manager')
|
2018-08-02 10:41:40 +02:00
|
|
|
subparsers = parser.add_subparsers()
|
|
|
|
|
2018-10-27 21:13:35 +02:00
|
|
|
parser_update_login = subparsers.add_parser('update-login')
|
2018-08-02 10:41:40 +02:00
|
|
|
parser_update_login.set_defaults(action='update-login')
|
|
|
|
parser_update_login.add_argument('app', help='Application name')
|
|
|
|
parser_update_login.add_argument('login', help='Administrative login')
|
|
|
|
parser_update_login.add_argument('password', help='Administrative password')
|
|
|
|
|
2018-10-27 21:13:35 +02:00
|
|
|
parser_rebuild_issue = subparsers.add_parser('rebuild-issue')
|
2018-08-31 09:13:18 +02:00
|
|
|
parser_rebuild_issue.set_defaults(action='rebuild-issue')
|
|
|
|
|
2018-10-27 21:13:35 +02:00
|
|
|
parser_prepare_container = subparsers.add_parser('prepare-container')
|
2018-09-21 16:21:55 +02:00
|
|
|
parser_prepare_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
|
|
|
parser_prepare_container.set_defaults(action='prepare-container')
|
2018-09-14 23:56:02 +02:00
|
|
|
|
2018-10-27 21:13:35 +02:00
|
|
|
parser_register_container = subparsers.add_parser('register-container')
|
2018-09-12 10:36:48 +02:00
|
|
|
parser_register_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
|
|
|
parser_register_container.set_defaults(action='register-container')
|
|
|
|
|
2018-10-27 21:13:35 +02:00
|
|
|
parser_unregister_container = subparsers.add_parser('unregister-container')
|
2018-09-12 10:36:48 +02:00
|
|
|
parser_unregister_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
|
|
|
parser_unregister_container.set_defaults(action='unregister-container')
|
|
|
|
|
2018-10-27 21:13:35 +02:00
|
|
|
parser_register_proxy = subparsers.add_parser('register-proxy')
|
2018-08-02 10:41:40 +02:00
|
|
|
parser_register_proxy.set_defaults(action='register-proxy')
|
|
|
|
parser_register_proxy.add_argument('app', help='Application name')
|
|
|
|
|
2018-10-27 21:13:35 +02:00
|
|
|
parser_unregister_proxy = subparsers.add_parser('unregister-proxy')
|
2018-08-02 10:41:40 +02:00
|
|
|
parser_unregister_proxy.set_defaults(action='unregister-proxy')
|
|
|
|
parser_unregister_proxy.add_argument('app', help='Application name')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
2018-09-04 21:42:26 +02:00
|
|
|
mgr = VMMgr()
|
2018-10-31 22:27:17 +01:00
|
|
|
if args.action == 'update-login':
|
2018-10-27 21:13:35 +02:00
|
|
|
# Used by app install scripts
|
2018-08-02 10:41:40 +02:00
|
|
|
mgr.update_login(args.app, args.login, args.password)
|
2018-08-31 09:13:18 +02:00
|
|
|
elif args.action == 'rebuild-issue':
|
2018-10-27 21:13:35 +02:00
|
|
|
# Used on VM startup
|
2018-08-31 09:13:18 +02:00
|
|
|
mgr.rebuild_issue()
|
2018-09-21 16:21:55 +02:00
|
|
|
elif args.action == 'prepare-container':
|
2018-10-27 21:13:35 +02:00
|
|
|
# Used with LXC hooks
|
2018-09-21 16:21:55 +02:00
|
|
|
mgr.prepare_container()
|
2018-09-12 10:36:48 +02:00
|
|
|
elif args.action == 'register-container':
|
2018-10-27 21:13:35 +02:00
|
|
|
# Used with LXC hooks
|
2018-09-12 10:36:48 +02:00
|
|
|
mgr.register_container()
|
|
|
|
elif args.action == 'unregister-container':
|
2018-10-27 21:13:35 +02:00
|
|
|
# Used with LXC hooks
|
2018-09-12 10:36:48 +02:00
|
|
|
mgr.unregister_container()
|
2018-08-02 10:41:40 +02:00
|
|
|
elif args.action == 'register-proxy':
|
2018-10-27 21:13:35 +02:00
|
|
|
# Used in init scripts
|
2018-08-02 10:41:40 +02:00
|
|
|
mgr.register_proxy(args.app)
|
|
|
|
elif args.action == 'unregister-proxy':
|
2018-10-27 21:13:35 +02:00
|
|
|
# Used in init scripts
|
2018-08-02 10:41:40 +02:00
|
|
|
mgr.unregister_proxy(args.app)
|