#NEWLINE# def save_config( ) : #NEWLINE# #INDENT# "\n    Save RAID configuration to config file.\n\n    Same as:\n    mdadm --detail --scan >> /etc/mdadm/mdadm.conf\n\n    Fixes this issue with Ubuntu\n    REF: http://askubuntu.com/questions/209702/why-is-my-raid-dev-md1-showing-up-as-dev-md126-is-mdadm-conf-being-ignored\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' raid.save_config\n\n    " #NEWLINE# scan = __salt__ [ 'cmd.run' ] ( 'mdadm --detail --scan' , python_shell = False ) . splitlines ( ) #NEWLINE# if ( __grains__ [ 'os' ] == 'Ubuntu' ) : #NEWLINE# #INDENT# buggy_ubuntu_tags = [ 'name' , 'metadata' ] #NEWLINE# for ( i , elem ) in enumerate ( scan ) : #NEWLINE# #INDENT# for bad_tag in buggy_ubuntu_tags : #NEWLINE# #INDENT# pattern = '\\s{0}=\\S+' . format ( re . escape ( bad_tag ) ) #NEWLINE# pattern = re . compile ( pattern , flags = re . I ) #NEWLINE# scan [ i ] = re . sub ( pattern , '' , scan [ i ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( __grains__ . get ( 'os_family' ) == 'Debian' ) : #NEWLINE# #INDENT# cfg_file = '/etc/mdadm/mdadm.conf' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cfg_file = '/etc/mdadm.conf' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# vol_d = dict ( [ ( line . split ( ) [ 1 ] , line ) for line in scan ] ) #NEWLINE# for vol in vol_d : #NEWLINE# #INDENT# pattern = '^ARRAY\\s+{0}.*$' . format ( re . escape ( line ) ) #NEWLINE# __salt__ [ 'file.replace' ] ( cfg_file , pattern , vol_d [ vol ] , append_if_not_found = True ) #NEWLINE# #UNINDENT# #UNINDENT# except SaltInvocationError : #NEWLINE# #INDENT# __salt__ [ 'file.write' ] ( cfg_file , args = scan ) #NEWLINE# #UNINDENT# if ( __grains__ . get ( 'os_family' ) == 'Debian' ) : #NEWLINE# #INDENT# return __salt__ [ 'cmd.run' ] ( 'update-initramfs -u' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( __grains__ . get ( 'os_family' ) == 'RedHat' ) : #NEWLINE# #INDENT# return __salt__ [ 'cmd.run' ] ( 'dracut --force' )