#NEWLINE# def set_automaster( name , device , fstype , opts = '' , config = '/etc/auto_salt' , test = False , **kwargs ) : #NEWLINE# #INDENT# "\n    Verify that this mount is represented in the auto_salt, change the mount\n    to match the data passed, or add the mount if it is not present.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' mount.set_automaster /mnt/foo /dev/sdz1 ext4\n    " #NEWLINE# if isinstance ( opts , list ) : #NEWLINE# #INDENT# opts = ',' . join ( opts ) #NEWLINE# #UNINDENT# lines = [ ] #NEWLINE# change = False #NEWLINE# present = False #NEWLINE# automaster_file = '/etc/auto_master' #NEWLINE# if ( not os . path . isfile ( config ) ) : #NEWLINE# #INDENT# __salt__ [ 'file.touch' ] ( config ) #NEWLINE# __salt__ [ 'file.append' ] ( automaster_file , '/-\t\t\t{0}' . format ( config ) ) #NEWLINE# #UNINDENT# name = '/..{0}' . format ( name ) #NEWLINE# device_fmt = '{0}:{1}' . format ( fstype , device ) #NEWLINE# type_opts = '-fstype={0},{1}' . format ( fstype , opts ) #NEWLINE# if ( fstype == 'smbfs' ) : #NEWLINE# #INDENT# device_fmt = device_fmt . replace ( fstype , '' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# with salt . utils . fopen ( config , 'r' ) as ifile : #NEWLINE# #INDENT# for line in ifile : #NEWLINE# #INDENT# if line . startswith ( '#' ) : #NEWLINE# #INDENT# lines . append ( line ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( not line . strip ( ) ) : #NEWLINE# #INDENT# lines . append ( line ) #NEWLINE# continue #NEWLINE# #UNINDENT# comps = line . split ( ) #NEWLINE# if ( len ( comps ) != 3 ) : #NEWLINE# #INDENT# lines . append ( line ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( ( comps [ 0 ] == name ) or ( comps [ 2 ] == device_fmt ) ) : #NEWLINE# #INDENT# present = True #NEWLINE# if ( comps [ 0 ] != name ) : #NEWLINE# #INDENT# change = True #NEWLINE# comps [ 0 ] = name #NEWLINE# #UNINDENT# if ( config [ 1 ] != type_opts ) : #NEWLINE# #INDENT# change = True #NEWLINE# comps [ 1 ] = type_opts #NEWLINE# #UNINDENT# if ( comps [ 2 ] != device_fmt ) : #NEWLINE# #INDENT# change = True #NEWLINE# comps [ 2 ] = device_fmt #NEWLINE# #UNINDENT# if change : #NEWLINE# #INDENT# log . debug ( 'auto_master entry for mount point {0} needs to be updated' . format ( name ) ) #NEWLINE# newline = '{0}\t{1}\t{2}\n' . format ( name , type_opts , device_fmt ) #NEWLINE# lines . append ( newline ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# lines . append ( line ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except ( IOError , OSError ) as exc : #NEWLINE# #INDENT# msg = "Couldn't read from {0}: {1}" #NEWLINE# raise CommandExecutionError ( msg . format ( config , str ( exc ) ) ) #NEWLINE# #UNINDENT# if change : #NEWLINE# #INDENT# if ( not salt . utils . test_mode ( test = test , ** kwargs ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# with salt . utils . fopen ( config , 'w+' ) as ofile : #NEWLINE# #INDENT# ofile . writelines ( lines ) #NEWLINE# #UNINDENT# #UNINDENT# except ( IOError , OSError ) : #NEWLINE# #INDENT# msg = 'File not writable {0}' #NEWLINE# raise CommandExecutionError ( msg . format ( config ) ) #NEWLINE# #UNINDENT# #UNINDENT# return 'change' #NEWLINE# #UNINDENT# if ( not change ) : #NEWLINE# #INDENT# if present : #NEWLINE# #INDENT# return 'present' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not salt . utils . test_mode ( test = test , ** kwargs ) ) : #NEWLINE# #INDENT# newline = '{0}\t{1}\t{2}\n' . format ( name , type_opts , device_fmt ) #NEWLINE# lines . append ( newline ) #NEWLINE# try : #NEWLINE# #INDENT# with salt . utils . fopen ( config , 'w+' ) as ofile : #NEWLINE# #INDENT# ofile . writelines ( lines ) #NEWLINE# #UNINDENT# #UNINDENT# except ( IOError , OSError ) : #NEWLINE# #INDENT# raise CommandExecutionError ( 'File not writable {0}' . format ( config ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return 'new'