ok

Mini Shell

Direktori : /proc/self/root/proc/self/root/usr/lib/python2.7/site-packages/tuned/plugins/
Upload File :
Current File : //proc/self/root/proc/self/root/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyc

�
��\c@s�ddlmZddlTddlZddlmZddlmZddlj	Z	ddl
Z
ddlZddlZej
j�Zdejfd��YZdS(	i(tbase(t*i����N(t
exceptions(tcommandstBootloaderPlugincBseZdZd�Zd�Zd�Zed��Zd�Zd�Z	d�Z
d�Zed	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed�d��Zed�d��Zed�d��Zeddedd�d ��Zed!dedd�d"��Zed#dedd�d$��Z d%�Z!RS(&s�
	Plugin for tuning bootloader options.

	Currently only grub2 is supported and reboot is required to apply the tunings.
	These tunings are unloaded only on profile change followed by reboot.
	cOsPtjjtj�s'tjd��ntt|�j	||�t
�|_dS(Ns4Required GRUB2 template not found, disabling plugin.(tostpathtisfiletconststGRUB2_TUNED_TEMPLATE_PATHRtNotSupportedPluginExceptiontsuperRt__init__Rt_cmd(tselftargstkwargs((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyRscCsRt|_t|_t|_t|_d|_d|_d|_	|j
�|_dS(Nt(tFalset_has_dynamic_tuningtTruet_has_static_tuningtupdate_grub2_cfgt_initrd_remove_dirtNonet_initrd_dst_img_valt_cmdline_valt_initrd_valt_get_grub2_cfg_filest_grub2_cfg_file_names(Rtinstance((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_instance_inits							cCsdS(N((RR((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_instance_cleanup'scCs.idd6dd6dd6dd6dd6dd6S(Ntgrub2_cfg_filetinitrd_dst_imgtinitrd_add_imgtinitrd_add_dirtinitrd_remove_dirtcmdline(R(tcls((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_get_config_options*sc	Cs�|j�j�}g}xm|D]e}t|�jd�rJ|j|�q||krg||||<qtjd||jjf�qW|j	�d}x�|D]�}||}|dks�|dkr�q�n|d}|dj�}|dkr|dkr|d|7}q�|dkrn|dkrnxQ|j�D]2}	t
j|	�}
t
jd	|
d
d|�}q5Wq�|d|7}q�W|j�}|dkr�||d<n|S(sSMerge provided options with plugin default options and merge all cmdline.* options.R&s$Unknown option '%s' for plugin '%s'.Riit+t t-s(\A|\s)s	(?=\Z|\s)N(R(tcopytstrt
startswithtappendtlogtwarnt	__class__t__name__tsortRtstriptsplittretescapetsub(Rtoptionst	effectivetcmdline_keystkeyR&tvaltoptvalstptregex((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_get_effective_options5s6
!



$
cCs@g}x3tjD](}tjj|�r|j|�qqW|S(N(RtGRUB2_CFG_FILESRRtexistsR/(Rt	cfg_filestf((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyRUs
cCs|jjtj|�S(N(R
tadd_modify_option_in_fileRtBOOT_CMDLINE_FILE(Rtd((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_patch_bootcmdline\scCs�|jstjd�dS|jidtj6dtj6�xF|jD];}|jj|iddtj	6ddtj
6dt�qEW|jdk	r�tjd|j�|jj|j�ndS(Nscannot find grub.cfg to patchRsset\s+taddsremoving initrd image '%s'(RR0tinfoRKRtBOOT_CMDLINE_TUNED_VARtBOOT_CMDLINE_INITRD_ADD_VARR
RHtGRUB2_TUNED_VARtGRUB2_TUNED_INITRD_VARRRRtunlink(RRG((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_remove_grub2_tuning_s	
!9cCs?|r;tjd�|j�|jidd6dd6�ndS(Ns/removing grub2 tuning previously added by TunedRttuned_paramsttuned_initrd(R0RMRSt_update_grubenv(RRt
full_rollback((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_instance_unapply_staticjs

cCs�tjd�tjdtjdd|dtj�}tjdtjd|dtj�}tjdtjdd|dtj�}tjdtjd|dtj�}tjtjdd|dtj�}tjtj	dd|dtj�S(	Nsunpatching grub.cfgs
^\s*set\s+s\s*=.*
Rtflagss *\$s\ns\n+(
R0tdebugR7R9RRPt	MULTILINERQtGRUB2_TEMPLATE_HEADER_BEGINtGRUB2_TEMPLATE_HEADER_END(Rt	grub2_cfgtcfg((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_grub2_cfg_unpatchps
)%)%%cCsItjd�dtjd}xD|D]<}|d|jj|�d|jj||�d7}q%W|tjd7}tjd||d	tj	�}itj
d
6tjd6}x�|D]�}tjd|d
d|||d	tj	�}tjd|d||dd|d	tj	�}tjd|dd|d	tj	�}q�W|S(Nsinitial patching of grub.cfgs\1\n\ns
sset s="s"
s\ns+^(\s*###\s+END\s+[^#]+/00_header\s+### *)\nRYtlinuxtinitrds^(\s*s(16|efi)?\s+.*)$s\1 $s(?:16|efi)?\s+\S+rescue.*)\$s *(.*)$s\1\2s(?:16|efi)?\s+\S+rescue.*) +$s\1(R0RZRR\R
R8R]R7R9R[RPRQ(RR^RJtstopttd2ti((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_grub2_cfg_patch_initialys

:
.2*cCs,|jjtj�}t|�dkr?tjdtj�tSitjd6tj	d6}t}x�|D]�}t
jd|d||d|dt
j�dkrft}|d	d
kr�|d
7}n||d|d|d
||d7}qfqfW|r(tjdtj�|jjtj|�ntS(Niscannot read '%s'tGRUB_CMDLINE_LINUX_DEFAULTtGRUB_INITRD_OVERLAYs^[^#]*\bs
\s*=.*\\\$s\b.*$RYi����s
s="${s:+$s }\$s"
s
patching '%s'(R
t	read_fileRtGRUB2_DEFAULT_ENV_FILEtlenR0RMRRPRQR7tsearchR[RRRZt
write_to_file(Rtgrub2_default_envRJtwriteRf((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_grub2_default_env_patch�s 
5
1cCs�tjd�|js'tjd�tSxz|jD]o}|jj|�}t|�dkrptjd|�tStjd|�|}t}x�|D]x}tj	d|dd
||d	|d
tj
�\}}|dkstjd||d
tj
�dkr�t
}q�q�Wttjdtj|d
tj
��ttjdtj|d
tj
��krit
}n|r�|j|j|�|�}n|jj||�q1W|j�t
S(Nspatching grub.cfgscannot find grub.cfg to patchiscannot patch %ss+adding boot command line parameters to '%s's	\b(set\s+s\s*=).*$s\1s"RYis\$s\1"(R0RZRRMRR
RjRlR7tsubnR[RmRRtfindallRRPRQRgR`RnRq(RRJRGR^t
grub2_cfg_newt
patch_initialRdtnsubs((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_grub2_cfg_patch�s0
	

81
%+	
cCsR|ji|jtj6|jtj6�|ji|jtj6|jtj6�dS(N(	RwRRRPRRQRKRNRO(R((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt
_grub2_update�s'cCstjjtj�S(N(RRRERtBLS_ENTRIES_PATH(R((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_has_bls�scCs�tjdt|��g|j�D](\}}dt|�t|�f^q$}|jjdddg|�\}}|dkr�tjd|�tStS(Nsupdating grubenv, setting %ss%s=%ss
grub2-editenvR+tsetiscannot update grubenv: '%s'(	R0RZR-titemsR
texecuteR1RR(RRJtoptiontvaluetltrctout((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyRV�s;%cCs�|jj�}|dkrtStjdtj�|jjtjdgdi|d6�\}}|dkr�tjd|�tSt	S(NRs4running kernel update hook '%s' to patch BLS entriesRLtenvtKERNEL_INSTALL_MACHINE_IDiscannot patch BLS entries: '%s'(
R
tget_machine_idRR0RZRtKERNEL_UPDATE_HOOK_FILER}R1R(Rt
machine_idR�R�((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_bls_entries_patch_initial�s.cCsPtjd�|j�rL|ji|jd6|jd6�rL|j�rLtStS(Nsupdating BLSRTRU(	R0RZRzRVRRR�RR(R((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_bls_update�s
#cCs=|jdkr9tjjtjtjj|��|_ndS(N(RRRRtjoinRtBOOT_DIRtbasename(Rtname((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_init_initrd_dst_img�scCstjjtj�S(N(RRtisdirRtPETITBOOT_DETECT_DIR(R((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_check_petitboot�scCs�|j�rtjd�ntjd|j�tjj|j�}|jj	||j�sat
St|_|jj
d�j�}d}t|�}|r�tjdd|�}t|�|kr�|}q�ntjj||�|_tS(NskDetected Petitboot which doesn't support initrd overlays. The initrd overlay will be ignored by bootloader.sinstalling initrd image as '%s's
/proc/cmdlinet/s^\s*BOOT_IMAGE=\s*(\S*/).*$s\1(R�R0R1RMRRRR�R
R,RRRRjtrstripRlR7R9R�R(Rtimgtimg_nametcurr_cmdlinetinitrd_grubpathtlcR((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_install_initrd�s 	R!cCs5|r
dS|r1|dk	r1t|�g|_ndS(N(RR-R(RtenablingRtverifytignore_missing((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_grub2_cfg_file�sR"cCsy|r
dS|ru|dk	rut|�|_|jdkr>tS|jddkrutjjtj|j�|_qundS(NRiR�(	RR-RRRRR�RR�(RR�RR�R�((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_initrd_dst_img�sR%cCs>|r
dS|r:|dk	r:|jj|�dk|_ndS(Nt1(RR
tget_boolR(RR�RR�R�((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyRsR#t
per_devicetpriorityi
cCs_|r
dS|r[|dk	r[t|�}|j|�|dkrEtS|j|�s[tSndS(NR(RR-R�RR�(RR�RR�R�tsrc_img((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_initrd_add_imgs
R$c
Csv|r
dS|rr|dk	rrt|�}|j|�|dkrEtStjj|�sltjd|�tStj	d|�t
jdddd�\}}tjd|�tj
|�|jjd	|d
|dt�\}}	tjd|	�|d
kr%tjd�|jj|dt�tS|j|�|jj|�|jrrtj	d|�|jj|�qrndS(NRsFerror: cannot create initrd image, source directory '%s' doesn't exists+generating initrd image from directory '%s'tprefixstuned-bootloader-tsuffixs.tmps+writing initrd image to temporary file '%s'sfind . | cpio -co > %stcwdtshellscpio log: %siserror generating initrd imagetno_errorsremoving directory '%s'(RR-R�RRRR�R0terrorRMttempfiletmkstempRZtcloseR
R}RRRR�Rtrmtree(
RR�RR�R�tsrc_dirtfdttmpfileR�R�((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_initrd_add_dir s2

(

	R&c
Cs|jj|jj|��}|r�|jjd�}t|�dkrLdSt|j��}t|j��}|j	|�}	|	|kr�t
jtj
dt|�f�tSt
jtjdt|	�t|�f�tSn|r|dk	rt
jd�t|_||_ndS(Ns
/proc/cmdlineiR&s;installing additional boot command line parameters to grub2(t
_variablestexpandR
tunquoteRjRlRR{R6tintersectionR0RMRtSTR_VERIFY_PROFILE_VALUE_OKR-RR�tSTR_VERIFY_PROFILE_VALUE_FAILRRR(
RR�RR�R�tvR&tcmdline_sett	value_settcmdline_intersect((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_cmdline>s" )
	cCs3|r/|jr/|j�|j�t|_ndS(N(RRxR�R(RRR�((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_instance_post_staticSs

("R3t
__module__t__doc__RRR tclassmethodR(RCRRKRSRRXR`RgRqRwRxRzRVR�R�R�R�R�tcommand_customR�R�RR�R�R�R�(((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyRs:				 																	!
!!(RRt
decoratorst
tuned.logsttunedRttuned.utils.commandsRttuned.constsRRR7R�tlogstgetR0tPluginR(((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt<module>s


Zerion Mini Shell 1.0