(action_name, args)
| 743 | |
| 744 | |
| 745 | def main_modules(action_name, args): |
| 746 | name = args.mode |
| 747 | # Cloud-init 'modules' stages are broken up into the following sub-stages |
| 748 | # 1. Ensure that the init object fetches its config without errors |
| 749 | # 2. Get the datasource from the init object, if it does |
| 750 | # not exist then that means the main_init stage never |
| 751 | # worked, and thus this stage can not run. |
| 752 | # 3. Construct the modules object |
| 753 | # 4. Adjust any subsequent logging/output redirections using |
| 754 | # the modules objects configuration |
| 755 | # 5. Run the modules for the given stage name |
| 756 | # 6. Done! |
| 757 | bootstage_name = "%s:%s" % (action_name, name) |
| 758 | w_msg = welcome_format(bootstage_name) |
| 759 | init = stages.Init(ds_deps=[], reporter=args.reporter) |
| 760 | # Stage 1 |
| 761 | init.read_cfg(extract_fns(args)) |
| 762 | # Stage 2 |
| 763 | try: |
| 764 | init.fetch(existing="trust") |
| 765 | except sources.DataSourceNotFoundException: |
| 766 | # There was no datasource found, theres nothing to do |
| 767 | msg = ( |
| 768 | "Can not apply stage %s, no datasource found! Likely bad " |
| 769 | "things to come!" % name |
| 770 | ) |
| 771 | util.logexc(LOG, msg) |
| 772 | print_exc(msg) |
| 773 | if not args.force: |
| 774 | return [msg] |
| 775 | _maybe_persist_instance_data(init) |
| 776 | # Stage 3 |
| 777 | mods = Modules(init, extract_fns(args), reporter=args.reporter) |
| 778 | # Stage 4 |
| 779 | try: |
| 780 | if not args.skip_log_setup: |
| 781 | close_stdin() |
| 782 | util.fixup_output(mods.cfg, name) |
| 783 | except Exception: |
| 784 | util.logexc(LOG, "Failed to setup output redirection!") |
| 785 | if args.debug: |
| 786 | # Reset so that all the debug handlers are closed out |
| 787 | LOG.debug( |
| 788 | "Logging being reset, this logger may no longer be active shortly" |
| 789 | ) |
| 790 | loggers.reset_logging() |
| 791 | if not args.skip_log_setup: |
| 792 | loggers.setup_logging(mods.cfg) |
| 793 | apply_reporting_cfg(init.cfg) |
| 794 | |
| 795 | # now that logging is setup and stdout redirected, send welcome |
| 796 | welcome(name, msg=w_msg) |
| 797 | LOG.info("PID [%s] started cloud-init '%s'.", os.getppid(), bootstage_name) |
| 798 | |
| 799 | if name == "init": |
| 800 | lifecycle.deprecate( |
| 801 | deprecated="`--mode init`", |
| 802 | deprecated_version="24.1", |
nothing calls this directly
no test coverage detected