@@ -49,9 +49,17 @@ def init_devices(self):
4949 self ._init_devices ()
5050 self ._devices_inited = True
5151
52- @property
53- def name (self ):
54- return self .__class__ .__module__ .split ("." )[- 1 ].split ("_" , 1 )[1 ]
52+ @classmethod
53+ def name (cls ):
54+ return cls .__module__ .split ("." )[- 1 ].split ("_" , 1 )[1 ]
55+
56+ @classmethod
57+ def supports_static_tuning (cls ):
58+ raise NotImplementedError ()
59+
60+ @classmethod
61+ def supports_dynamic_tuning (cls ):
62+ raise NotImplementedError ()
5563
5664 #
5765 # Plugin configuration manipulation and helpers.
@@ -74,8 +82,10 @@ def _get_config_options_used_by_dynamic(self):
7482
7583 def _get_effective_options (self , options ):
7684 """Merge provided options with plugin default options."""
77- # TODO: _has_dynamic_options is a hack
7885 effective = self ._get_config_options ().copy ()
86+ if self .supports_dynamic_tuning ():
87+ effective ["dynamic" ] = True
88+ # TODO: _has_dynamic_options is a hack
7989 for key in options :
8090 if key in effective or self ._has_dynamic_options :
8191 effective [key ] = options [key ]
@@ -119,13 +129,13 @@ def destroy_instance(self, instance):
119129
120130 def initialize_instance (self , instance ):
121131 """Initialize an instance."""
122- log .debug ("initializing instance %s (%s)" % (instance .name , self .name ))
132+ log .debug ("initializing instance %s (%s)" % (instance .name , self .name () ))
123133 self ._instance_init (instance )
124134
125135 def destroy_instances (self ):
126136 """Destroy all instances."""
127137 for instance in list (self ._instances .values ()):
128- log .debug ("destroying instance %s (%s)" % (instance .name , self .name ))
138+ log .debug ("destroying instance %s (%s)" % (instance .name , self .name () ))
129139 self ._destroy_instance (instance )
130140 self ._instances .clear ()
131141
@@ -134,10 +144,13 @@ def _destroy_instance(self, instance):
134144 self ._instance_cleanup (instance )
135145
136146 def _instance_init (self , instance ):
137- raise NotImplementedError ()
147+ instance ._static_tuning_enabled = self .supports_static_tuning ()
148+ instance ._dynamic_tuning_enabled = self .supports_dynamic_tuning () \
149+ and self .__class__ in self ._global_cfg .get (consts .CFG_DYNAMIC_PLUGINS ) \
150+ and self ._option_bool (instance .options ["dynamic" ])
138151
139152 def _instance_cleanup (self , instance ):
140- raise NotImplementedError ()
153+ pass
141154
142155 #
143156 # Devices handling
@@ -159,7 +172,7 @@ def _get_matching_devices(self, instance, devices):
159172 else :
160173 udev_devices = self ._get_device_objects (devices )
161174 if udev_devices is None :
162- log .error ("Plugin '%s' does not support the 'devices_udev_regex' option" , self .name )
175+ log .error ("Plugin '%s' does not support the 'devices_udev_regex' option" , self .name () )
163176 return set ()
164177 udev_devices = self ._device_matcher_udev .match_list (instance .devices_udev_regex , udev_devices )
165178 return set ([x .sys_name for x in udev_devices ])
@@ -175,8 +188,8 @@ def assign_free_devices(self, instance):
175188 log .warn ("instance %s: no matching devices available" % instance .name )
176189 else :
177190 name = instance .name
178- if instance .name != self .name :
179- name += " (%s)" % self .name
191+ if instance .name != self .name () :
192+ name += " (%s)" % self .name ()
180193 log .info ("instance %s: assigning devices %s" % (name , ", " .join (to_assign )))
181194 instance .assigned_devices .update (to_assign ) # cannot use |=
182195 self ._assigned_devices |= to_assign
@@ -255,15 +268,15 @@ def instance_apply_tuning(self, instance):
255268 if not instance .active :
256269 return
257270
258- if instance .has_static_tuning :
271+ if instance .static_tuning_enabled :
259272 self ._call_device_script (instance , instance .script_pre ,
260273 "apply" , instance .assigned_devices )
261274 self ._instance_pre_static (instance , True )
262275 self ._instance_apply_static (instance )
263276 self ._instance_post_static (instance , True )
264277 self ._call_device_script (instance , instance .script_post ,
265278 "apply" , instance .assigned_devices )
266- if instance .has_dynamic_tuning and self . _global_cfg . get ( consts . CFG_DYNAMIC_TUNING , consts . CFG_DEF_DYNAMIC_TUNING ) :
279+ if instance .dynamic_tuning_enabled :
267280 self ._instance_init_dynamic (instance )
268281 self ._run_for_each_device (instance , self ._instance_apply_dynamic , instance .assigned_devices )
269282 instance .processed_devices .update (instance .assigned_devices )
@@ -280,7 +293,7 @@ def instance_verify_tuning(self, instance, ignore_missing):
280293 log .error ("BUG: Some devices have not been tuned: %s"
281294 % ", " .join (instance .assigned_devices ))
282295 devices = instance .processed_devices .copy ()
283- if instance .has_static_tuning :
296+ if instance .static_tuning_enabled :
284297 if self ._call_device_script (instance , instance .script_pre , "verify" , devices ) == False :
285298 return False
286299 if self ._instance_verify_static (instance , ignore_missing , devices ) == False :
@@ -297,7 +310,7 @@ def instance_update_tuning(self, instance):
297310 """
298311 if not instance .active :
299312 return
300- if instance .has_dynamic_tuning and self . _global_cfg . get ( consts . CFG_DYNAMIC_TUNING , consts . CFG_DEF_DYNAMIC_TUNING ) :
313+ if instance .dynamic_tuning_enabled :
301314 self ._run_for_each_device (instance , self ._instance_update_dynamic , instance .processed_devices .copy ())
302315
303316 def instance_unapply_tuning (self , instance , rollback = consts .ROLLBACK_SOFT ):
@@ -307,9 +320,9 @@ def instance_unapply_tuning(self, instance, rollback = consts.ROLLBACK_SOFT):
307320 if rollback == consts .ROLLBACK_NONE :
308321 return
309322
310- if instance .has_dynamic_tuning and self . _global_cfg . get ( consts . CFG_DYNAMIC_TUNING , consts . CFG_DEF_DYNAMIC_TUNING ) :
323+ if instance .dynamic_tuning_enabled :
311324 self ._run_for_each_device (instance , self ._instance_unapply_dynamic , instance .processed_devices )
312- if instance .has_static_tuning :
325+ if instance .static_tuning_enabled :
313326 self ._call_device_script (instance , instance .script_post ,
314327 "unapply" , instance .processed_devices ,
315328 rollback = rollback )
@@ -345,7 +358,7 @@ def _instance_apply_dynamic(self, instance, device):
345358 self ._instance_update_dynamic (instance , device )
346359
347360 def _instance_unapply_dynamic (self , instance , device ):
348- raise NotImplementedError ()
361+ pass
349362
350363 def _instance_update_dynamic (self , instance , device ):
351364 raise NotImplementedError ()
0 commit comments