HEX
Server: Apache
System: Linux a16-asgard6.hospedagemuolhost.com.br 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: maoristu4c3dbd03 (1436)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/cloud_what/__pycache__/provider.cpython-39.pyc
a

X�ZhY)�
@s�dZddlmZmZmZddlZddlZzddlmZddl	m
Z
Wn*eynddlm
ZddlmZ
Yn0ddlmZdd	lmZdd
lmZddlmZeeegZe�e�ZGdd
�d
ej�Zed�dd�Zddejfee eee!e"fd�dd�Z#ddejfee eeeeeedfd�dd�Z$ddejfee eee%d�dd�Z&edk�r�ddl'Z'e��Z(e(�)ej*�e�+e'j,�Z-e-�)ej*�e�.d�Z/e-�0e/�e(�1e-�e&�Z2e3de2���ddlm
Z
e
�Z4e4�5�Z6e&e6�Z2e3de2���dS)zC
This module contains several utils used for VMs running on clouds
�)�Union�Tuple�ListN)�
HostCollector)�CustomFactsCollector)�MiniHostCollector)�MiniCustomFactsCollector)�BaseCloudProvider)�AWSCloudProvider)�AzureCloudProvider)�GCPCloudProviderc@s(eZdZdZe��Ze��ZeeBZdS)�DetectionMethodzN
    Enumeration of allowed methods used for detection of cloud providers
    N)	�__name__�
__module__�__qualname__�__doc__�enum�auto�STRONG�	HEURISTIC�ALL�rr�9/usr/lib64/python3.9/site-packages/cloud_what/provider.pyr
3sr
)�returncCs(i}|�t����|�t����|S)zx
    Try to gather system facts necessary for detection of cloud provider
    :return: Dictionary with system facts
    )�updater�get_allr��factsrrr�gather_system_factsBsrg�?)r�	threshold�methodsrcs��durt���fdd�tD�}t�d�g}tj|vr�|D]}|��}|dur<|�|�q<t|�dkr�t�dj	|dj
d	��|dfSt|�dkr�t�d
�q�t|�dkr�t�dj	d�d
d�|D��d��n
t�d�tj
|v�r�g}|D]:}|��}t�d|j
�d|���||kr�|�||f�q�|jdd�dd�dd�|D�}t|�dk�rdt�d�n"t�dj	d�dd�|D��d��n
t�d�|dfS)aI
    This method tries to detect cloud providers and return list of possible cloud providers
    :param facts: Dictionary with system facts
    :param threshold: Threshold using for detection of cloud provider
    :param methods: The flag of methods used for detecting of cloud providers
    :return: List of cloud providers
    Ncsg|]}|���qSrr)�.0�clsrrr�
<listcomp>d�z(_get_cloud_providers.<locals>.<listcomp>zTrying to detect cloud providerT�z:Detected one cloud provider using strong signs: {provider}r�Zproviderz-No cloud provider detected using strong signszFMore than one cloud provider detected using strong signs ({providers})z, cSsg|]
}|j�qSr��CLOUD_PROVIDER_ID�r!�cloud_providerrrrr#~r$)Z	providersz7Skipping detection of cloud provider using strong signszCloud provider z has probability: cSs|dS)Nrr)�xrrr�<lambda>�r$z&_get_cloud_providers.<locals>.<lambda>)�key�reversecSsg|]}|d�qS)r%r)r!�itemrrrr#�r$z+No cloud provider detected using heuristicsz@Following cloud providers detected using heuristics: {providers}cSsg|]
}|j�qSrr'r)rrrr#�r$z5Skipping detection of cloud providers using heuristicF)r�CLOUD_PROVIDERS�log�debugr
rZis_running_on_cloud�append�len�formatr(�error�joinrZis_likely_running_on_cloud�sort)rrr Zcloud_providers�
cloud_listr*Zcloud_detectedZprobabilityrrr�_get_cloud_providersSsX


����
��
r:cCs|t|||�\}}t|�dkr,|dur,|dSt|�dkrx|D]0}|��}|dur<t�dj|jd��|Sq<t�d�dS)ai
    This method tries to detect cloud provider and return corresponding instance of
    cloud provider.
    :param facts: Dictionary with system facts
    :param threshold: Threshold used for heuristic detection of cloud provider
    :param methods: The flag of methods used for detecting of cloud providers
    :return: Instance of cloud provider or None
    r%TrNzKMetadata gathered from cloud provider detected using heuristics: {provider}r&zHUnable to get metadata from any cloud provider detected using heuristics)r:r4Zget_metadatar1�infor5r(r2)rrr r9�strong_signr*�metadatarrr�get_cloud_provider�s
��

r>cCs"t|||�\}}dd�|D�}|S)a�
    This method tries to detect cloud provider using hardware information provided by dmidecode.
    When there is strong sign that the VM is running on one of the cloud provider, then return
    list containing only one provider. When there is no strong sign of one cloud provider, then
    try to detect cloud provider using heuristics methods. In this case this method will return
    list of all cloud providers sorted according detected probability
    :param facts: dictionary of facts. When no facts are provided, then hardware, virtualization
        and custom facts are gathered.
    :param threshold: Threshold used for heuristic detection of cloud provider
    :param methods: The flag of methods used for detection of cloud providers (possible enumerates
        are following in DetectionMethod). When only STRONG is listed, then detection is
        performed only using strong signs. When only HEURISTIC is listed, then only heuristics
        detections is used. When both methods are listed, then this method tries to use detection
        using strong signs first and if no cloud provider is detected, then it falls back to
        heuristics detection.
    :return: List of string representing detected cloud providers. E.g. ['aws'] or ['aws', 'gcp']
    cSsg|]
}|j�qSrr'r)rrrr#�r$z)detect_cloud_provider.<locals>.<listcomp>)r:)rrr r9r<rrr�detect_cloud_provider�sr?�__main__z4%(asctime)s - %(name)s - %(levelname)s - %(message)sz>>> debug <<< detector result: z.>>> debug <<< detector result (minimalistic): )7r�typingrrrrZloggingZrhsmlib.facts.host_collectorrZrhsmlib.facts.customr�ImportErrorZcloud_what.fact_collectorrrZcloud_what._base_providerr	Zcloud_what.providers.awsr
Zcloud_what.providers.azurerZcloud_what.providers.gcprr0Z	getLoggerrr1�Flagr
�dictrr�float�list�boolr:r>�strr?�sys�rootZsetLevel�DEBUGZ
StreamHandler�stdoutZhandlerZ	Formatter�	formatterZsetFormatterZ
addHandlerZ_detector_result�printZ	collectorrZ_factsrrrr�<module>s~�
�
�R��(��!