Your IP : 3.142.42.247


Current Path : /usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/plugin_systemd.cpython-36.pyc

3

�<�e4�@snddlmZddlTddlZddlmZddlmZddlj	Z	ddl
Z
ddlZejj
�ZGdd�dej�ZdS)	�)�base)�*�N)�
exceptions)�commandscs�eZdZdZ�fdd�Zdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zejfdd�Zdd�Zeddd�dd ��Z�ZS)!�
SystemdPlugina<
	`systemd`::
	
	Plug-in for tuning systemd options.
	+
	The [option]`cpu_affinity` option allows setting CPUAffinity in
	`/etc/systemd/system.conf`. This configures the CPU affinity for the
	service manager as well as the default CPU affinity for all forked
	off processes. The option takes a comma-separated list of CPUs with
	optional CPU ranges specified by the minus sign (`-`).
	+
	.Set the CPUAffinity for `systemd` to `0 1 2 3`
	====
	----
	[systemd]
	cpu_affinity=0-3
	----
	====
	+
	NOTE: These tunings are unloaded only on profile change followed by a reboot.
	cs<tjjtj�stjdtj��tt|�j	||�t
�|_dS)NzERequired systemd '%s' configuration file not found, disabling plugin.)�os�path�isfile�consts�SYSTEMD_SYSTEM_CONF_FILErZNotSupportedPluginException�superr�__init__r�_cmd)�self�args�kwargs)�	__class__��$/usr/lib/python3.6/plugin_systemd.pyr$szSystemdPlugin.__init__cCsd|_d|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuning)r�instancerrr�_instance_init*szSystemdPlugin._instance_initcCsdS)Nr)rrrrr�_instance_cleanup.szSystemdPlugin._instance_cleanupcCsddiS)N�cpu_affinityr)�clsrrr�_get_config_options1sz!SystemdPlugin._get_config_optionscCsB|dk	r>tjd|d|tjd�}|dk	r>|jdkr>|jd�SdS)Nz^\s*z\s*=\s*(.*)$)�flagsr)�re�search�	MULTILINE�	lastindex�group)r�conf�key�morrr�_get_keyval7s

zSystemdPlugin._get_keyvalcCs~tjd|ddt|�|tjd�\}}|dkrzy|ddkrF|d7}Wntk
r\YnX||dt|�d7}|S|S)	Nz^(\s*z\s*=).*$z\g<1>)rr�
�=���)r�subn�strr�
IndexError)rr"r#�valZconf_newZnsubsrrr�_add_keyval?s(zSystemdPlugin._add_keyvalcCstjd|dd|tjd�S)Nz^\s*z\s*=.*\n�)r)r�subr)rr"r#rrr�_del_keyKszSystemdPlugin._del_keycCs,|jjtjdd�}|dkr(tjd�dS|S)N)�err_retz(error reading systemd configuration file)r�	read_filerr�log�error)rZsystemd_system_confrrr�_read_systemd_system_confNs

z'SystemdPlugin._read_systemd_system_confcCsptjtj}|jj||�s8tjd�|jj|dd�dS|jj|tj�sltjdtj�|jj|dd�dSdS)Nz(error writing systemd configuration fileT)�no_errorFz/error replacing systemd configuration file '%s')	rrZTMP_FILE_SUFFIXr�
write_to_filer3r4�unlink�rename)rr"Ztmpfilerrr�_write_systemd_system_confUs
z(SystemdPlugin._write_systemd_system_confcCstjjtj|j�S)N)rr	�joinrZPERSISTENT_STORAGE_DIR�name)rrrr�_get_storage_filenamecsz#SystemdPlugin._get_storage_filenamecCsl|j�}|dk	rh|j�}|jj|ddd�}|jj|�|dkrN|j|tj�}n|j|tj|�}|j	|�dS)NT)r1r6)
r5r=rr2r8r0r�SYSTEMD_CPUAFFINITY_VARr-r:)rr"�fname�cpu_affinity_savedrrr�_remove_systemd_tuningfsz$SystemdPlugin._remove_systemd_tuningcCs0|tjkr,tjdtj�|j�tjd�dS)Nz6removing '%s' systemd tuning previously added by TuneDz[you may need to manualy run 'dracut -f' to update the systemd configuration in initrd image)rZ
ROLLBACK_FULLr3�infor>rAZconsole)rrZrollbackrrr�_instance_unapply_staticrs
z&SystemdPlugin._instance_unapply_staticc
Cs<|dkrdSdjdd�|jjtjddtjdd|���D��S)Nr.� css|]}t|�VqdS)N)r*)�.0�vrrr�	<genexpr>|sz8SystemdPlugin._cpulist_convert_unpack.<locals>.<genexpr>z\s+�,z,\s+)r;r�cpulist_unpackrr/)rZcpulistrrr�_cpulist_convert_unpackysz%SystemdPlugin._cpulist_convert_unpackrF)Z
per_devicecCs�d}d}|jj|jj|jj|���}djdd�|jj|�D��}|j�}	|	dk	rh|j|	t	j
�}|j|�}|r||jd|||�S|r�|j
�}
|jj|
ddd�}|dk	r�|dkr�||kr�|jj|
|dd�tjdt	j
|t	jf�|j|j|	t	j
|��dS)	NrDcss|]}t|�VqdS)N)r*)rErFrrrrG�sz)SystemdPlugin._cmdline.<locals>.<genexpr>rT)r1r6)Zmakedirz setting '%s' to '%s' in the '%s')rZunescapeZ
_variables�expandZunquoter;rIr5r%rr>rJZ
_verify_valuer=r2r7r3rBrr:r-)rZenabling�valueZverifyZignore_missingZ
conf_affinityZconf_affinity_unpackedrFZ
v_unpackedr"r?r@rrr�_cmdline~s"
zSystemdPlugin._cmdline)�__name__�
__module__�__qualname__�__doc__rrr�classmethodrr%r-r0r5r:r=rArZ
ROLLBACK_SOFTrCrJZcommand_customrM�
__classcell__rr)rrr
sr)r.rZ
decoratorsZ
tuned.logsZtunedrZtuned.utils.commandsrZtuned.constsrrrZlogs�getr3ZPluginrrrrr�<module>s



?>