def launch_new(options, args): """ Boot a new launch plan. You must supply the path to a top level configuration file. A run name will be displayed in the output. See --help for more information. """ if len(args) < 2: print "The boot command requires a top level file. See --help" return 1 config_file = args[1] print_chars(1, "Starting up run ") print_chars(1, "%s\n" % (options.name), inverse=True, color="green", bold=True) cb = CloudInitD(options.database, log_level=options.loglevel, db_name=options.name, config_file=config_file, level_callback=level_callback, service_callback=service_callback, logdir=options.logdir, terminate=False, boot=True, ready=True, fail_if_db_present=True) print_chars(3, "Logging to: %s%s.log\n" % (options.logdir, options.name)) if options.validate: print_chars(1, "Validating the launch plan.\n") errors = cb.boot_validate() if len(errors) > 0: print_chars(0, "The boot plan is not valid.\n", color = "red") for (svc, ex) in errors: print_chars(1, "Service %s had the error:\n" % (svc.name)) print_chars(1, "\t%s" %(str(ex))) return 1 if options.dryrun: test_env = _getenv_or_none('CLOUDINITD_TESTENV') host_time_env = _getenv_or_none('CLOUDINITD_CBIAAS_TEST_HOSTNAME_TIME') fab_env = _getenv_or_none('CLOUDINITD_FAB') ssh_env = _getenv_or_none('CLOUDINITD_SSH') print_chars(1, "Performing a dry run...\n", bold=True) os.environ['CLOUDINITD_TESTENV'] = "2" os.environ['CLOUDINITD_CBIAAS_TEST_HOSTNAME_TIME'] = "0.0" os.environ['CLOUDINITD_FAB'] = cloudinitd.find_true() os.environ['CLOUDINITD_SSH'] = cloudinitd.find_true() try: (rc, cb) = _launch_new(options, args, cb) print_chars(1, "Dry run successful\n", bold=True, color="green") finally: _setenv_or_none('CLOUDINITD_TESTENV', test_env) _setenv_or_none('CLOUDINITD_CBIAAS_TEST_HOSTNAME_TIME', host_time_env) _setenv_or_none('CLOUDINITD_FAB', fab_env) _setenv_or_none('CLOUDINITD_SSH', ssh_env) if not options.noclean: path = "%s/cloudinitd-%s.db" % (options.database, cb.run_name) if not os.path.exists(path): raise Exception("That DB does not seem to exist: %s" % (path)) os.remove(path) return rc (rc, cb) = _launch_new(options, args, cb) return rc
def reload_conf(options, args): """ Reload an updated launch plan configuration into the database of the run name supplied with --name. This is typically followed by a repair of the same run name. """ if len(args) < 2: print "The reload command requires a top level file. See --help" return 1 config_file = args[1] print_chars(1, "Loading the launch plan for run ") print_chars(1, "%s\n" % (options.name), inverse=True, color="green", bold=True) cb = CloudInitD(options.database, log_level=options.loglevel, db_name=options.name, config_file=config_file, level_callback=level_callback, service_callback=service_callback, logdir=options.logdir, fail_if_db_present=False, terminate=False, boot=False, ready=False) if options.validate: print_chars(1, "Validating the launch plan.\n") errors = cb.boot_validate() if len(errors) > 0: print_chars(0, "The boot plan is not valid.\n", color = "red") for (svc, ex) in errors: print_chars(1, "Service %s had the error:\n" % (svc.name)) print_chars(1, "\t%s" %(str(ex))) return 1 return 0