3 Yd@s~ddlZddlZddlZddlZddlZddlZddlZddlj Z ddl m Z ddl m Z ejjZdgZGdddeZdS)N) GlobalConfig)commandsManagercseZdZdZdfdd ZeddZeddZed d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZejfddZZS) rz? Manager creates plugin instances and keeps a track of them. NcsJtt|j||_||_||_||_g|_g|_|p:t |_ t |_ dS)N) superr__init___plugins_repository_monitors_repository_def_instance_priority_hardware_inventory _instances_pluginsr_configr_cmd)selfplugins_repositoryZmonitors_repositoryZdef_instance_priorityZhardware_inventoryconfig) __class__/usr/lib/python3.6/manager.pyrs zManager.__init__cCs|jS)N)r )rrrrplugins!szManager.pluginscCs|jS)N)r )rrrr instances%szManager.instancescCs|jS)N)r)rrrrr)szManager.plugins_repositorycCsF|jdkrdS|jjtj}|dkr0|jjd}tj|j|tj dk S)NTz /proc/cpuinfo) Z cpuinfo_regexr getconstsZCFG_CPUINFO_STRINGrZ read_fileresearch MULTILINE)runitZcpuinfo_stringrrr_unit_matches_cpuinfo-s   zManager._unit_matches_cpuinfocCsH|jdkrdS|jjtj}|dkr2djtj}tj |j|tj dk S)NT ) Z uname_regexr rrZCFG_UNAME_STRINGjoinosunamerrr)rrZ uname_stringrrr_unit_matches_uname6s  zManager._unit_matches_unamec Cs2g}xt|jD]\}}|js0tjd|q|j|sJtjd|q|j|sdtjd|q|jjd|j t |jd|jd<|j |qW|j dddt j}x"|D]}|jjdd||j<qWxt|jD]\}}y$|jj|}|||<|jj |Wqtjjjk r8tjd|wYqtk rt} z tjd |tj| wWYdd} ~ XqXqWg} xf|D]^}||j}|dkrqtjd |j|jf|j|j|j|j|j |j!|j} | j | qWx0| D](} | j"j#| j"j$| | j"j%| qW|j&j'|j(j)| dS) Nzskipping disabled instance '%s'z.skipping instance '%s', cpuinfo does not matchz,skipping instance '%s', uname does not matchprioritycSs |jdS)Nr#)options)xrrrPsz Manager.create..)keyz2skipping plugin '%s', not supported on your systemzfailed to initialize plugin %szcreating '%s' (%s))*listitemsZenabledlogdebugrr"r$ setdefaultr intappendsort collections OrderedDictpoptypercreater tunedr exceptionsZNotSupportedPluginExceptioninfo ExceptionerrorZ exceptionnameZcreate_instanceZdevicesZdevices_udev_regexZ script_preZ script_postpluginZ init_devicesZassign_free_devicesZinitialize_instancer Zstart_processing_eventsr extend) rZinstances_configZinstance_info_listZ instance_nameZ instance_infoZplugins_by_nameZ plugin_nameZnoner;erZ new_instanceinstancerrrr4?s\             zManager.createcOsXy |||Stk rR}z,tj}tjd|t|ftj||Sd}~XnXdS)Nz"BUG: Unhandled exception in %s: %s)r8 traceback format_excr*r9str)rZcallerZexc_retfargskwargsr=Ztracerrr _try_callus  zManager._try_callcCsx2|jD](}tjd|j|jdd|jj|qWx.|jD]$}tjd|j|jdd|jqr;rrrrFs    zManager.destroy_allcCs4x.|jjD]"}tjd||jdd|jq WdS)Nzupdating monitor %supdate_monitors)rZmonitorsr*r+rEupdate)rZmonitorrrrrGszManager.update_monitorscCs$x|jD]}|jdd|jqWdS)N start_tuning)r rEZ apply_tuning)rr>rrrrIs zManager.start_tuningcCs6d}x,|jD]"}|jdd|j|}|dkr d}q W|S)NT verify_tuningF)r rErJ)rZignore_missingretr>resrrrrJs  zManager.verify_tuningcCs$x|jD]}|jdd|jqWdS)N update_tuning)r rErM)rr>rrrrMs zManager.update_tuningcCs4|jjx$t|jD]}|jdd|j|qWdS)N stop_tuning)r Zstop_processing_eventsreversedr rEZunapply_tuning)rZrollbackr>rrrrNs zManager.stop_tuning)N)__name__ __module__ __qualname____doc__rpropertyrrrrr"r4rErFrGrIrJrMrZ ROLLBACK_SOFTrN __classcell__rr)rrrs     6    )r0r rr?Ztuned.exceptionsr5Z tuned.logsZtuned.plugins.exceptionsZ tuned.constsrZtuned.utils.global_configrZtuned.utils.commandsrZlogsrr*__all__objectrrrrrs