66 lines
2.6 KiB
Python
Executable File
66 lines
2.6 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import argparse
|
|
from vmmgr import Config, LXCMgr, VMMgr
|
|
|
|
parser = argparse.ArgumentParser(description='VM application manager')
|
|
subparsers = parser.add_subparsers()
|
|
|
|
parser_register_app = subparsers.add_parser('register-app')
|
|
parser_register_app.set_defaults(action='register-app')
|
|
parser_register_app.add_argument('app', help='Application name')
|
|
parser_register_app.add_argument('host', help='Application subdomain')
|
|
parser_register_app.add_argument('login', nargs='?', help='Admin login')
|
|
parser_register_app.add_argument('password', nargs='?', help='Admin password')
|
|
|
|
parser_rebuild_issue = subparsers.add_parser('rebuild-issue')
|
|
parser_rebuild_issue.set_defaults(action='rebuild-issue')
|
|
|
|
parser_prepare_container = subparsers.add_parser('prepare-container')
|
|
parser_prepare_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
|
parser_prepare_container.set_defaults(action='prepare-container')
|
|
|
|
parser_register_container = subparsers.add_parser('register-container')
|
|
parser_register_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
|
parser_register_container.set_defaults(action='register-container')
|
|
|
|
parser_unregister_container = subparsers.add_parser('unregister-container')
|
|
parser_unregister_container.add_argument('lxc', nargs=argparse.REMAINDER)
|
|
parser_unregister_container.set_defaults(action='unregister-container')
|
|
|
|
parser_register_proxy = subparsers.add_parser('register-proxy')
|
|
parser_register_proxy.set_defaults(action='register-proxy')
|
|
parser_register_proxy.add_argument('app', help='Application name')
|
|
parser_register_proxy.add_argument('host', help='Application subdomain')
|
|
|
|
parser_unregister_proxy = subparsers.add_parser('unregister-proxy')
|
|
parser_unregister_proxy.set_defaults(action='unregister-proxy')
|
|
parser_unregister_proxy.add_argument('app', help='Application name')
|
|
|
|
args = parser.parse_args()
|
|
conf = Config()
|
|
vmmgr = VMMgr(conf)
|
|
lxcmgr = LXCMgr(conf)
|
|
if args.action == 'register-app':
|
|
# Used by app install scripts
|
|
vmmgr.register_app(args.app, args.host, args.login, args.password)
|
|
elif args.action == 'rebuild-issue':
|
|
# Used on VM startup
|
|
vmmgr.rebuild_issue()
|
|
elif args.action == 'prepare-container':
|
|
# Used with LXC hooks
|
|
lxcmgr.prepare_container()
|
|
elif args.action == 'register-container':
|
|
# Used with LXC hooks
|
|
lxcmgr.register_container()
|
|
elif args.action == 'unregister-container':
|
|
# Used with LXC hooks
|
|
lxcmgr.unregister_container()
|
|
elif args.action == 'register-proxy':
|
|
# Used in init scripts
|
|
lxcmgr.register_proxy(args.app, args.host)
|
|
elif args.action == 'unregister-proxy':
|
|
# Used in init scripts
|
|
lxcmgr.unregister_proxy(args.app)
|