HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/libcloud/__pycache__/pricing.cpython-310.pyc
o

;j�-�@s6dZddlZddlZddlmZmZmZddlmZ	zddl
ZzejZWne
y/eZYnwWney@ddlZeZYnwgd�ZdZdZej�ej�e��Ze	ed�Zej�d	�Ziid
�ZddgZd
Zd#dd�Zd$dd�Zdd�Z d#dd�Z!d%dd�Z"d&dd�Z#dd�Z$dd�Z%dd �Z&eefd!d"�Z'dS)'z2
A class which handles loading the pricing files.
�N)�Dict�Union�Optional)�join)�get_pricing�get_size_price�get_image_price�set_pricing�clear_pricing_data�download_pricing_filezYhttps://git.apache.org/repos/asf?p=libcloud.git;a=blob_plain;f=libcloud/data/pricing.jsonz;https://libcloud-pricing-data.s3.amazonaws.com/pricing.jsonzdata/pricing.jsonz~/.libcloud/pricing.json)�compute�storagerr
FcCs tj�t�rtj�t�rtStS�N)�os�path�exists�CUSTOM_PRICING_FILE_PATH�isfile�DEFAULT_PRICING_FILE_PATH��	file_path�r�D/opt/saltstack/salt/lib/python3.10/site-packages/libcloud/pricing.py�get_pricing_file_pathBsrc	Cs�|pt}|tvr
td|��|t|vrt||S|s t|d�}t|��}|��}Wd�n1s3wYt�|�}|||}|rYtD]}|�	|d�}|sRqG|t|<qG|St
|||d�|S)a�
    Return pricing for the provided driver.

    NOTE: This method will also cache data for the requested driver
    memory.

    We intentionally only cache data for the requested driver and not all the
    pricing data since the whole pricing data is quite large (~2 MB). This
    way we avoid unnecessary memory overhead.

    :type driver_type: ``str``
    :param driver_type: Driver type ('compute' or 'storage')

    :type driver_name: ``str``
    :param driver_name: Driver name

    :type pricing_file_path: ``str``
    :param pricing_file_path: Custom path to a price file. If not provided
                              it uses a default path.

    :type cache_all: ``bool``
    :param cache_all: True to cache pricing data in memory for all the drivers
                      and not just for the requested one.

    :rtype: ``dict``
    :return: Dictionary with pricing where a key name is size ID and
             the value is a price.
    zInvalid driver type: %srN��driver_type�driver_name�pricing)�CACHE_ALL_PRICING_DATA�VALID_PRICING_DRIVER_TYPES�AttributeError�PRICING_DATAr�open�read�json�loads�getr	)	rrZpricing_file_pathZ	cache_all�fp�contentZpricing_dataZdriver_pricingrrrrrKs*



�

�rcCs|t||<dS)a?
    Populate the driver pricing dictionary.

    :type driver_type: ``str``
    :param driver_type: Driver type ('compute' or 'storage')

    :type driver_name: ``str``
    :param driver_name: Driver name

    :type pricing: ``dict``
    :param pricing: Dictionary where a key is a size ID and a value is a price.
    N�r!rrrrr	�sr	cCsft||d�}|dusJ�d}z|durt||�}W|St|||�}W|Sty2d}Y|Sw)a�
    Return price for the provided size.

    :type driver_type: ``str``
    :param driver_type: Driver type ('compute' or 'storage')

    :type driver_name: ``str``
    :param driver_name: Driver name

    :type size_id: ``str`` or ``int``
    :param size_id: Unique size ID (can be an integer or a string - depends on
                    the driver)

    :rtype: ``float``
    :return: Size price.
    �rrN)r�float�KeyError)rrZsize_idZregionr�pricerrrr�s���r�cCs|dkrt|||d�SdS)N�
