<s> import abc <EOL> import importlib <EOL> import inspect <EOL> import six <EOL> from st2common import log as logging <EOL> from st2common . persistence import policy as policy_access <EOL> from st2common . services import coordination <EOL> LOG = logging . getLogger ( __name__ ) <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> @ six . add_metaclass ( abc . ABCMeta ) <EOL> class ResourcePolicyApplicator ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , policy_ref , policy_type , * args , ** kwargs ) : <EOL> self . _policy_ref = policy_ref <EOL> self . _policy_type = policy_type <EOL> def apply_before ( self , target ) : <EOL> """<STR_LIT>""" <EOL> if not coordination . configured ( ) : <EOL> LOG . warn ( '<STR_LIT>' ) <EOL> return target <EOL> def apply_after ( self , target ) : <EOL> """<STR_LIT>""" <EOL> if not coordination . configured ( ) : <EOL> LOG . warn ( '<STR_LIT>' ) <EOL> return target <EOL> def _get_lock_name ( self , values ) : <EOL> """<STR_LIT>""" <EOL> lock_uid = [ ] <EOL> for key , value in six . iteritems ( values ) : <EOL> lock_uid . append ( '<STR_LIT>' % ( key , value ) ) <EOL> lock_uid = '<STR_LIT:U+002C>' . join ( lock_uid ) <EOL> return lock_uid <EOL> def get_driver ( policy_ref , policy_type , ** parameters ) : <EOL> policy_type_db = policy_access . PolicyType . get_by_ref ( policy_type ) <EOL> module = importlib . import_module ( policy_type_db . module , package = None ) <EOL> for name , obj in inspect . getmembers ( module ) : <EOL> if inspect . isclass ( obj ) and issubclass ( obj , ResourcePolicyApplicator ) : <EOL> return obj ( policy_ref , policy_type , ** parameters ) </s>
