88
99from sqlalchemy import insert , select
1010
11- from wnm import __version__
12- from wnm .config import (
13- LOCK_FILE ,
14- S ,
15- apply_config_updates ,
16- config_updates ,
17- engine ,
18- machine_config ,
19- options ,
20- )
11+ from wnm import __version__ , config
12+ from wnm .config import LOCK_FILE , apply_config_updates
2113from wnm .decision_engine import DecisionEngine
2214from wnm .executor import ActionExecutor
2315from wnm .migration import detect_port_ranges_from_nodes , survey_machine
@@ -69,7 +61,7 @@ def signal_handler(signum, frame):
6961
7062
7163# Make a decision about what to do (new implementation using DecisionEngine)
72- def choose_action (machine_config , metrics , dry_run ):
64+ def choose_action (machine_config , metrics , dry_run , options , S ):
7365 """Plan and execute actions using DecisionEngine and ActionExecutor.
7466
7567 This function now acts as a thin wrapper around the new decision engine
@@ -79,6 +71,8 @@ def choose_action(machine_config, metrics, dry_run):
7971 machine_config: Machine configuration dictionary
8072 metrics: Current system metrics
8173 dry_run: If True, log actions without executing
74+ options: Parsed CLI options
75+ S: Database session factory
8276
8377 Returns:
8478 Dictionary with execution status
@@ -119,22 +113,22 @@ def choose_action(machine_config, metrics, dry_run):
119113 )
120114
121115 # Use the new DecisionEngine to plan actions
122- engine = DecisionEngine (
116+ de = DecisionEngine (
123117 machine_config ,
124118 metrics ,
125119 is_init = is_init ,
126120 should_survey_init = should_survey_init ,
127121 enable_upgrade = getattr (options , "enable_upgrade" , False ),
128122 )
129- actions = engine .plan_actions ()
123+ actions = de .plan_actions ()
130124
131125 # Log the computed features for debugging
132126 if (
133127 options .show_decisions
134128 or options .v
135129 or logging .getLogger ().isEnabledFor (logging .DEBUG )
136130 ):
137- logging .info (json .dumps (engine .get_features (), indent = 2 ))
131+ logging .info (json .dumps (de .get_features (), indent = 2 ))
138132
139133 # Inject transient action delay override into machine_config if provided
140134 # Priority: --interval takes precedence over --this_action_delay
@@ -155,6 +149,15 @@ def choose_action(machine_config, metrics, dry_run):
155149
156150
157151def main ():
152+ config .initialize ()
153+
154+ # Bind locals from config module (set by initialize())
155+ options = config .options
156+ S = config .S
157+ engine = config .engine
158+ machine_config = config .machine_config
159+ config_updates = config .config_updates
160+
158161 # Handle --version flag (before any lock file or database checks)
159162 if options .version :
160163 print (f"wnm version { __version__ } " )
@@ -443,7 +446,7 @@ def main():
443446 count = options .count if hasattr (options , "count" ) else 1 ,
444447 )
445448 else :
446- this_action = choose_action (local_config , metrics , options .dry_run )
449+ this_action = choose_action (local_config , metrics , options .dry_run , options , S )
447450
448451 logging .info ("Action: " + json .dumps (this_action , indent = 2 ))
449452
0 commit comments