@@ -34,7 +34,7 @@ def add_arguments(self, parser):
3434
3535 def handle (self , * args , ** options ):
3636
37- def _run_script ():
37+ def _run_script (script ):
3838 """
3939 Core script execution task. We capture this within a subfunction to allow for conditionally wrapping it with
4040 the event_tracking context manager (which is bypassed if commit == False).
@@ -85,7 +85,6 @@ def _run_script():
8585
8686 module_name , script_name = script .split ('.' , 1 )
8787 module , script = get_module_and_script (module_name , script_name )
88- script = script .python_class
8988
9089 # Take user from command line if provided and exists, other
9190 if options ['user' ]:
@@ -102,7 +101,7 @@ def _run_script():
102101 stdouthandler .setLevel (logging .DEBUG )
103102 stdouthandler .setFormatter (formatter )
104103
105- logger = logging .getLogger (f"netbox.scripts.{ script .full_name } " )
104+ logger = logging .getLogger (f"netbox.scripts.{ script .python_class . full_name } " )
106105 logger .addHandler (stdouthandler )
107106
108107 try :
@@ -118,13 +117,13 @@ def _run_script():
118117 raise CommandError (f"Invalid log level: { loglevel } " )
119118
120119 # Initialize the script form
121- script = script ()
122- form = script .as_form (data , None )
120+ script_instance = script . python_class ()
121+ form = script_instance .as_form (data , None )
123122
124123 # Create the job
125124 job = Job .objects .create (
126- object = module ,
127- name = script .class_name ,
125+ object = script ,
126+ name = script_instance .class_name ,
128127 user = user ,
129128 job_id = uuid .uuid4 ()
130129 )
@@ -149,7 +148,7 @@ def _run_script():
149148 # Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process
150149 # change logging, webhooks, etc.
151150 with event_tracking (request ):
152- _run_script ()
151+ _run_script (script_instance )
153152 else :
154153 logger .error ('Data is not valid:' )
155154 for field , errors in form .errors .get_json_data ().items ():
0 commit comments