(name, args)
| 445 | |
| 446 | |
| 447 | def main_init(name, args): |
| 448 | deps = [sources.DEP_FILESYSTEM, sources.DEP_NETWORK] |
| 449 | if args.local: |
| 450 | deps = [sources.DEP_FILESYSTEM] |
| 451 | |
| 452 | early_logs = [ |
| 453 | attempt_cmdline_url( |
| 454 | path=os.path.join( |
| 455 | "%s.d" % CLOUD_CONFIG, "91_kernel_cmdline_url.cfg" |
| 456 | ), |
| 457 | network=not args.local, |
| 458 | ) |
| 459 | ] |
| 460 | |
| 461 | # Cloud-init 'init' stage is broken up into the following sub-stages |
| 462 | # 1. Ensure that the init object fetches its config without errors |
| 463 | # 2. Setup logging/output redirections with resultant config (if any) |
| 464 | # 3. Initialize the cloud-init filesystem |
| 465 | # 4. Check if we can stop early by looking for various files |
| 466 | # 5. Fetch the datasource |
| 467 | # 6. Connect to the current instance location + update the cache |
| 468 | # 7. Consume the userdata (handlers get activated here) |
| 469 | # 8. Construct the modules object |
| 470 | # 9. Adjust any subsequent logging/output redirections using the modules |
| 471 | # objects config as it may be different from init object |
| 472 | # 10. Run the modules for the 'init' stage |
| 473 | # 11. Done! |
| 474 | bootstage_name = "init-local" if args.local else "init" |
| 475 | w_msg = welcome_format(bootstage_name) |
| 476 | init = stages.Init(ds_deps=deps, reporter=args.reporter) |
| 477 | # Stage 1 |
| 478 | init.read_cfg(extract_fns(args)) |
| 479 | # Stage 2 |
| 480 | outfmt = None |
| 481 | errfmt = None |
| 482 | try: |
| 483 | if not args.skip_log_setup: |
| 484 | close_stdin(lambda msg: early_logs.append((logging.DEBUG, msg))) |
| 485 | outfmt, errfmt = util.fixup_output(init.cfg, name) |
| 486 | else: |
| 487 | outfmt, errfmt = util.get_output_cfg(init.cfg, name) |
| 488 | except Exception: |
| 489 | msg = "Failed to setup output redirection!" |
| 490 | util.logexc(LOG, msg) |
| 491 | print_exc(msg) |
| 492 | early_logs.append((logging.WARN, msg)) |
| 493 | if args.debug: |
| 494 | # Reset so that all the debug handlers are closed out |
| 495 | LOG.debug( |
| 496 | "Logging being reset, this logger may no longer be active shortly" |
| 497 | ) |
| 498 | loggers.reset_logging() |
| 499 | if not args.skip_log_setup: |
| 500 | loggers.setup_logging(init.cfg) |
| 501 | apply_reporting_cfg(init.cfg) |
| 502 | |
| 503 | # Any log usage prior to setup_logging above did not have local user log |
| 504 | # config applied. We send the welcome message now, as stderr/out have |
nothing calls this directly
no test coverage detected