????

Your IP : 18.119.110.152


Current Path : /lib/python3.6/site-packages/glances/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/glances/__pycache__/server.cpython-36.opt-1.pyc

3

Eo�c �@s�dZddlmZddlZddlZddlmZddlmZddl	m
Z
mZddlm
Z
ddlmZdd	lmZdd
lmZGdd�de
e�ZGd
d�dee�ZGdd�de�ZGdd�de�ZdS)zManage the Glances server.�)�
json_dumpsN)�	b64decode)�__version__)�SimpleXMLRPCRequestHandler�SimpleXMLRPCServer)�GlancesAutoDiscoverClient)�logger)�GlancesStatsServer)�TimercsLeZdZdZdZ�fdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
�ZS)�GlancesXMLRPCHandlerzMain XML-RPC handler.�/RPC2cs|j�tt|�j�dS)N)�send_my_headers�superr�end_headers)�self)�	__class__��/usr/lib/python3.6/server.pyrsz GlancesXMLRPCHandler.end_headerscCs|jdd�dS)NzAccess-Control-Allow-Origin�*)Zsend_header)rrrrr
%sz$GlancesXMLRPCHandler.send_my_headersc
Cs�y|jd�jd�\}}}Wntk
r4|jjSX|jd�jd�\}}}|j�}t|�}|j�}|jd�\}}}	|j||	�SdS)NZ
Authorization� �:)	�get�	partition�	Exception�server�isAuth�encoder�decode�
check_user)
r�headersZbasic�_ZencodedZencoded_byte_stringZ
decoded_bytes�decoded_string�username�passwordrrr�authenticate)sz!GlancesXMLRPCHandler.authenticatecCsB||jjkr:ddlm}|||jd�}|j|jj||�SdSdS)Nr)�GlancesPassword)r"�configF)r�	user_dictZglances.passwordr%r&Zcheck_password)rr"r#r%�pwdrrrrAs
zGlancesXMLRPCHandler.check_usercCs*tj|�r&|j|j�rdS|jdd�dS)NTi�zAuthentication failedF)r�
parse_requestr$rZ
send_error)rrrrr)Ks

z"GlancesXMLRPCHandler.parse_requestcGsdS)Nr)rZ
log_format�argsrrr�log_messageUsz GlancesXMLRPCHandler.log_message)r)�__name__�
__module__�__qualname__�__doc__Z	rpc_pathsrr
r$rr)r+�
__classcell__rr)rrrs

rcs<eZdZdZdZdedf�fdd�	Zdd�Zd	d
�Z�Z	S)�GlancesXMLRPCServerz0Init a SimpleXMLRPCServer instance (IPv6-ready).Fi�Ncs�||_||_||_ytj||�dd|_Wn>tjk
rj}z tjdj|��t	j
d�WYdd}~XnXtt|�j
||f|�dS)NrzCouldn't open socket: {}�)�bind_address�	bind_portr&�socketZgetaddrinfoZaddress_family�errorr�format�sys�exitrr1�__init__)rr3r4�requestHandlerr&�e)rrrr:`szGlancesXMLRPCServer.__init__cCs|j�d|_dS)zStop the serverTN)Zserver_close�finished)rrrr�endmszGlancesXMLRPCServer.endcCsx|js|j�qWdS)z	Main loopN)r=Zhandle_request)rrrr�
serve_foreverrsz!GlancesXMLRPCServer.serve_forever)
r,r-r.r/r=rr:r>r?r0rr)rrr1Zs

r1c@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�GlancesInstancez?All the methods of this class are published as XML-RPC methods.NcCs.t||d�|_|jj�td�|_|j|_dS)N)r&r*r)r	�stats�updater
�timer�cached_time)rr&r*rrrr:|s

zGlancesInstance.__init__cCs$|jj�r |jj�t|j�|_dS)N)rCr=rArBr
rD)rrrr�
__update__�s

zGlancesInstance.__update__cCstS)N)r)rrrr�init�szGlancesInstance.initcCs|j�t|jj��S)N)rErrA�getAll)rrrrrG�szGlancesInstance.getAllcCst|jj��S)N)rrAZgetPluginsList)rrrr�
getAllPlugins�szGlancesInstance.getAllPluginscCst|jj��S)N)rrAZgetAllLimitsAsDict)rrrr�getAllLimits�szGlancesInstance.getAllLimitscCst|jj��S)N)rrAZgetAllViewsAsDict)rrrr�getAllViews�szGlancesInstance.getAllViewscCsNd}|j|�rBy|j�t|j|�Stk
r>t|��YqJXnt|��dS)z�Overwrite the getattr method in case of attribute is not found.

        The goal is to dynamically generate the API get'Stats'() methods.
        rN)�
startswithrE�getattrrAr�AttributeError)r�item�headerrrr�__getattr__�s
zGlancesInstance.__getattr__)NN)r,r-r.r/r:rErFrGrHrIrJrPrrrrr@xs

r@c@s8eZdZdZeddfdd�Zdd�Zdd�Zd	d
�ZdS)�
GlancesServerz.This class creates and manages the TCP server.NcCs�||_yt|j|j||d�|_Wn<tk
r\}z tjdj|��t	j
d�WYdd}~XnXtdj|j|j��i|j_d|j_
|jj�|jjt||��|jjs�tjdjtj�jdd�d	��ttj�jdd�d	|�|_n
tjd
�dS)N)r&zCannot start Glances server: {}�z*Glances XML-RPC server is running on {}:{}Fz,Autodiscover is enabled with service name {}�.r2rz)Glances autodiscover announce is disabled)r*r1r3ZportrrrZcriticalr7r8r9�printr'rZ register_introspection_functionsZregister_instancer@�disable_autodiscover�infor5Zgethostname�splitr�autodiscover_client)rr;r&r*r<rrrr:�s
 zGlancesServer.__init__cCs||jj|<d|j_dS)zAdd an user to the dictionary.TN)rr'r)rr"r#rrr�add_user�szGlancesServer.add_usercCs.|jjdkr |j|jj|jj�|jj�dS)zCall the main loop.�N)r*r#rYr"rr?)rrrrr?�szGlancesServer.serve_forevercCs |jjs|jj�|jj�dS)z"End of the Glances server session.N)r*rUrX�closerr>)rrrrr>�s
zGlancesServer.end)	r,r-r.r/rr:rYr?r>rrrrrQ�s
rQ)r/Zglances.globalsrr5r8�base64rZglancesrZglances.compatrrZglances.autodiscoverrZglances.loggerrZglances.stats_serverr	Z
glances.timerr
�objectrr1r@rQrrrr�<module>
sAA