File: //opt/alt/python37/lib/python3.7/site-packages/ssa/__pycache__/manager.cpython-37.pyc
B
�Bgd�5 � @ s� d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl m
Z
ddlmZ ddl
mZ ddlmZmZ dd lmZ dd
lmZ ddlmZ ddlmZ dd
lmZ G dd� d�Zdd�dd�ZdS )zA
This module contains classes implementing SSA Manager behaviour
� N)�contextmanager)�iglob)�is_cl_solo_edition)�Tuple� )�load_validated_parser�load_configuration)� flag_file)�SSAManagerError)�ssa_version)�
AutoTracer)�
DecisionMakerc @ s� e Zd ZdZdd� Zedd�dd��Zeed�dd ��Z ee
d�d
d��Zee
d�dd
��Ze
e
d�dd�ZdAeejd�dd�Ze
dd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�d d!�Zeed"�d#d$�Zeeeef ef d�d%d&�Zed'd(� �Zeeed)d*�d+d,�Z d)d�d-d.�Z!eeeef ef d�d/d0�Z"d)d�d1d2�Z#d)d�d3d4�Z$d)d�d5d6�Z%ed�d7d8�Z&d)d�d9d:�Z'd)d�d;d<�Z(dd�d=d>�Z)d)d�d?d@�Z*d)S )B�Managerz
SSA Manager class.
c C sD t �d�| _d| _d| _d| _tddd� d�f| _tt t
jf| _d S ) N�managerzclos_ssa.ini)Zphp44Zphp51Zphp52Zphp53zphp\d+-imunifyzphp-internal)z /opt/alt/php[0-9][0-9]/link/confz+/opt/cpanel/ea-php[0-9][0-9]/root/etc/php.dz$/opt/plesk/php/[0-9].[0-9]/etc/php.dz'/usr/local/php[0-9][0-9]/lib/php.conf.dzM/usr/share/cagefs/.cpanel.multiphp/opt/cpanel/ea-php[0-9][0-9]/root/etc/php.dzA/usr/share/cagefs-skeleton/usr/local/php[0-9][0-9]/lib/php.conf.dz./var/cagefs/*/*/etc/cl.php.d/alt-php[0-9][0-9]c S s t �| �d�d �S )N�/� )�pwd�getpwnam�split)�path� r �</opt/alt/python37/lib/python3.7/site-packages/ssa/manager.py�<lambda>5 � z"Manager.__init__.<locals>.<lambda>)r �user)
�logging� getLogger�logger�
ini_file_name�substrings_to_exclude_dir_paths�wildcard_ini_locations�dict�wildcard_ini_user_locations�OSError�
ValueError�
subprocess�SubprocessError�subprocess_errors)�selfr r r �__init__$ s zManager.__init__zjson str)�returnc O s* ddi}|� dd� |�� D �� t�|�S )z@
Form a success json response with given kwargs
�result�successc S s i | ]\}}||�qS r r )�.0�k�vr r r �
<dictcomp>A s z$Manager.response.<locals>.<dictcomp>)�update�items�json�dumps)�args�kwargsZraw_responser r r �response; s zManager.responsec C s t j�t�S )z
Is SSA enabled
)�osr �isfiler )r( r r r �_enabledD s zManager._enabledc C s ddhS )zK
Configuration settings required Request Processor restart
�requests_duration�ignore_listr )r( r r r �_restart_required_settingsK s z"Manager._restart_required_settingsc C s dddddhS )N�correlation�correlation_coefficient�request_number�time�domains_numberr )r( r r r �solo_filtered_settingsR s zManager.solo_filtered_settings)�settingsr* c C s | j �|�S )z�
SSA Agent requires restart in case of changing these configuration:
- requests_duration
- ignore_list
)r= �intersection)r( rD r r r �_restart_requiredW s zManager._restart_requiredF)�commandr* c
C s y0t jdd|gdd|d�}| j�d|� d�� W n� t jk
r� } zj| jjd|j� d|j� d |jpf|j � �|j|j|j|j d
�d� t
d|j� d|j� d |jp�|j � ���W dd}~X Y nZ | jk
�r } z8| jjd
|� d�dt|�id� t
d
|� d|� ���W dd}~X Y nX |S )z�
Run /sbin/service utility to make given operation with SSA Agent service
:command: command to invoke
:check_retcode: whether to run with check or not
:return: subprocess info about completed process
z
/sbin/servicez ssa-agentT)�capture_output�text�checkz
ssa-agent z
succeededz
SSA Agent z failed with code z: )�cmd�retcode�stdout�stderr)�extraNzFailed to run z command for SSA Agent�errz for SSA Agent: )
r% �runr �info�CalledProcessError�errorrK �
returncoderM rN r
r'