2014-11-25 21:12:37 +01:00
|
|
|
"""Main module containing all the setup necessary for running the remote bootstrapping process
|
|
|
|
"""
|
|
|
|
|
2014-11-25 20:14:56 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Main function for invoking the bootstrap process remotely
|
2014-11-25 21:12:37 +01:00
|
|
|
|
|
|
|
|
2014-11-25 20:14:56 +01:00
|
|
|
"""
|
|
|
|
# Get the commandline arguments
|
|
|
|
opts = get_opts()
|
|
|
|
|
|
|
|
# Load the manifest
|
|
|
|
from bootstrapvz.base.manifest import Manifest
|
|
|
|
manifest = Manifest(path=opts['MANIFEST'])
|
|
|
|
|
2014-11-25 21:12:37 +01:00
|
|
|
# Load the build servers
|
2014-11-25 20:14:56 +01:00
|
|
|
from bootstrapvz.common.tools import load_data
|
|
|
|
build_servers = load_data(opts['--servers'])
|
|
|
|
|
|
|
|
# Set up logging
|
|
|
|
from bootstrapvz.base.main import setup_loggers
|
|
|
|
setup_loggers(opts)
|
|
|
|
|
2014-11-25 21:12:37 +01:00
|
|
|
# Register deserialization handlers for objects
|
|
|
|
# that will pass between server and client
|
2014-11-25 20:14:56 +01:00
|
|
|
from . import register_deserialization_handlers
|
|
|
|
register_deserialization_handlers()
|
|
|
|
|
2014-11-25 21:12:37 +01:00
|
|
|
# Everything has been set up, connect to the server and begin the bootstrapping process
|
|
|
|
run(manifest,
|
|
|
|
build_servers[opts['SERVER']],
|
|
|
|
debug=opts['--debug'],
|
|
|
|
dry_run=opts['--dry-run'])
|
|
|
|
|
|
|
|
|
|
|
|
def get_opts():
|
|
|
|
"""Creates an argument parser and returns the arguments it has parsed
|
|
|
|
"""
|
|
|
|
from docopt import docopt
|
|
|
|
usage = """bootstrap-vz-remote
|
|
|
|
|
|
|
|
Usage: bootstrap-vz-remote [options] --servers=<path> SERVER MANIFEST
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--servers <path> Path to list of build servers
|
|
|
|
--log <path> Log to given directory [default: /var/log/bootstrap-vz]
|
|
|
|
If <path> is `-' file logging will be disabled.
|
|
|
|
--pause-on-error Pause on error, before rollback
|
|
|
|
--dry-run Don't actually run the tasks
|
|
|
|
--debug Print debugging information
|
|
|
|
-h, --help show this help
|
|
|
|
"""
|
|
|
|
return docopt(usage)
|
|
|
|
|
|
|
|
|
|
|
|
def run(manifest, server, debug=False, dry_run=False):
|
|
|
|
"""Connects to the remote build server, starts an RPC daemin
|
|
|
|
on the other side and initiates a remote bootstrapping procedure
|
|
|
|
"""
|
2014-11-25 20:14:56 +01:00
|
|
|
bootstrap_info = None
|
|
|
|
|
|
|
|
from ssh_rpc_manager import SSHRPCManager
|
2014-11-25 21:12:37 +01:00
|
|
|
manager = SSHRPCManager(server)
|
2014-11-25 20:14:56 +01:00
|
|
|
try:
|
2014-11-25 21:12:37 +01:00
|
|
|
# Connect to the build server and start the RPC daemon
|
2014-11-25 20:14:56 +01:00
|
|
|
manager.start()
|
|
|
|
server = manager.rpc_server
|
2014-11-25 21:12:37 +01:00
|
|
|
# Start a callback server on this side, so that we may receive log entries
|
2014-11-25 20:14:56 +01:00
|
|
|
from callback import CallbackServer
|
2014-11-25 20:43:04 +01:00
|
|
|
callback_server = CallbackServer(listen_port=manager.local_callback_port,
|
|
|
|
remote_port=manager.remote_callback_port)
|
2014-11-25 20:14:56 +01:00
|
|
|
from bootstrapvz.base.log import LogServer
|
|
|
|
log_server = LogServer()
|
|
|
|
try:
|
2014-11-25 21:12:37 +01:00
|
|
|
# Start the callback server (in a background thread)
|
2014-11-25 20:14:56 +01:00
|
|
|
callback_server.start(log_server)
|
2014-11-25 21:12:37 +01:00
|
|
|
# Tell the RPC daemon about the callback server
|
2014-11-25 20:14:56 +01:00
|
|
|
server.set_log_server(log_server)
|
|
|
|
|
|
|
|
# Everything has been set up, begin the bootstrapping process
|
|
|
|
bootstrap_info = server.run(manifest,
|
2014-11-25 21:12:37 +01:00
|
|
|
debug=debug,
|
|
|
|
# We can't pause the bootstrapping process remotely, yet...
|
2014-11-25 20:14:56 +01:00
|
|
|
pause_on_error=False,
|
2014-11-25 21:12:37 +01:00
|
|
|
dry_run=dry_run)
|
2014-11-25 20:14:56 +01:00
|
|
|
finally:
|
2014-11-25 21:12:37 +01:00
|
|
|
# Stop the callback server
|
2014-11-25 20:14:56 +01:00
|
|
|
callback_server.stop()
|
|
|
|
finally:
|
2014-11-25 21:12:37 +01:00
|
|
|
# Stop the RPC daemon and close the SSH connection
|
2014-11-25 20:14:56 +01:00
|
|
|
manager.stop()
|
|
|
|
return bootstrap_info
|