MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: sonne (1011)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyc
�
d�bc@s�ddlZddlZddlZddlmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
mZddlmZddlmZmZddlmZdd	lmZmZdd
lmZddlmZmZddlmZdd
l m!Z!m"Z"dZ#dZ$edZ%e#de%Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3de4fd ��YZ5d!�Z6d"�Z7d#e4fd$��YZ8dS(%i����N(tconf(tlogger(t	CpuCgrouptAGENT_NAME_TELEMETRYtMetricsCounter(t
CGroupsApitSystemdCgroupsApitSystemdRunErrortEXTENSION_SLICE_PREFIX(tCGroupsTelemetry(tExtensionErrorCodestCGroupsException(tustr(t
get_osutiltsystemd(t
get_distro(t	shellutiltfileutil(thandle_process_completion(t	add_eventtWALAEventOperationsazure.slicesh
[Unit]
Description=Slice for Azure VM Agent and Extensions
DefaultDependencies=no
Before=slices.target
s.slicet/sx
[Unit]
Description=Slice for Azure VM Extensions
DefaultDependencies=no
Before=slices.target
[Slice]
CPUAccounting=yes
s�
[Unit]
Description=Slice for Azure VM extension {extension_name}
DefaultDependencies=no
Before=slices.target
[Slice]
CPUAccounting=yes
s%azure-walinuxagent-logcollector.slices�
[Unit]
Description=Slice for Azure VM Agent Periodic Log Collector
DefaultDependencies=no
Before=slices.target
[Slice]
CPUAccounting=yes
CPUQuota={cpu_quota}
MemoryAccounting=yes
MemoryLimit={memory_limit}
s5%t30Ms
10-Slice.confsh
# This drop-in unit file was created by the Azure VM Agent.
# Do not edit.
[Service]
Slice=azure.slice
s11-CPUAccounting.confsh
# This drop-in unit file was created by the Azure VM Agent.
# Do not edit.
[Service]
CPUAccounting=yes
s12-CPUQuota.confsc
# This drop-in unit file was created by the Azure VM Agent.
# Do not edit.
[Service]
CPUQuota={0}
ixtDisableCgroupscBseZdZdZdZRS(talltagentt
extensions(t__name__t
__module__tALLtAGENTt
EXTENSIONS(((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyRdscGs:|j|�}tjd|�tdtjd|�dS(Ns[CGI] toptmessage(tformatRtinfoRRtCGroupsInfo(t
format_stringtargsR!((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt_log_cgroup_infojsc	GsF|j|�}tjd|�tdtjd|dtdt�dS(Ns[CGW] R R!t
is_successt	log_event(R"RR#RRR$tFalse(R%R&R!((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt_log_cgroup_warningpstCGroupConfiguratorcBs9eZdZdefd��YZeZed��ZRS(s

    This class implements the high-level operations on CGroups (e.g. initialization, creation, etc)

    NOTE: with the exception of start_extension_command, none of the methods in this class
    raise exceptions (cgroup operations should not block extensions)
    t_ImplcBs�eZd�Zd�Zed��Zed��Zd�Zd�Zed��Z	ed��Z
ed��Zed	��Zed
��Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zed��Zed��Zed��Zd�Zd�Zed��Zed��Zed��Zed��Zd�Zd�Z d�Z!e"j#d�Z$d �Z%d!�Z&d"�Z'd#�Z(d$�Z)d%�Z*RS(&cCsCt|_t|_t|_t|_d|_d|_d|_dS(N(	R*t_initializedt_cgroups_supportedt_agent_cgroups_enabledt_extensions_cgroups_enabledtNonet_cgroups_apit_agent_cpu_cgroup_patht_agent_memory_cgroup_path(tself((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__init__s						cCs�z�yb|jrdStj�|_|jsBtjdt��dSt�|_t	j
�sntdt��dStdt	j
��|j�s�dSt	j�}t	j|d�}|tdfkr�td|�dS|j�|j�\}}|j|||�\|_|_|jdk	rTtd|j�|j�tjtt|j��ntd|j�Wn&tk
r�}td	t|��nXWdt |_XdS(
Ns)Cgroup monitoring is not supported on {0}ssystemd was not detected on {0}ssystemd version: {0}tSlicessystem.slices,The agent is within an unexpected slice: {0}sAgent CPU cgroup: {0}sAgent cgroups enabled: {0}sError initializing cgroups: {0}(!R.Rtcgroups_supportedR/RR#RRR3Rt
is_systemdR+R'tget_versiont_Impl__check_no_legacy_cgroupstget_agent_unit_nametget_unit_propertytAZURE_SLICEt_Impl__setup_azure_slicet_Impl__get_cgroup_controllerst_Impl__get_agent_cgroupsR4R5R2tenableR	ttrack_cgroupRRR0t	ExceptionRtTrue(R6tagent_unit_nametagent_slicetcpu_controller_roottmemory_controller_roott	exception((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt
initialize�sB		

	
c
Cs�g}y|tjddddg�}xZ|jd�D]I}tjd|tj�}|dk	r4|j|jd�|f�q4q4WWn)tj	k
r�}t
dt|��nXxl|D]d\}}d	}ytj
|d
�}Wn)tk
r}t
d|t|��nXtd||�q�Wt|�d
kr�yztjd�}	xd|	jd�D]S}tjd|tj�rQtjtd�j|	��tdtjdd�qQqQWWq�tj	k
r�}t
dt|��q�XndS(Nt	systemctls
list-unitssazure*s-alls
s\s?(azure[^\s]*)\s?is!Failed to list systemd units: {0}tUnknownR8s"Failed to query Slice for {0}: {1}s(Found an Azure unit under slice {0}: {1}issystemd-cglss[^\x00-\xff]+azure\.slice\s*s"Found a cgroup for azure.slice
{0}R R!sFound a cgroup for azure.slice(Rtrun_commandtsplittretmatcht
IGNORECASER2tappendtgrouptCommandErrorR+RRR>RER'tlentUNICODERR#R"RRR$(
tazure_unitstunitstlineRRt
command_errort	unit_nametunit_descriptiont
unit_sliceRKtcgroups((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__collect_azure_unit_telemetry�s2'!c	CsLg}t�j�}y8tj|d�}|tj�krL|j|�nWn&tk
ru}tdt|��nXy:tj|d�}x!|j	�D]}|j|�q�WWn&tk
r�}tdt|��nXxl|D]d}y2t
|d��}td||j��WdQXWq�tk
rC}td|t|��q�Xq�WdS(NtFragmentPaths-Failed to query the agent's FragmentPath: {0}tDropInPathss,Failed to query the agent's DropInPaths: {0}trs/Found a custom unit file for the agent: {0}
{1}sCan't read {0}: {1}(
R
tget_service_nameRR>tget_agent_unit_fileRTRER+RRPtopenR'tread(tagent_unit_filestagent_service_namet
fragment_pathRKt
drop_in_pathstpatht	unit_filetfile_object((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt$__collect_agent_unit_files_telemetry�s*
	cCs-|jj�}|dkr)td�tStS(s
            Older versions of the daemon (2.2.31-2.2.40) wrote their PID to /sys/fs/cgroup/{cpu,memory}/WALinuxAgent/WALinuxAgent. When running
            under systemd this could produce invalid resource usage data. Cgroups should not be enabled under this condition.
            isOThe daemon's PID was added to a legacy cgroup; will not monitor resource usage.(R3tcleanup_legacy_cgroupsR+R*RF(R6tlegacy_cgroups((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__check_no_legacy_cgroups�s

cCs�|jj�\}}|dk	r4tjd|�n
td�|dk	r]tjd|�n
td�|jj�\}}|dk	r�td||�n||fS(Ns+The CPU cgroup controller is mounted at {0}s(The CPU cgroup controller is not mounteds.The memory cgroup controller is mounted at {0}s+The memory cgroup controller is not mounteds.cgroups v2 mounted at {0}.  Controllers: [{1}](R3tget_cgroup_mount_pointsR2RR#R+tget_cgroup2_controllersR'(R6RIRJtcgroup2_mount_pointtcgroup2_controllers((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__get_cgroup_controllerss

	
cCs�tjjd�tj�}tjj|t�}tjj|t	�}tjj|t
�}tj�}tj�}tjj|t
�}tjj|t�}g}tjj|�s�|j|tf�ntjj|�s�|j|tf�ntjj|�s3tjdtdt�}	|j||	f�ntj|d�dk	r^tjj|�n(tjj|�s�|j|tf�ntj|d�dk	r�tjj|�n(tjj|�s�|j|tf�nt|�dkr�y.x'|D]\}
}tjj|
|�q�WWnHtk
rc}tdt |��x|D]}
tjj|
�qEWdSXy$t!j"d	�t#j$d
dg�Wq�tk
r�}tdt |��q�XndS(
s�
            The agent creates "azure.slice" for use by extensions and the agent. The agent runs under "azure.slice" directly and each
            extension runs under its own slice ("Microsoft.CPlat.Extension.slice" in the example below). All the slices for
            extensions are grouped under "vmextensions.slice".

            Example:  -.slice
                      ├─user.slice
                      ├─system.slice
                      └─azure.slice
                        ├─walinuxagent.service
                        │ ├─5759 /usr/bin/python3 -u /usr/sbin/waagent -daemon
                        │ └─5764 python3 -u bin/WALinuxAgent-2.2.53-py2.7.egg -run-exthandlers
                        └─azure-vmextensions.slice
                          └─Microsoft.CPlat.Extension.slice
                              └─5894 /usr/bin/python3 /var/lib/waagent/Microsoft.CPlat.Extension-1.0.0.0/enable.py

            This method ensures that the "azure" and "vmextensions" slices are created. Setup should create those slices
            under /lib/systemd/system; but if they do not exist, __ensure_azure_slices_exist will create them.

            It also creates drop-in files to set the agent's Slice and CPUAccounting if they have not been
            set up in the agent's unit file.

            Lastly, the method also cleans up unit files left over from previous versions of the agent.
            s8/etc/systemd/system/system-walinuxagent.extensions.slicet	cpu_quotatmemory_limitsSlice=sCPUAccounting=is4Failed to create unit files for the azure slice: {0}Ns$Executing systemctl daemon-reload...RMs
daemon-reloads.daemon-reload failed (create azure slice): {0}(%R,R-t_Impl__cleanup_unit_fileRtget_unit_file_install_pathtosRmtjoinR?t_VMEXTENSIONS_SLICEtLOGCOLLECTOR_SLICERftget_agent_drop_in_patht_AGENT_DROP_IN_FILE_SLICEt_DROP_IN_FILE_CPU_ACCOUNTINGtexistsRTt_AZURE_SLICE_CONTENTSt_VMEXTENSIONS_SLICE_CONTENTSt _LOGCOLLECTOR_SLICE_CONTENTS_FMTR"t_LOGCOLLECTOR_CPU_QUOTAt_LOGCOLLECTOR_MEMORY_LIMITRtfindre_in_fileR2t"_AGENT_DROP_IN_FILE_SLICE_CONTENTSt%_DROP_IN_FILE_CPU_ACCOUNTING_CONTENTSRWt_Impl__create_unit_fileRER+RRR#RRO(tunit_file_install_pathtazure_slicetvmextensions_slicetlogcollector_slicetagent_unit_filetagent_drop_in_pathtagent_drop_in_file_slicet!agent_drop_in_file_cpu_accountingtfiles_to_createtslice_contentsRmtcontentsRKRn((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__setup_azure_slicesP	

cCs�tjj|�\}}tjj|�s@tj|dd�ntjj|�}tj||�td|rtdnd|�dS(Ntmodei�s{0} {1}tUpdatedtCreated(R}RmRPR�Rtmkdirt
write_fileR'(RmR�tparentt_R�((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__create_unit_filenscCsctjj|�r_ytj|�td|�Wq_tk
r[}td|t|��q_XndS(NsRemoved {0}sFailed to remove {0}: {1}(R}RmR�tremoveR'RER+R(RmRK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__cleanup_unit_filews
cCstxm|D]e}tjj|�rytj|�td|�Wqltk
rh}td|t|��qlXqqWdS(NsRemoved {0}sFailed to remove {0}: {1}(R}RmR�R�R'RER+R(tfiles_to_cleanupRmRK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__cleanup_all_files�s

cCs}y.x'|D]\}}tjj||�q
WWnHtk
rx}tdt|��x|D]}tjj|�qZWdSXdS(Ns!Failed to create unit files : {0}(R,R-R�RER+RR{(R�RmR�RKRn((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__create_all_files�s
cCsDtj�}tjj|tj|��}tjj|�r@tSt	S(N(
RR|R}RmR~Rtget_extension_slice_nameR�RFR*(R6textension_nameR�textension_slice_path((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt,is_extension_resource_limits_setup_completed�scCs|tj�}tjj||�}|jjd�\}}|dkrRtd�nW||kr�t	dtj
|d��t	dtj
|d��ntd||�d}|dkr�td�nD||kr�tj
|d	�}t	d
|�nt	d||�d}|dk	r6|dk	r6tjj||�}	nd}	|dk	rl|dk	rltjj||�}
nd}
|	|
fS(NR6s.The agent's process is not within a CPU cgroupsCPUAccounting: {0}t
CPUAccountings
CPUQuota: {0}tCPUQuotaPerSecUSecsdThe Agent is not in the expected CPU cgroup; will not enable monitoring. Cgroup:[{0}] Expected:[{1}]s1The agent's process is not within a memory cgrouptMemoryAccountingsMemoryAccounting: {0}sgThe Agent is not in the expected memory cgroup; will not enable monitoring. CGroup:[{0}] Expected:[{1}](RR=R}RmR~R3t!get_process_cgroup_relative_pathsR2R+R'R>(R6RHRIRJRGtexpected_relative_pathtcpu_cgroup_relative_pathtmemory_cgroup_relative_pathtmemory_accountingtagent_cpu_cgroup_pathtagent_memory_cgroup_path((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__get_agent_cgroups�s>	

cCs|jS(N(R/(R6((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt	supported�scCs|jp|jS(N(R0R1(R6((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytenabled�scCs|jS(N(R0(R6((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt
agent_enabled�scCs|jS(N(R1(R6((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytextensions_enabled�scCsD|j�std��nt|_t|_|jtj��dS(NsOAttempted to enable cgroups, but they are not supported on the current platform(R�RRFR0R1t_Impl__set_cpu_quotaRtget_agent_cpu_quota(R6((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyRC�s		c	Cs�|tjkr8t|_t|_|j�tj�nY|tjkrvt|_|j�tj	t
t|j��n|tj
kr�t|_ndj|�}tj|�tdtjd|dtdt�dS(Ns6[CGW] Disabling resource usage monitoring. Reason: {0}R R!R(R)(RRR*R0R1t_Impl__reset_agent_cpu_quotaR	tresetRt
stop_trackingRRR4RR"RR#RRtCGroupsDisabled(R6treasontdisable_cgroupsR!((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytdisable�s		

	

cCsBdj|�}td|�tjj|�r>tjt�ndS(s
            Sets the agent's CPU quota to the given percentage (100% == 1 CPU)

            NOTE: This is done using a dropin file in the default dropin directory; any local overrides on the VM will take precedence
            over this setting.
            s{0}%s$Ensuring the agent's CPUQuota is {0}N(R"R'R,R-t_Impl__try_set_cpu_quotaR	tset_track_throttled_timeRF(tquotatquota_percentage((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__set_cpu_quota�s
cCsRtjd�tjjd�rNtjt�tdt	j
t	j�d��ndS(s�
            Removes any CPUQuota on the agent

            NOTE: This resets the quota on the agent's default dropin file; any local overrides on the VM will take precedence
            over this setting.
            sResetting agent's CPUQuotats
CPUQuota: {0}R�N(RR#R,R-R�R	R�R*R'RR>R=(((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__reset_agent_cpu_quota�s

cCsy�tjjtj�t�}tj|�}tjj|�rpt	|d��}|j
�|krgtSWdQXntj
j||�Wn'tk
r�}tdt|��tSXy$tjd�tjddg�Wn'tk
r�}tdt|��tSXtS(NRdsFailed to set CPUQuota: {0}s$Executing systemctl daemon-reload...RMs
daemon-reloads%daemon-reload failed (set quota): {0}(R}RmR~RR�t_DROP_IN_FILE_CPU_QUOTAt'_DROP_IN_FILE_CPU_QUOTA_CONTENTS_FORMATR"R�RgRhRFR,R-R�RER+RR*RR#RRO(R�tdrop_in_fileR�tfile_RK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__try_set_cpu_quotas$

cCs|j�sdSg}t}y|j�t}Wn tk
rR}|j|�nXt}y|j|�t}Wn tk
r�}|j|�nXdjdjg|D]}t	|�^q���}|r�t
j�r�|j|t
j�n|rt
j�r|j|t
j�ndS(NsCheck on cgroups failed:
{0}s
(R�R*t _check_processes_in_agent_cgroupRFRRTt_check_agent_throttled_timeR"R~RRt+get_cgroup_disable_on_process_check_failureR�RRt)get_cgroup_disable_on_quota_check_failureR(R6tcgroup_metricsterrorstprocess_check_successRKtquota_check_successteR�((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt
check_cgroups s(



1c
Cs�g}yftj�}tj�}t�}|jtj��t�}|j|jj��t	j
|j�}|jtj��|j|jj��x�|D]�}|||fks�||kr�q�n|j|�|kr�|j
|�dkr�q�n|}x+|dkr+||kr+|j|�}qW|dkr�|j|j|��t|�dkrgPqgq�q�WWn,tk
r�}	tdjt|	���nXt|�dkr�tdj|���ndS(s�
            Verifies that the agent's cgroup includes only the current process, its parent, commands started using shellutil and instances of systemd-run
            (those processes correspond, respectively, to the extension handler, the daemon, commands started by the extension handler, and the systemd-run
            commands used to start extensions on their own cgroup).
            Other processes started by the agent (e.g. extensions) and processes not started by the agent (e.g. services installed by extensions) are reported
            as unexpected, since they should belong to their own cgroup.

            Raises a CGroupsException if the check fails
            ssystemd-runiis7Error checking the processes in the agent's cgroup: {0}s5The agent's cgroup includes unexpected processes: {0}N(R}tgetppidtgetpidtsettupdateRtget_running_commandsR3tget_systemd_run_commandsRtget_processes_in_cgroupR4t_get_parentt_get_commandRTt_Impl__format_processRWRER+R"RR(
R6t
unexpectedtdaemontextension_handlertagent_commandstsystemd_run_commandstagent_cgrouptprocesstcurrentRK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyR�<s8
		
cCswy^tdj|�d��@}|j�}|rM|ddkrM|d }n|j�SWdQXWntk
rrdSXdS(Ns/proc/{0}/commRdi����ttUNKNOWN(RgR"RhtrstripRE(tpidR�tcomm((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyR�js

cCswyVdj|�}tjj|�rUt|d��}dj||j��SWdQXnWntk
rinXdj|�S(s�
            Formats the given PID as a string containing the PID and the corresponding command line truncated to 64 chars
            s/proc/{0}/cmdlineRds[PID: {0}] {1:64.64}Ns[PID: {0}] UNKNOWN(R"R}RmR�RgRhRE(R�tcmdlinetcmdline_file((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt__format_processus#
cCscx\|D]T}|jtkr|jtjkr|jtkr[tdj|j���q[qqWdS(Ns,The agent has been throttled for {0} seconds(	tinstanceRtcounterRtTHROTTLED_TIMEtvaluet_AGENT_THROTTLED_TIME_THRESHOLDRR"(R�tmetric((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyR��s
!cCsryZdj|�}tjj|�rYt|d��!}t|j�j�d�SWdQXnWntk
rmnXdS(s�
            Returns the parent of the given process. If the parent cannot be determined returns 0 (which is the PID for the scheduler)
            s/proc/{0}/statRdiNi(	R"R}RmR�RgtintRhRPRE(R�tstatt	stat_file((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyR��s'
cCs~yN|jj|�\}}|dkr7tjd�ntjt||��Wn)tk
ry}tjdt	|��nXdS(s=
            TODO: Start tracking Memory Cgroups
            s@The CPU controller is not mounted; will not track resource usages>Failed to start tracking resource usage for the extension: {0}N(
R3tget_unit_cgroup_pathsR2RR#R	RDRRER(R6R]tcpu_cgroup_pathR�RK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytstart_tracking_unit_cgroups�scCsqyA|jj|�\}}|dk	r@tjt||��nWn)tk
rl}tjdt	|��nXdS(sH
            TODO: remove Memory cgroups from tracked list.
            sEFailed to stop tracking resource usage for the extension service: {0}N(
R3R�R2R	R�RRERR#R(R6R]R�R�RK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytstop_tracking_unit_cgroups�scCs�ywtj|�}tjjt|�}|jj�\}}tjj||�}|dk	rvt	j
t||��nWn)tk
r�}t
jdt|��nXdS(sQ
            TODO: remove extension Memory cgroups from tracked list
            sEFailed to stop tracking resource usage for the extension service: {0}N(RR�R}RmR~t_AZURE_VMEXTENSIONS_SLICER3RtR2R	R�RRERR#R(R6R�textension_slice_nametcgroup_relative_pathtcpu_cgroup_mountpointR�R�RK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytstop_tracking_extension_cgroups�s	cCs�|j�r�yA|jj||||d|d|d|d|d|	d|
�SWq�tk
r�}dj|t|��}|j|tj�q�Xnt	j
|d|d|d|d|d|	dtj�}
t
d	|
d
|d|d|d|	d|
�S(s$
            Starts a command (install/enable/etc) for an extension and adds the command's PID to the extension's cgroup
            :param extension_name: The extension executing the command
            :param command: The command to invoke
            :param cmd_name: The type of the command(enable, install, etc.)
            :param timeout: Number of seconds to wait for command completion
            :param cwd: The working directory for the command
            :param env:  The environment to pass to the command's process
            :param stdout: File object to redirect stdout to
            :param stderr: File object to redirect stderr to
            :param stderr: File object to redirect stderr to
            :param error_code: Extension error code to raise in case of error
            tshelltcwdtenvtstdouttstderrt
error_codes[Failed to start {0} using systemd-run, will try invoking the extension directly. Error: {1}t
preexec_fnR�tcommandttimeout(R�R3tstart_extension_commandRR"RR�RRt
subprocesstPopenR}tsetsidR(R6R�Rtcmd_nameR
RRRRR	R
RKR�R�((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyR�s6cCs�|j�r�tj�}tjj|tj|��}y)tj	d|�}t
jj||�Wq�t
k
r�}tdt|��t
jj|�q�XndS(s�
            Each extension runs under its own slice (Ex "Microsoft.CPlat.Extension.slice"). All the slices for
            extensions are grouped under "azure-vmextensions.slice.

            This method ensures that the extension slice is created. Setup should create
            under /lib/systemd/system if it is not exist.
            TODO: set cpu and memory quotas
            R�s8Failed to create unit files for the extension slice: {0}N(R�RR|R}RmR~RR�t_EXTENSION_SLICE_CONTENTSR"R,R-R�RER+RR{(R6R�R�R�R�RK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytsetup_extension_slice�s	cCsu|j�rqtj�}tj|�}tjj||�}tjj|�rq|j	|�t
jj|�qqndS(s�
            This method ensures that the extension slice gets removed from /lib/systemd/system if it exist
            Lastly stop the unit. This would ensure the cleanup the /sys/fs/cgroup controller paths
            N(
R�RR|RR�R}RmR~R�RR,R-R{(R6R�R�RR�((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytremove_extension_slice�s
c	Cs|j�r|dk	rx�|D]�}|jdd�}|jdd�}|dk	r|dk	rg}tjj|dj|��}tjj|t�}|j|t	f�|j
|�qqWy$tjd�t
jddg�Wqtk
r
}tdt|��qXndS(	s?
            Each extension service will have name, systemd path and it's quotas.
            This method ensures that drop-in files are created under service.d folder if quotas given.
            ex: /lib/systemd/system/extension.service.d/11-CPUAccounting.conf
            TODO: set cpu and memory quotas
            tnameRms{0}.ds$Executing systemctl daemon-reload...RMs
daemon-reloads5daemon-reload failed (create service unit files): {0}N(R�R2tgetR}RmR~R"R�RTR�t_Impl__create_all_filesRR#RRORER+R(	R6t
services_listtservicetservice_nametunit_file_pathR�tdrop_in_pathtdrop_in_file_cpu_accountingRK((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt'set_extension_services_cpu_memory_quotas 
	
cCs�|dk	r�x�|D]�}|jdd�}|jdd�}|dk	r|dk	rg}tjj|dj|��}tjj|t�}|j|�tj	j
|�tdj|��qqWndS(s^
            Remove the dropin files from service .d folder for the given service
            RRms{0}.dsDrop in files removed for {0}N(R2RR}RmR~R"R�RTR,R-t_Impl__cleanup_all_filesR'(R6RRRRR�RR((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt'remove_extension_services_drop_in_files s
	
cCs^|j�rZ|dk	rZx?|D]4}|jdd�}|dk	r|j|�qqWndS(s[
            Remove the cgroup entry from the tracked groups to stop tracking.
            RN(R�R2RR�(R6RRR((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt(stop_tracking_extension_services_cgroups1s

cCs^|j�rZ|dk	rZx?|D]4}|jdd�}|dk	r|j|�qqWndS(sV
            Add the cgroup entry to start tracking the services cgroups.
            RN(R�R2RR�(R6RRR((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt)start_tracking_extension_services_cgroups;s

(+RRR7RLtstaticmethodt#_Impl__collect_azure_unit_telemetryt)_Impl__collect_agent_unit_files_telemetryR<RAR@R�R{R RR�RBR�R�R�R�RCR�R�R�R�R�R�R�R�R�R�R�R�RR
tPluginUnknownFailureRRRRR!R"R#(((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyR-~sL			3!		S		
		-						

		.		
			
			
cCs(tjdkr!tj�t_ntjS(N(R,t	_instanceR2R-(((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pytget_instanceHs(	RRt__doc__tobjectR-R2R(R$R)(((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyR,vs���(9R}RQRtazurelinuxagent.commonRRtazurelinuxagent.common.cgroupRRRt azurelinuxagent.common.cgroupapiRRRRt'azurelinuxagent.common.cgroupstelemetryR	t azurelinuxagent.common.exceptionR
Rtazurelinuxagent.common.futureRtazurelinuxagent.common.osutilR
Rtazurelinuxagent.common.versionRtazurelinuxagent.common.utilsRRt1azurelinuxagent.common.utils.extensionprocessutilRtazurelinuxagent.common.eventRRR?R�RRR�RR�R�R�R�R�R�R�R�R�R�R�R+RR'R+R,(((sM/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupconfigurator.pyt<module>sF"