o
    #j4+                     @   s   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ eeZG d
d de
ZdS )z1
This module provides a client class for EIP TP.
    N)utils)bce_v1_signer)BceBaseClient)bce_http_client)handler)http_methods)requiredc                   @   s   e Zd ZdZdZdZdddZeee	d		ddd	Z
eee	d		dd
dZee	ddddZ		dddZedd ZedddZdd Z		dddZdS )EipTpClientz
    EIP_TP sdk client
    s   /v1s   /eiptpNc                 C   s   t | | dS )zV
        :type config: baidubce.BceClientConfiguration
        :param config:
        N)r   __init__)selfconfig r   d/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/baidubce/services/eip/eip_tp_client.pyr
   ,   s   zEipTpClient.__init__)reservation_lengthcapacityc           
      C   sf   ||d}|dur||d< |dur||d< |   }|du r!|  }d|i}	| jtj|t||	|dS )a1  
        Create an eip_tp with the specified options.

        :type reservation_length: int
        :param reservation_length: the reservation length of the eip_tp including 1, 6 and 12 months.

        :type capacity: string
        :param capacity: the capacity of the eip_tp.
        When reservationLength = 1 => capacity: {"10G"/"50G"/"100G"/"500G"/"1T"/"5T"/"10T"/"50T"}
        When reservationLength = 6 => capacity: {"60G"/"300G"/"600G"/"3T"/"6T"/"30T"/"60T"/"300T"}
        When reservationLength = 12 => capacity: {"1T"/"10T"/"50T"/"100T"/"500T"/"1P"}

        :type deduct_policy: string
        :param deduct_policy: the deduct policy of the eip_tp including 'FullTimeDurationPackage'
        and 'TimeDurationPackage'.
        The default deduct policy is 'FullTimeDurationPackage', the optional parameter.

        :type package_type: string
        :param package_type: the eip_tp package type.
        The default package type is 'WebOutBytes', the optional parameter.

        :type client_token: string
        :param client_token: if the clientToken is not specified by the user,
         a random string generated by default algorithm will be used.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: created eip_tp id, for example,{"id":"tp-xxxxxxxxxx"}
        ZreservationLengthr   NdeductPolicypackageType   clientTokenbodyparamsr   )	_get_path_generate_default_client_token_send_requestr   POSTjsondumps
r   r   r   deduct_policyZpackage_typeZclient_tokenr   r   pathr   r   r   r   create_eip_tp3   s    #

zEipTpClient.create_eip_tpc           
      C   sn   ||d}|dur||d< |dur||d< t |  d}|du r%|  }d|i}	| jtj|t||	|dS )a>  
        Get the price of creating an eip_tp with the specified options.

        :type reservation_length: int
        :param reservation_length: the reservation length of the eip_tp including 1, 6 and 12 months.

        :type capacity: string
        :param capacity: the capacity of the eip_tp.
        When reservationLength = 1 => capacity: {"10G"/"50G"/"100G"/"500G"/"1T"/"5T"/"10T"/"50T"}
        When reservationLength = 6 => capacity: {"60G"/"300G"/"600G"/"3T"/"6T"/"30T"/"60T"/"300T"}
        When reservationLength = 12 => capacity: {"1T"/"10T"/"50T"/"100T"/"500T"/"1P"}

        :type deduct_policy: string
        :param deduct_policy: the deduct policy of the eip_tp including 'FullTimeDurationPackage'
        and 'TimeDurationPackage'.
        The default deduct policy is 'FullTimeDurationPackage', the optional parameter.

        :type package_type: string
        :param package_type: the eip_tp package type.
        The default package type is 'WebOutBytes', the optional parameter.

        :type client_token: string
        :param client_token: if the clientToken is not specified by the user,
         a random string generated by default algorithm will be used.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: eip_tp price, for example, {"price": "7.20000"}
        r   Nr   r   Zpricer   r   )	r   
append_urir   r   r   r   r   r   r   r   r   r   r   get_eip_tp_priceg   s    "

