#NEWLINE# def _run_wrapper( status , container , func , cmd , * args , **kwargs ) : #NEWLINE# #INDENT# '\n    Wrapper to a cmdmod function\n\n    Idea is to prefix the call to cmdrun with the relevant driver to\n    execute inside a container context\n\n    .. note::\n\n        Only lxc and native drivers are implemented.\n\n    status\n        status object\n    container\n        container id to execute in\n    func\n        cmd function to execute\n    cmd\n        command to execute in the container\n    ' #NEWLINE# client = _get_client ( ) #NEWLINE# driver = client . info ( ) . get ( 'ExecutionDriver' , 'lxc-' ) #NEWLINE# container_info = _get_container_infos ( container ) #NEWLINE# container_id = container_info [ 'Id' ] #NEWLINE# if driver . startswith ( 'lxc-' ) : #NEWLINE# #INDENT# full_cmd = 'lxc-attach -n {0} -- {1}' . format ( container_id , cmd ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if driver . startswith ( 'native-' ) : #NEWLINE# #INDENT# if HAS_NSENTER : #NEWLINE# #INDENT# container_pid = container_info [ 'State' ] [ 'Pid' ] #NEWLINE# if ( container_pid == 0 ) : #NEWLINE# #INDENT# _invalid ( status , id_ = container , comment = 'Container is not running' ) #NEWLINE# return status #NEWLINE# #UNINDENT# full_cmd = 'nsenter --target {pid} --mount --uts --ipc --net --pid -- {cmd}' . format ( pid = container_pid , cmd = cmd ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise CommandExecutionError ( 'nsenter is not installed on the minion, cannot run command' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise NotImplementedError ( "Unknown docker ExecutionDriver '{0}'. Or didn't find command to attach to the container" . format ( driver ) ) #NEWLINE# #UNINDENT# #UNINDENT# comment = 'Executed {0}' . format ( full_cmd ) #NEWLINE# try : #NEWLINE# #INDENT# ret = __salt__ [ func ] ( full_cmd , * args , ** kwargs ) #NEWLINE# if ( ( isinstance ( ret , dict ) and ( 'retcode' in ret ) and ( ret [ 'retcode' ] != 0 ) ) or ( ( func == 'cmd.retcode' ) and ( ret != 0 ) ) ) : #NEWLINE# #INDENT# _invalid ( status , id_ = container , out = ret , comment = comment ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _valid ( status , id_ = container , out = ret , comment = comment ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# _invalid ( status , id_ = container , comment = comment , out = traceback . format_exc ( ) ) #NEWLINE# #UNINDENT# return status