<s> import functools <EOL> import re <EOL> from oslo_log import log as oslo_logging <EOL> from cloudbaseinit . plugins . common import execcmd <EOL> LOG = oslo_logging . getLogger ( __name__ ) <EOL> _compile = functools . partial ( re . compile , flags = re . I ) <EOL> FORMATS = ( <EOL> ( _compile ( br'<STR_LIT>' ) , execcmd . Shell ) , <EOL> ( _compile ( br'<STR_LIT>' ) , execcmd . Python ) , <EOL> ( _compile ( br'<STR_LIT>' ) , execcmd . Bash ) , <EOL> ( _compile ( br'<STR_LIT>' ) , execcmd . PowershellSysnative ) , <EOL> ( _compile ( br'<STR_LIT>' ) , execcmd . Powershell ) , <EOL> ( _compile ( br'<STR_LIT>' ) , execcmd . EC2Config ) , <EOL> ) <EOL> del _compile <EOL> def _get_command ( data ) : <EOL> for pattern , command_class in FORMATS : <EOL> if pattern . search ( data ) : <EOL> return command_class . from_data ( data ) <EOL> def execute_user_data_script ( user_data ) : <EOL> ret_val = <NUM_LIT:0> <EOL> out = err = None <EOL> command = _get_command ( user_data ) <EOL> if not command : <EOL> LOG . warning ( '<STR_LIT>' ) <EOL> return ret_val <EOL> try : <EOL> out , err , ret_val = command ( ) <EOL> except Exception as exc : <EOL> LOG . warning ( '<STR_LIT>' , <EOL> exc ) <EOL> else : <EOL> LOG . debug ( '<STR_LIT>' , out ) <EOL> LOG . debug ( '<STR_LIT>' , err ) <EOL> LOG . info ( '<STR_LIT>' , ret_val ) <EOL> return ret_val </s>
