l#g+ ddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ej e ZdZedZed ZGd d eZd efd Zde edededed ejjf dZd efdZd efdZdS)N)Enum)fsdecode)Path)List) OsReleaseInfoz/usr/libexec/run-with-intensityz/usr/sbin/lvectlz/proc/lve/listceZdZdZdZdZdS) LimitsMethodnicelvecgroupsN)__name__ __module__ __qualname__NICELVECGROUPSZ/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/utils/resource_limits.pyr r s D CGGGrr returncKtjtdtjjtjjd{V}|d{V\}}t |}|dkr tj S|dkr tj S|dkr tj Std |t |)z6Returns limit method, used in run-with-intensity tool.show)stdoutstderrNr r r z>Parsing of used limitation method failed stdout: {} stderr: {})asynciocreate_subprocess_execRUN_WITH_INTENSITY subprocessPIPE communicaterstripr rrr LookupErrorformat)procrrs rget_current_methodr%s/!&!&       D ++--------NFF f   # # % %F     ## J ((..00 1 1  rcmdkey intensity_cpu intensity_iocKtddt|dt|g}|d|gtj||zi|d{VS)aS Creates asyncio.Process with limited resources (cpu & io), using run-with-intensity tool. :param cmd: command to execute :param intensity_cpu: cpu intensity limit :param intensity_io: io intensity limit :param subprocess_kwargs: keyword arguments for create_subprocess_exec func :return: executed Process runz--intensity-cpuz--intensity-ioz--keyN)rstrextendrr)r&r'r(r)subprocess_kwargs limits_cmds rcreate_subprocessr02s$   M L Jwn%%%/ s 0      rcZtotjS)z1Checks that LVE-utils is active resource limiter.)PROC_LVE_LIST_PATHexistsr is_cloudlinuxrrr is_lve_activer5Rs$  $ $ & & H=+F+H+HHrc4tS)z#Checks that LVE-utils is installed.)LVECTL_BIN_PATHr3rrr has_lvectlr8Ys  ! ! # ##r)rloggingenumrosrpathlibrtypingrdefence360agent.utilsr getLoggerr loggerrr7r2r r%r,intrProcessr0boolr5r8rrrrDs//////  8 $ $7$)**T*++4 ,0 c     @ItIIII$D$$$$$$r