HEX
Server: LiteSpeed
System: Linux baran.dnsprotection.me 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: ddir12 (3618)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/glances/plugins/__pycache__/glances_cloud.cpython-36.pyc
3

Eo�c��@s�dZddlZddlmZmZddlmZddlmZyddl	Z	Wn6e
k
rvZzdZej
dje��WYddZ[XnXdZGd	d
�d
e�ZGdd�dej�ZdS)
zjCloud plugin.

Supported Cloud API:
- OpenStack meta data (class ThreadOpenStack, see below): AWS, OVH...
�N)�	iteritems�to_ascii)�
GlancesPlugin)�loggerTz1Missing Python Lib ({}), Cloud plugin is disabledFcsLeZdZdZd�fdd�	Z�fdd�Zejejdd���Z	dd	d
�Z
�ZS)
�Pluginz�Glances' cloud plugin.

    The goal of this plugin is to retrieve additional information
    concerning the datacenter where the host is connected.

    See https://github.com/nicolargo/glances/issues/1029

    stats is a dict
    Ncs8tt|�j||d�d|_|j�t�|_|jj�dS)zInit the plugin.)�args�configTN)�superr�__init__Z
display_curse�reset�ThreadOpenStack�	OPENSTACK�start)�selfrr)�	__class__��#/usr/lib/python3.6/glances_cloud.pyr
,s
zPlugin.__init__cs|jj�tt|�j�dS)z+Overwrite the exit method to close threads.N)r
�stopr	r�exit)r)rrrr<s
zPlugin.exitcCs.|j�}tr|S|jdkr"|jj}||_|jS)zAUpdate the cloud stats.

        Return the stats (dict)
        Zlocal)Zget_init_value�import_error_tagZinput_methodr
�stats)rrrrr�updateBs
	z
Plugin.updatecCs�g}|js|jiks|j�r"|Sd|jkr�d|jkr�d|jkr�d}|j|j|d��dj|jd|jd|jd�}|j|j|��|S)z4Return the string to display in the curse interface.z
instance-typezinstance-id�regionzCloud ZTITLEz{} instance {} ({}))rZis_disabled�appendZcurse_add_line�format)rrZ	max_width�ret�msgrrr�	msg_curse_szPlugin.msg_curse)NN)NN)�__name__�
__module__�__qualname__�__doc__r
rrZ_check_decoratorZ_log_result_decoratorrr�
__classcell__rr)rrr!s	rcsfeZdZdZdZddddd�Z�fdd	�Zd
d�Zedd
��Z	e	j
dd
��Z	ddd�Zdd�Z�Z
S)rzG
    Specific thread to grab OpenStack stats.

    stats is a dict
    z'http://169.254.169.254/latest/meta-datazami-idzinstance-idz
instance-typezplacement/availability-zone)zami-idzinstance-idz
instance-typercs,tjd�tt|�j�tj�|_i|_dS)zInit the class.z3cloud plugin - Create thread for OpenStack metadataN)	r�debugr	rr
�	threadingZEvent�_stopper�_stats)r)rrrr
�s

zThreadOpenStack.__init__cCs�tr|j�dSx�t|j�D]v\}}dj|j|�}ytj|dd�}Wn6tk
rz}zt	j
dj||��PWYdd}~XqX|jrt|j
�|j|<qWdS)zdGrab plugin's stats.

        Infinite loop, should be stopped by calling the stop() method
        Fz{}/{}�)�timeoutzBcloud plugin - Cannot connect to the OpenStack metadata API {}: {}NT)rrr�OPENSTACK_API_METADATAr�OPENSTACK_API_URL�requests�get�	Exceptionrr#�okrZcontentr&)r�k�vZr_url�r�errr�run�szThreadOpenStack.runcCs|jS)z
Stats getter.)r&)rrrrr�szThreadOpenStack.statscCs
||_dS)z
Stats setter.N)r&)r�valuerrrr�sNcCstjd�|jj�dS)zStop the thread.z2cloud plugin - Close thread for OpenStack metadataN)rr#r%�set)rr(rrrr�s
zThreadOpenStack.stopcCs
|jj�S)z%Return True is the thread is stopped.)r%Zis_set)rrrr�stopped�szThreadOpenStack.stopped)N)rrr r!r*r)r
r3�propertyr�setterrr6r"rr)rrrus	
r)r!r$Zglances.compatrrZglances.plugins.glances_pluginrZglances.loggerrr+�ImportErrorr2rZwarningrrZThreadrrrrr�<module>s"T