gce_images)�
image_name�	size_name�coresr)�_get_gce_image_price)rr0r1r2rrrr�srcCs�dd�}||�}|sdStddd�}z||}Wn
ty"YdSwd}d|vr,d}nd	|vr2d	}|��}|D]�}	|	d
kr?q8t�d|	�rW|t|	d�krWt||	d�St�d
|	�rmt|�|	vrmt||	d�St�d|	�r�|t|	d�kr�t||	d�S|	dvr�|	|vr�t||	d�S|	dvr�||	kr�t||	d�S|	dkr�t||	d�}
d|vr�|
|S|
Sq8dS)aR
    Return price per hour for an gce image.
    Price depends on the size of the VM.

    :type image_name: ``str``
    :param image_name: GCE image full name.
                       Can be found from GCENodeImage.name

    :type size_name: ``str``
    :param size_name: Size name of the machine running the image.
                      Can be found from GCENodeSize.name

    :type cores: ``int``
    :param cores: The number of the CPUs the machine running the image has.
                  Can be found from GCENodeSize.extra['guestCpus']

    :rtype: ``float``
    :return: Image price
    cSstd}d|vr
d}|Sd|vrd}|Sd|vrd|vrd}|Sd|vr*d|vr*d	}|Sd|vr2d
}|Sd|vr8d}|S)NZsqlz
SQL ServerZwindowszWindows ServerZrhelZsapzRHEL with Update Services�sleszSLES for SAPZRHELZSLESr)r0�image_familyrrr�_get_gce_image_family�s&�	����z3_get_gce_image_price.<locals>._get_gce_image_familyrrr/r*�any�f1�g1�descriptionz.{1}vcpu or lessr-z
.{1}-.{1}vcpuz.{1}vcpu or more>ZwebZstandardZ
enterprise>r9r8r4)rr,�keys�re�search�intr+�str)r0r1r2r6r5rZ
price_dictZ	size_typeZprice_dict_keys�keyr-rrrr3�sD��r3cCsitd<itd<dS)z7
    Invalidate pricing cache for all the drivers.
    rr
Nr)rrrr�invalidate_pricing_cachesrAcCs
t�dS)z�
    Invalidate pricing cache for all the drivers.

    Note: This method does the same thing as invalidate_pricing_cache and is
    here for backward compatibility reasons.
    N)rArrrrr
's
r
cCs|t|vr
t||=dSdS)z�
    Invalidate the cache for the specified driver.

    :type driver_type: ``str``
    :param driver_type: Driver type ('compute' or 'storage')

    :type driver_name: ``str``
    :param driver_name: Driver name
    Nr)r*rrr�invalidate_module_pricing_cache2s�rBc	Cs�ddlm}tj�|�}tj�|�sd�||�}t|��tj�|�r0tj�|�r0d|}t|��||�}|j	}zt
�|�}Wn
tyKd}t
|��w|�dd�sXd}t
|��t|d��}|�|�Wd�dS1snwYdS)	a
    Download pricing file from the file_url and save it to file_path.

    :type file_url: ``str``
    :param file_url: URL pointing to the pricing file.

    :type file_path: ``str``
    :param file_path: Path where a download pricing file will be saved.
    r)�get_response_objectz.Can't write to {}, directory {}, doesn't existz4Can't write to %s file path because it's a directoryz/Provided URL doesn't contain valid pricing data�updatedN�w)Zlibcloud.utils.connectionrCrr�dirnamer�format�
ValueError�isdir�bodyr$r%�JSONDecodeError�	Exceptionr&r"�write)	Zfile_urlrrCZdir_name�msg�responserJ�dataZfile_handlerrrrAs,�"�rr)NF)Nr.)r.)(�__doc__r<Zos.pathr�typingrrrrZpjoinZ
simplejsonr$rKr rH�ImportError�__all__ZDEFAULT_FILE_URL_GITZDEFAULT_FILE_URL_S3_BUCKETrrF�abspath�__file__ZCURRENT_DIRECTORYr�
expanduserrr!rrrrr	rrr3rAr
rBrrrrr�<module>sH
���




	B

#
T