Rework vmmgr un/register-app script

This commit is contained in:
Disassembler 2020-04-04 13:39:37 +02:00
parent 5265b31504
commit 0209d4eb5b
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -5,50 +5,42 @@ import argparse
from vmmgr import config, vmmgr from vmmgr import config, vmmgr
def main(args): def register_app(app, host, login, password):
if args.action == 'register-app':
# Used by package install.sh script # Used by package install.sh script
vmmgr.register_app(args.app, args.host, args.login, args.password) vmmgr.register_app(app, host, login, password)
elif args.action == 'unregister-app':
def unregister_app(app):
# Used by package uninstall.sh script # Used by package uninstall.sh script
vmmgr.unregister_app(args.app) vmmgr.unregister_app(app)
elif args.action == 'rebuild-issue':
def rebuild_issue():
# Used by inittab on VM startup # Used by inittab on VM startup
vmmgr.rebuild_issue() vmmgr.rebuild_issue()
elif args.action == 'register-proxy':
# Used in init scripts on application startup
vmmgr.register_proxy(args.app)
elif args.action == 'unregister-proxy':
# Used in init scripts on application stop
vmmgr.unregister_proxy(args.app)
parser = argparse.ArgumentParser(description='VM application manager') parser = argparse.ArgumentParser(description='VM application manager')
parser.set_defaults(action=None)
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
parser_register_app = subparsers.add_parser('register-app') parser_register_app = subparsers.add_parser('register-app')
parser_register_app.set_defaults(action='register-app') parser_register_app.set_defaults(action=register_app)
parser_register_app.add_argument('app', help='Application name') parser_register_app.add_argument('app', help='Application name')
parser_register_app.add_argument('host', help='Application subdomain') parser_register_app.add_argument('host', help='Application subdomain')
parser_register_app.add_argument('login', nargs='?', help='Admin login') parser_register_app.add_argument('login', nargs='?', help='Admin login')
parser_register_app.add_argument('password', nargs='?', help='Admin password') parser_register_app.add_argument('password', nargs='?', help='Admin password')
parser_unregister_app = subparsers.add_parser('unregister-app') parser_unregister_app = subparsers.add_parser('unregister-app')
parser_unregister_app.set_defaults(action='unregister-app') parser_unregister_app.set_defaults(action=unregister_app)
parser_unregister_app.add_argument('app', help='Application name') parser_unregister_app.add_argument('app', help='Application name')
parser_rebuild_issue = subparsers.add_parser('rebuild-issue') parser_rebuild_issue = subparsers.add_parser('rebuild-issue')
parser_rebuild_issue.set_defaults(action='rebuild-issue') parser_rebuild_issue.set_defaults(action=rebuild_issue)
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_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() args = parser.parse_args()
if hasattr(args, 'action'): if args.action is register_app:
main(args) register_app(args.app, args.host, args.login, args.password)
elif args.action is unregister_app:
unregister_app(args.app)
elif args.action is rebuild_issue:
rebuild_issue()
else: else:
parser.print_usage() parser.print_usage()