#NEWLINE# def pkg( pkg_path , pkg_sum , hash_type , test = False , **kwargs ) : #NEWLINE# #INDENT# "\n    Execute a packaged state run, the packaged state run will exist in a\n    tarball available locally. This packaged state\n    can be generated using salt-ssh.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' state.pkg /tmp/state_pkg.tgz\n    " #NEWLINE# if ( not os . path . isfile ( pkg_path ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( not ( salt . utils . get_hash ( pkg_path , hash_type ) == pkg_sum ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# root = tempfile . mkdtemp ( ) #NEWLINE# s_pkg = tarfile . open ( pkg_path , 'r:gz' ) #NEWLINE# members = s_pkg . getmembers ( ) #NEWLINE# for member in members : #NEWLINE# #INDENT# if member . path . startswith ( ( os . sep , '..{0}' . format ( os . sep ) ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( '..{0}' . format ( os . sep ) in member . path ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# s_pkg . extractall ( root ) #NEWLINE# s_pkg . close ( ) #NEWLINE# lowstate_json = os . path . join ( root , 'lowstate.json' ) #NEWLINE# with salt . utils . fopen ( lowstate_json , 'r' ) as fp_ : #NEWLINE# #INDENT# lowstate = json . load ( fp_ , object_hook = salt . utils . decode_dict ) #NEWLINE# #UNINDENT# for chunk in lowstate : #NEWLINE# #INDENT# if ( not isinstance ( chunk , dict ) ) : #NEWLINE# #INDENT# return lowstate #NEWLINE# #UNINDENT# #UNINDENT# pillar_json = os . path . join ( root , 'pillar.json' ) #NEWLINE# if os . path . isfile ( pillar_json ) : #NEWLINE# #INDENT# with salt . utils . fopen ( pillar_json , 'r' ) as fp_ : #NEWLINE# #INDENT# pillar = json . load ( fp_ ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# pillar = None #NEWLINE# #UNINDENT# popts = _get_opts ( kwargs . get ( 'localconfig' ) ) #NEWLINE# popts [ 'fileclient' ] = 'local' #NEWLINE# popts [ 'file_roots' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if salt . utils . test_mode ( test = test , ** lowstate_json ) : #NEWLINE# #INDENT# popts [ 'test' ] = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# popts [ 'test' ] = __opts__ . get ( 'test' , None ) #NEWLINE# #UNINDENT# envs = os . listdir ( root ) #NEWLINE# for fn_ in envs : #NEWLINE# #INDENT# full = os . path . join ( root , fn_ ) #NEWLINE# if ( not os . path . isdir ( full ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# popts [ 'file_roots' ] [ fn_ ] = [ full ] #NEWLINE# #UNINDENT# st_ = salt . state . State ( popts , pillar = pillar ) #NEWLINE# ret = st_ . call_chunks ( lowstate ) #NEWLINE# try : #NEWLINE# #INDENT# shutil . rmtree ( root ) #NEWLINE# #UNINDENT# except ( IOError , OSError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return ret