<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import os <EOL> import stat <EOL> import logging <EOL> from salt . utils . odict import OrderedDict <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in __salt__ : <EOL> return True <EOL> else : <EOL> return ( <EOL> False , <EOL> '<STR_LIT>' . format ( <EOL> __virtualname__ <EOL> ) <EOL> ) <EOL> def _check_device ( device , config ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT:/>' not in device and config [ '<STR_LIT>' ] and os . path . exists ( config [ '<STR_LIT>' ] ) : <EOL> device = os . path . join ( config [ '<STR_LIT>' ] , device ) <EOL> if not os . path . exists ( device ) : <EOL> return False , '<STR_LIT>' <EOL> else : <EOL> mode = os . stat ( device ) . st_mode <EOL> if not stat . S_ISBLK ( mode ) and not stat . S_ISREG ( mode ) and not stat . S_ISCHR ( mode ) : <EOL> return False , '<STR_LIT>' <EOL> return True , '<STR_LIT>' <EOL> def present ( name , properties = None , filesystem_properties = None , layout = None , config = None ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> state_config = config if config else { } <EOL> config = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None if __grains__ [ '<STR_LIT>' ] != '<STR_LIT>' else '<STR_LIT>' , <EOL> '<STR_LIT>' : False <EOL> } <EOL> config . update ( state_config ) <EOL> log . debug ( '<STR_LIT>' . format ( name , config ) ) <EOL> if layout : <EOL> layout_valid = True <EOL> layout_result = { } <EOL> for root_dev in layout : <EOL> if '<STR_LIT:->' in root_dev : <EOL> if root_dev . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> layout_valid = False <EOL> layout_result [ root_dev ] = '<STR_LIT>' <EOL> layout [ root_dev ] = layout [ root_dev ] . keys ( ) if isinstance ( layout [ root_dev ] , OrderedDict ) else layout [ root_dev ] . split ( '<STR_LIT:U+0020>' ) <EOL> for dev in layout [ root_dev ] : <EOL> dev_info = _check_device ( dev , config ) <EOL> if not dev_info [ <NUM_LIT:0> ] : <EOL> layout_valid = False <EOL> layout_result [ root_dev ] = { } <EOL> layout_result [ root_dev ] [ dev ] = dev_info [ <NUM_LIT:1> ] <EOL> else : <EOL> dev_info = _check_device ( root_dev , config ) <EOL> if not dev_info [ <NUM_LIT:0> ] : <EOL> layout_valid = False <EOL> layout_result [ root_dev ] = dev_info [ <NUM_LIT:1> ] <EOL> if not layout_valid : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> ret [ '<STR_LIT>' ] = "<STR_LIT>" . format ( layout_result ) <EOL> return ret <EOL> log . debug ( '<STR_LIT>' . format ( name , layout ) ) <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> if __salt__ [ '<STR_LIT>' ] ( name ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> properties_current = __salt__ [ '<STR_LIT>' ] ( name ) [ name ] <EOL> properties_update = [ ] <EOL> for prop in properties : <EOL> if prop not in properties_current : <EOL> continue <EOL> value = properties [ prop ] <EOL> if isinstance ( value , bool ) : <EOL> value = '<STR_LIT>' if value else '<STR_LIT>' <EOL> if properties_current [ prop ] != value : <EOL> properties_update . append ( prop ) <EOL> for prop in properties_update : <EOL> value = properties [ prop ] <EOL> res = __salt__ [ '<STR_LIT>' ] ( name , prop , value ) <EOL> if isinstance ( value , bool ) : <EOL> value = '<STR_LIT>' if value else '<STR_LIT>' <EOL> elif '<STR_LIT:U+0020>' in value : <EOL> value = "<STR_LIT>" . format ( value ) <EOL> if name in res and prop in res [ name ] and res [ name ] [ prop ] == value : <EOL> if name not in ret [ '<STR_LIT>' ] : <EOL> ret [ '<STR_LIT>' ] [ name ] = { } <EOL> ret [ '<STR_LIT>' ] [ name ] . update ( res [ name ] ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> if ret [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( ret [ '<STR_LIT>' ] , prop ) <EOL> if ret [ '<STR_LIT:result>' ] : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' if len ( ret [ '<STR_LIT>' ] ) > <NUM_LIT:0> else '<STR_LIT>' <EOL> else : <EOL> if config [ '<STR_LIT>' ] : <EOL> log . debug ( '<STR_LIT>' . format ( name ) ) <EOL> ret [ '<STR_LIT:result>' ] = __salt__ [ '<STR_LIT>' ] ( <EOL> name , <EOL> force = config [ '<STR_LIT>' ] , <EOL> dir = config [ '<STR_LIT>' ] <EOL> ) <EOL> ret [ '<STR_LIT:result>' ] = ret [ '<STR_LIT:result>' ] . get ( name ) == '<STR_LIT>' <EOL> if ret [ '<STR_LIT:result>' ] : <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> if not ret [ '<STR_LIT:result>' ] : <EOL> if not layout : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> else : <EOL> log . debug ( '<STR_LIT>' . format ( name ) ) <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> else : <EOL> params = [ ] <EOL> params . append ( name ) <EOL> for root_dev in layout : <EOL> if '<STR_LIT:->' in root_dev : <EOL> params . append ( root_dev . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] ) <EOL> if root_dev . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> for sub_dev in layout [ root_dev ] : <EOL> if '<STR_LIT:/>' not in sub_dev and config [ '<STR_LIT>' ] and os . path . exists ( config [ '<STR_LIT>' ] ) : <EOL> sub_dev = os . path . join ( config [ '<STR_LIT>' ] , sub_dev ) <EOL> params . append ( sub_dev ) <EOL> else : <EOL> if '<STR_LIT:/>' not in root_dev and config [ '<STR_LIT>' ] and os . path . exists ( config [ '<STR_LIT>' ] ) : <EOL> root_dev = os . path . join ( config [ '<STR_LIT>' ] , root_dev ) <EOL> params . append ( root_dev ) <EOL> ret [ '<STR_LIT:result>' ] = __salt__ [ '<STR_LIT>' ] ( * params , force = config [ '<STR_LIT>' ] , properties = properties , filesystem_properties = filesystem_properties ) <EOL> if ret [ '<STR_LIT:result>' ] . get ( name ) == '<STR_LIT>' : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> else : <EOL> if ret [ '<STR_LIT:result>' ] . get ( name ) : <EOL> ret [ '<STR_LIT>' ] = ret [ '<STR_LIT:result>' ] [ name ] <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> if ret [ '<STR_LIT:result>' ] : <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret <EOL> def absent ( name , export = False , force = False ) : <EOL> '''<STR_LIT>''' <EOL> name = name . lower ( ) <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> log . debug ( '<STR_LIT>' . format ( name , force ) ) <EOL> log . debug ( '<STR_LIT>' . format ( name , export ) ) <EOL> if __salt__ [ '<STR_LIT>' ] ( name ) : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> if export : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = __salt__ [ '<STR_LIT>' ] ( name , force = force ) <EOL> ret [ '<STR_LIT:result>' ] = ret [ '<STR_LIT:result>' ] . get ( name ) == '<STR_LIT>' <EOL> else : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = __salt__ [ '<STR_LIT>' ] ( name , force = force ) <EOL> ret [ '<STR_LIT:result>' ] = ret [ '<STR_LIT:result>' ] . get ( name ) == '<STR_LIT>' <EOL> if ret [ '<STR_LIT:result>' ] : <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' if export else '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name , ret [ '<STR_LIT>' ] [ name ] ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( name ) <EOL> return ret </s>
