@@ -19,7 +19,7 @@ class Plugin(object):
1919 Intentionally a lot of logic is included in the plugin to increase plugin flexibility.
2020 """
2121
22- def __init__ (self , monitors_repository , storage_factory , hardware_inventory , device_matcher , device_matcher_udev , instance_factory , global_cfg , variables ):
22+ def __init__ (self , monitors_repository , storage_factory , hardware_inventory , device_matcher , device_matcher_udev , instance_factory , global_cfg ):
2323 """Plugin constructor."""
2424
2525 self ._storage = storage_factory .create (self .__class__ .__name__ )
@@ -33,7 +33,6 @@ def __init__(self, monitors_repository, storage_factory, hardware_inventory, dev
3333 self ._init_commands ()
3434
3535 self ._global_cfg = global_cfg
36- self ._variables = variables
3736 self ._has_dynamic_options = False
3837 self ._devices_inited = False
3938
@@ -93,14 +92,14 @@ def _option_bool(self, value):
9392 # Interface for manipulation with instances of the plugin.
9493 #
9594
96- def create_instance (self , name , priority , devices_expression , devices_udev_regex , script_pre , script_post , options ):
95+ def create_instance (self , name , priority , devices_expression , devices_udev_regex , script_pre , script_post , options , variables ):
9796 """Create new instance of the plugin and seize the devices."""
9897 if name in self ._instances :
9998 raise Exception ("Plugin instance with name '%s' already exists." % name )
10099
101100 effective_options = self ._get_effective_options (options )
102101 instance = self ._instance_factory .create (self , name , priority , devices_expression , devices_udev_regex , \
103- script_pre , script_post , effective_options )
102+ script_pre , script_post , effective_options , variables )
104103 self ._instances [name ] = instance
105104 self ._instances = collections .OrderedDict (sorted (self ._instances .items (), key = lambda x : x [1 ].priority ))
106105
@@ -249,8 +248,8 @@ def _call_device_script(self, instance, script, op, devices, rollback = consts.R
249248 dir_name = os .path .dirname (script )
250249 ret = True
251250 for dev in devices :
252- environ = os .environ
253- environ .update (self ._variables .get_env ())
251+ environ = os .environ . copy ()
252+ environ .update (instance ._variables .get_env ())
254253 arguments = [op ]
255254 if rollback == consts .ROLLBACK_FULL :
256255 arguments .append ("full_rollback" )
@@ -459,13 +458,13 @@ def _storage_unset(self, instance, command, device_name=None):
459458
460459 def _execute_all_non_device_commands (self , instance ):
461460 for command in [command for command in list (self ._commands .values ()) if not command ["per_device" ]]:
462- new_value = self ._variables .expand (instance .options .get (command ["name" ], None ))
461+ new_value = instance ._variables .expand (instance .options .get (command ["name" ], None ))
463462 if new_value is not None :
464463 self ._execute_non_device_command (instance , command , new_value )
465464
466465 def _execute_all_device_commands (self , instance , devices ):
467466 for command in [command for command in list (self ._commands .values ()) if command ["per_device" ]]:
468- new_value = self ._variables .expand (instance .options .get (command ["name" ], None ))
467+ new_value = instance ._variables .expand (instance .options .get (command ["name" ], None ))
469468 if new_value is None :
470469 continue
471470 for device in devices :
@@ -474,7 +473,7 @@ def _execute_all_device_commands(self, instance, devices):
474473 def _verify_all_non_device_commands (self , instance , ignore_missing ):
475474 ret = True
476475 for command in [command for command in list (self ._commands .values ()) if not command ["per_device" ]]:
477- new_value = self ._variables .expand (instance .options .get (command ["name" ], None ))
476+ new_value = instance ._variables .expand (instance .options .get (command ["name" ], None ))
478477 if new_value is not None :
479478 if self ._verify_non_device_command (instance , command , new_value , ignore_missing ) == False :
480479 ret = False
@@ -483,7 +482,7 @@ def _verify_all_non_device_commands(self, instance, ignore_missing):
483482 def _verify_all_device_commands (self , instance , devices , ignore_missing ):
484483 ret = True
485484 for command in [command for command in list (self ._commands .values ()) if command ["per_device" ]]:
486- new_value = self ._variables .expand (instance .options .get (command ["name" ], None ))
485+ new_value = instance ._variables .expand (instance .options .get (command ["name" ], None ))
487486 if new_value is None :
488487 continue
489488 for device in devices :
0 commit comments