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: //usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyc
�
d�bc@szddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZddlmZddlmZdd	lmZmZdd
lmZmZmZddlmZddl m!Z!d
Z"ddgZ#dZ$defd��YZ%de&fd��YZ'de'fd��YZ(dS(i����N(tlogger(t	CpuCgroup(tCGroupsTelemetry(tget_agent_pid_file_path(tCGroupsExceptiontExtensionErrorCodestExtensionErrortExtensionOperationError(tustr(tsystemd(tfileutilt	shellutil(thandle_process_completiontread_outputtTELEMETRY_MESSAGE_MAX_LEN(tFlexibleVersion(t
get_distros/sys/fs/cgrouptcputmemorysazure-vmextensionstSystemdRunErrorcBseZdZdd�ZRS(s'
    Raised when systemd-run fails
    cCstt|�j|�dS(N(tsuperRt__init__(tselftmsg((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyR1sN(t__name__t
__module__t__doc__tNoneR(((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyR,st
CGroupsApicBsSeZed��Zed��Zed��Zed��Zed��ZRS(cCs�t�}|d}yt|d�}Wntk
r;tSX|j�dkr]|jdkp�|j�d	ko�|jdkr�|jdkp�|jdkS(
Niitubuntuitcentostredhatii(RR(RRt
ValueErrortFalsetlowertmajortminor(tdistro_infotdistro_nametdistro_version((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytcgroups_supported6s	

!cCs^y"x|D]}tj|�q
WWn5tk
rY}tjdj|jt|���nXdS(NsXCannot add cgroup '{0}' to tracking list; resource usage will not be tracked. Error: {1}(Rttrack_cgroupt	ExceptionRtwarntformattpathR(textension_cgroupstcgroupt	exception((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyt
track_cgroupsBs
cCsTttjj|d�d��0}g|j�j�D]}t|�^q4SWdQXdS(Nscgroup.procstr(topentosR-tjointreadtsplittint(tcgroup_pathtcgroup_procstpid((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytget_processes_in_cgroupKs!cCs@g}xgddgD]Y}tjjt|dd�}tjj|�rtjd|�|j||f�qqWz�x�|D]y\}}tjj|d�}tjj|�rztj	|�j
�}tj�}t
|�|kr�|||�q�qzqzWWdx7|D]/\}}tjd|�tj|dt�qWXt|�S(	sE
        Previous versions of the daemon (2.2.31-2.2.40) wrote their PID to /sys/fs/cgroup/{cpu,memory}/WALinuxAgent/WALinuxAgent;
        starting from version 2.2.41 we track the agent service in walinuxagent.service instead of WALinuxAgent/WALinuxAgent. Also,
        when running under systemd, the PIDs should not be explicitly moved to the cgroup filesystem. The older daemons would
        incorrectly do that under certain conditions.

        This method checks for the existence of the legacy cgroups and, if the daemon's PID has been added to them, executes the
        given operation on the cgroups. After this check, the method attempts to remove the legacy cgroups.

        :param operation:
            The function to execute on each legacy cgroup. It must take 2 arguments: the controller and the daemon's PID
        RRtWALinuxAgentsFound legacy cgroup {0}scgroup.procsNsRemoving {0}t
ignore_errors(R4R-R5tCGROUPS_FILE_SYSTEM_ROOTtexistsRtinfotappendR
t	read_filetstripRtget_daemon_pidRtshutiltrmtreetTruetlen(t	operationtlegacy_cgroupst
controllerR/t
procs_filetprocs_file_contentst
daemon_pidt_((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyt_foreach_legacy_cgroupPs$cCsttjt��j��S(N(R8R
RCRRD(((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyREus(RRtstaticmethodR(R1R<RQRE(((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyR5s
	%tSystemdCgroupsApicBs�eZdZd�Zd�Zd�Zed��Zd�Zd�Z	ed��Z
ed��Zed	��Ze
jd
�Zd�ZRS(s'
    Cgroups interface via systemd
    cCs.d|_d|_g|_tj�|_dS(N(Rt_cgroup_mountpointst_agent_unit_namet_systemd_run_commandst	threadingtRLockt_systemd_run_commands_lock(R((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyRs			cCs|j�
|jSWdQXdS(s^
        Returns a list of the systemd-run commands currently running (given as PIDs)
        N(RYRV(R((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytget_systemd_run_commands�s
cCs�|jd	kr�d	}d	}xqtjdddg�j�D]Q}tjd|�}|d	k	r:|jd�}d|kr�|}q�|}q:q:Wi|d6|d6|_n|jd|jdfS(
s�
        Returns a tuple with the mount points for the cpu and memory controllers; the values can be None
        if the corresponding controller is not mounted
        tmounts-tR/s%on\s+(?P<path>/\S+(memory|cpuacct))\sR-tcpuacctRRN(RTRRtrun_commandt
splitlinestretsearchtgroup(RRRtlinetmatchR-((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytget_cgroup_mount_points�s%	
cCs�d}d}x�tjdj|��j�D]�}tjd|�}|dk	r+|jd�}|jd�dkr�|jd�jd�nd}|dkr�|}q�|}q+q+W||fS(s�
        Returns a tuple with the path of the cpu and memory cgroups for the given process (relative to the mount point of the corresponding
        controller).
        The 'process_id' can be a numeric PID or the string "self" for the current process.
        The values returned can be None if the process is not in a cgroup for that controller (e.g. the controller is not mounted).
        s/proc/{0}/cgroups5\d+:(?P<controller>(memory|.*cpuacct.*)):(?P<path>.+)RLR-t/RN(	RR
RCR,R^R_RcRatlstrip(t
process_idtcpu_pathtmemory_pathRbRcRLR-((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyt!get_process_cgroup_relative_paths�s
%3	
cCs�|j|�\}}|j�\}}|dk	rT|dk	rTtjj||�nd}|dk	r�|dk	r�tjj||�nd}||fS(s<
        Returns a tuple with the path of the cpu and memory cgroups for the given process. The 'process_id' can be a numeric PID or the string "self" for the current process.
        The values returned can be None if the process is not in a cgroup for that controller (e.g. the controller is not mounted).
        N(RjRdRR4R-R5(RRgtcpu_cgroup_relative_pathtmemory_cgroup_relative_pathtcpu_mount_pointtmemory_mount_pointtcpu_cgroup_pathtmemory_cgroup_path((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytget_process_cgroup_paths�s
33cCs�tj|d�}|j�\}}|dk	rItjj||d�nd}|dk	rttjj||d�nd}||fS(s'
        Returns a tuple with the path of the cpu and memory cgroups for the given unit.
        The values returned can be None if the controller is not mounted.
        Ex: ControlGroup=/azure.slice/walinuxagent.service
        controlgroup_path[1:] = azure.slice/walinuxagent.service
        tControlGroupiN(R	tget_unit_propertyRdRR4R-R5(Rt	unit_nametcontrolgroup_pathRmRnRoRp((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytget_unit_cgroup_paths�s
++cCs�x�tjdddg�j�D]|}tjd|�}|dk	r|jd�}d}tjj	|d�}tjj
|�r�tj|�}n||fSqWdS(	s�
        Returns a tuple with the mount point for the cgroups v2 controllers, and the currently mounted controllers;
        either value can be None if cgroups v2 or its controllers are not mounted
        R[s-ttcgroup2son\s+(?P<path>/\S+)\sR-scgroup.controllersN(NN(
RR]R^R_R`RRaR4R-R5R@R
RC(RbRctmount_pointtcontrollerstcontrollers_file((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytget_cgroup2_controllers�s
%cCsS|jd�t|jt�dddd�}dj|�}||kpR||kS(Nitencodingsutf-8terrorstbackslashreplacesUnit {0} not found.(tseekRR6RR,(t
scope_nametstderrtunit_not_found((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyt_is_systemd_failure�s
!cCstd|jdd�dS(Nt-RPs.slice(tEXTENSION_SLICE_PREFIXtreplace(textension_name((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytget_extension_slice_namescCs~dj|tj��}|j|�}|j�]tjdj|||�d|d|d|d|	d|dtj�}
|j	j
|
j�WdQX|d	}tj
d
|�yrtjjd|�}|j�\}}|dkr�tj
d�n+tjj||�}tjt||��Wnptk
re}|jd
krLtj
d�ntj
dt|��n)tk
r�}tj
dt|��nXz�y/td|
d|d|d|d|	d|
�SWn�tk
rQ}|j||	�s��nt||	�}|jd�|	jd�t|t�r8d|j |f}n
d|}t!|��nXWd|j�|j	j"|
j�WdQXXdS(Ns{0}_{1}s.systemd-run --unit={0} --scope --slice={1} {2}tshelltcwdtstdoutR�tenvt
preexec_fns.scopesStarted extension in unit '{0}'s$azure.slice/azure-vmextensions.slices@The CPU controller is not mounted; will not track resource usageisFThe extension command already completed; will not track resource usages>Failed to start tracking resource usage for the extension: {0}tprocesstcommandttimeoutt
error_codeis1Systemd process exited with code %s and output %ssSystemd timed-out, output: %s(#R,tuuidtuuid4R�RYt
subprocesstPopenR4tsetsidRVRBR;RRAR-R5RdRRR)RtIOErrorterrnoRR*RRR�R
ttruncatet
isinstanceRt	exit_codeRtremove(RR�R�tcmd_nameR�R�R�R�R�R�R�tscopetextension_slice_nameR�R�tcgroup_relative_pathtcpu_cgroup_mountpointRPRotetprocess_outputterr_msg((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytstart_extension_commandsX





cCstjd��S(s�
        Previous versions of the daemon (2.2.31-2.2.40) wrote their PID to /sys/fs/cgroup/{cpu,memory}/WALinuxAgent/WALinuxAgent;
        starting from version 2.2.41 we track the agent service in walinuxagent.service instead of WALinuxAgent/WALinuxAgent. If
        we find that any of the legacy groups include the PID of the daemon then we need to disable data collection for this
        instance (under systemd, moving PIDs across the cgroup file system can produce unpredictable results)
        cWsdS(N(R(RP((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyt<lambda>Ps(RRQ(R((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pytcleanup_legacy_cgroupsIs(RRRRRZRdRRRjRqRvR{R�R�RtPluginUnknownFailureR�R�(((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyRSzs					B()R4R_RFR�RWR�tazurelinuxagent.commonRtazurelinuxagent.common.cgroupRt'azurelinuxagent.common.cgroupstelemetryRtazurelinuxagent.common.confRt azurelinuxagent.common.exceptionRRRRtazurelinuxagent.common.futureRtazurelinuxagent.common.osutilR	tazurelinuxagent.common.utilsR
Rt1azurelinuxagent.common.utils.extensionprocessutilRR
Rt-azurelinuxagent.common.utils.flexible_versionRtazurelinuxagent.common.versionRR?tCGROUP_CONTROLLERSR�RtobjectRRS(((sD/usr/lib/python2.7/site-packages/azurelinuxagent/common/cgroupapi.pyt<module>s,"	E