\c@sddlmZddlTddlZddlmZddlmZddlj Z ddl Z ddl Z ddl Z ej jZdejfdYZdS( i(tbase(t*iN(t exceptions(tcommandstBootloaderPlugincBseZdZdZdZdZedZdZdZ dZ dZ e d Z d Zd Zd Zd ZdZdZdZdZdZdZdZdZeddZeddZeddZedde ddd Zed!de ddd"Zed#de ddd$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. cOsPtjjtjs'tjdntt|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|jj}g}xm|D]e}t|jdrJ|j|q||krg||||tS|jddkrutjjtj|j|_qundS(NRiR( RR-RRRRRRR(RRRRR((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_initrd_dst_imgsR%cCs>|r dS|r:|dk r:|jj|dk|_ndS(Nt1(RR tget_boolR(RRRRR((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyR sR#t per_devicetpriorityi cCs_|r dS|r[|dk r[t|}|j||dkrEtS|j|s[tSndS(NR(RR-RRR(RRRRRtsrc_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 j dddd\}}tj d|tj ||jjd |d |d t\}} tj d | |d kr%tjd|jj|dttS|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-RRRRRR0terrorRMttempfiletmkstempRZtcloseR R}RRRRRtrmtree( RRRRRtsrc_dirtfdttmpfileRR((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 |} | |krt j t j dt|ftSt jt jdt| t|ftSn|r|dk rt j dt|_||_ndS(Ns /proc/cmdlineiR&s;installing additional boot command line parameters to grub2(t _variablestexpandR tunquoteRjRlRR{R6t intersectionR0RMRtSTR_VERIFY_PROFILE_VALUE_OKR-RRtSTR_VERIFY_PROFILE_VALUE_FAILRRR( RRRRRtvR&t cmdline_sett value_settcmdline_intersect((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_cmdline>s"  )  cCs3|r/|jr/|j|jt|_ndS(N(RRxRR(RRR((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyt_instance_post_staticSs  ("R3t __module__t__doc__R RR t classmethodR(RCRRKRSRRXR`RgRqRwRxRzRVRRRRRtcommand_customRRRRRRR(((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyRs:               ! !!(RRt decoratorst tuned.logsttunedRttuned.utils.commandsRt tuned.constsRRR7RtlogstgetR0tPluginR(((sC/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.pyts