zEipTpClient.get_eip_tp_price)idc                 C   s$   t |  |}| jtj|d|dS )a  
        get the eip_tp's detail owned by the authenticated user by the passed eip_tp_id.

        :type id: string
        :param id: eip_tp's id.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: detail of eip_tp, for example:
                {
                  "id":"tp-87V5cnkwqO",
                  "deductPolicy":"TimeDurationPackage",
                  "packageType":"WebOutBytes",
                  "status":"RUNNING",
                  "capacity": 10737418240,
                  "usedCapacity": 0,
                  "createTime":"2021-04-10T11:40:57Z",
                  "activeTime": "2021-04-10T11:41:16Z",
                  "expireTime:" "2021-05-10T11:41:16Z"
                }
        Nr   r   )r   r"   r   r   r   GET)r   r$   r   r    r   r   r   get_eip_tp_detail   s   zEipTpClient.get_eip_tp_detail  c           	      C   sp   |   }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< | jtj|||dS )a  
        get a list of eip_tp owned by the authenticated filtered by specific conditions.

        :type id: string
        :param id: eip_tp's id, the optional parameter.

        :type deduct_policy: string
        :param deduct_policy: eip_tp's deduct policy, 'FullTimeDurationPackage' or 'TimeDurationPackage', the optional parameter.

        :type status: string
        :param status: eip_tp's status, 'RUNNING', 'EXPIRED' or 'USED_UP', the optional parameter.

        :type marker: string
        :param marker: The optional parameter marker specified in the original
         request to specify where in the results to begin listing.

        :type max_keys: int
        :param max_keys: The optional parameter to specifies the max number
         of list result to return. The default value is 1000.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: list of eip_tp model, for example:
                {
                    "marker": "tp-87V5cnkwqO",
                    "maxKeys": 1,
                    "nextMarker": "tp-Qn65tYXAx3",
                    "isTruncated": true,
                    "packageList": [
                        {
                           "id":"tp-87V5cnkwqO",
                           "deductPolicy":"TimeDurationPackage",
                           "packageType":"WebOutBytes",
                           "status":"RUNNING",
                           "capacity": 10737418240,
                           "usedCapacity": 0,
                           "createTime":"2021-04-10T11:40:57Z",
                           "activeTime": "2021-04-10T11:41:16Z",
                           "expireTime:" "2021-05-10T11:41:16Z"
                        }
                    ]
                }
       Ns   ids   deductPolicys   statuss   markers   maxKeysr%   )r   r   r   r&   )	r   r$   r   statusmarkerZmax_keysr   r    r   r   r   r   list_eip_tps   s   /zEipTpClient.list_eip_tpsc                   C   s   t  S )z/
        default client token by uuid1
        )uuiduuid1r   r   r   r   r      s   z*EipTpClient._generate_default_client_tokenc                 C   s   | du rt j} tt j| S )zI
        :type prefix: string
        :param prefix: path prefix
        N)r	   prefixr   r"   version)r.   r   r   r   r      s   zEipTpClient._get_pathc                 C   s(   |du r| j S t| j }|| |S )zg
        :type config: baidubce.BceClientConfiguration
        :param config:
        :return:
        N)r   copyZmerge_non_none_values)r   r   Z
new_configr   r   r   _merge_config	  s
   
zEipTpClient._merge_configc              
   C   sJ   |  |}|du rtj}|du rddd}t|tjtj|g|||||S )a  
        :param http_method:
        :param path:
        :param body:
        :param headers:
        :param params:

        :type config: baidubce.BceClientConfiguration
        :param config:

        :param body_parser:

        :return: baidubce.BceResponse
        Ns   */*s   application/json;charset=utf-8)s   Accepts   Content-Type)r1   r   Z
parse_jsonr   send_requestr   signZparse_error)r   Zhttp_methodr    r   headersr   r   Zbody_parserr   r   r   r     s   

zEipTpClient._send_request)N)NNNN)NNNNr(   N)NNNNN)__name__
__module____qualname____doc__r/   r.   r
   r   intstrr!   r#   r'   r+   staticmethodr   r   r1   r   r   r   r   r   r	   %   s8    

25
>
	r	   )r8   r0   r   loggingr,   Zbaidubcer   Zbaidubce.authr   Zbaidubce.bce_base_clientr   Zbaidubce.httpr   r   r   Zbaidubce.utilsr   	getLoggerr5   _loggerr	   r   r   r   r   <module>   s   
