o
    lqi6                     @   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jZdd ZeZdS )z0
This module provides a client class for HAVIP.
    N)bce_base_client)bce_v1_signer)bce_http_client)handler)http_methods)required)compatc                   @   s\  e Zd ZdZdZd#ddZd#ddZ		d$dd	Zee	e
fe	e
fe	e
fe	e
fd
		d%ddZee	e
fdd&ddZee	e
fdd&ddZee	e
fe	e
fe	e
fd			d%ddZee	e
fdd#ddZee	e
fge	e
fe	e
fdd&ddZee	e
fge	e
fe	e
fdd&ddZee	e
fe	e
fd		d'dd Zee	e
fdd'd!d"ZdS )(HavipClientz
    Route base sdk client
    s   /v1Nc                 C   s   t j| | d S N)r   BceBaseClient__init__)selfconfig r   k/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/baidubce/services/havip/havip_client.pyr   (   s   zHavipClient.__init__c                 C   s(   |du r| j S t| j }|| |S )zg
        :param config:
        :type config: baidubce.BceClientConfiguration
        :return:
        N)r   copyZmerge_non_none_values)r   r   Z
new_configr   r   r   _merge_config+   s
   
zHavipClient._merge_configc              
   C   sP   |  |}|d u rtj}|d u rddd}t|tjtj|g|tj	| |||S )Ns   */*s   application/json;charset=utf-8)s   Accepts   Content-Type)
r   r   Z
parse_jsonr   send_requestr   signZparse_errorr	   prefix)r   Zhttp_methodpathbodyheadersparamsr   Zbody_parserr   r   r   _send_request8   s   

zHavipClient._send_request)name	subnet_idprivate_ip_addressdescription c                 C   sf   d}i }	|du rt  |	d< n||	d< t|t|t|t|d}
| jtj|t|
|	|dS )aE  
        Create a havip with the specified options.

        :param name:
            The name of havip.
        :type name: string

        :param subnet_id:
            The subnet ID to which the havip belongs.
        :type subnet_id: string

        :param private_ip_address:
            The private_ip_address of the havip
        :type private_ip_address: string

        :param description:
            The option param to describe the havip.
        :type description: string

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
           /havipN   clientToken)r   ZsubnetIdZprivateIpAddressr   r   r   r   )generate_client_tokenr   convert_to_stringr   r   POSTjsondumps)r   r   r   r   r   client_tokenversionr   r   r   r   r   r   r   create_havipD   s   %zHavipClient.create_havip)vpc_idc                 C   s,   d}i }|dur||d< | j tj|||dS )a3  
        Get the detail information of havip list.

        :param vpc_id:
            the vpc id to which the havip belongs
        :type vpc_id: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r    Ns   vpcIdr   r   )r   r   GET)r   r+   r   r   r   r   r   r   get_havip_detail_list{   s
   z!HavipClient.get_havip_detail_list)havip_idc                 C   sB   dt | }i }|du rt |d< n||d< | jtj|||dS )a  
        Delete the  specific havip.

        :param havip_id:
            The id of the specified havip.
        :type havip_id: string

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        	   /havip/%sNr!   r,   )r   convert_to_bytesr#   r   r   DELETE)r   r/   r(   r   r   r   r   r   r   delete_havip   s   zHavipClient.delete_havipr   r/   r   c           
      C   sl   dt | }ddi}|du rt |d< n||d< t |t |t |d}	| jtj|t|	||dS )a  
        Update a havip with the specified options.

        :param name:
            The name of the havip to be updated.
        :type route_rule_id: string

        :param havip_id:
            The id of the specified havip.
        :type havip_id: string

        :param description:
            The option param to describe the route rule.
        :type description: string

        :param action:
            Action.
        :type action: string, default: modifyAttribute

        :param version:
            API version.
        :type version: string

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r0   s   modifyAttributeNr!   r4   r"   	r   r1   r#   r$   r   r   PUTr&   r'   )
r   r   r/   r   r)   r(   r   r   r   r   r   r   r   update_havip   s   (zHavipClient.update_havipc                 C   s&   dt | }i }| jtj|||dS )a,  
        Get the detail information of a specific havip.

        :param havip_id:
            The id of the havip.
        :type havip_id: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r0   r,   )r   r1   r   r   r-   )r   r/   r   r   r   r   r   r   get_havip_detail   s   zHavipClient.get_havip_detailinstance_idsinstance_typer/   c           	      C   sd   dt | }ddi}|du rt |d< n||d< t |t |t |d}| jtj|||dS )a
  
        Get the detail information of havip list.

        :param instance_ids:
            the instance ids of havip binding
        :type instance_ids: list
        
        :param instance_type:
            Binding instance type
        :type instance_type: string

        :param havip_id:
            The id of the specified havip.
        :type havip_id: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r0   s   attachNr!   )ZinstanceIdsZinstanceTypehaVipIdr,   )r   r1   r#   r$   r   r   r-   )	r   r:   r;   r/   r   r(   r   r   r   r   r   r   havip_attach_instance   s   z!HavipClient.havip_attach_instancec           	      C   sd   dt | }ddi}|du rt |d< n||d< t |t |t |d}| jtj|||dS )a  
        havip detach instance.

        :param instance_ids:
            the instance ids of havip binding
        :type instance_ids: list
        
        :param instance_type:
            Binding instance type
        :type instance_type: string

        :param havip_id:
            The id of the specified havip.
        :type havip_id: string

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r0   s   detachNr!   r9   r,   )r   r1   r#   r$   r   r   r2   )	r   r:   r;   r/   r(   r   r   r   r   r   r   r   havip_detach_instance&  s   z!HavipClient.havip_detach_instance)r/   public_ip_addressc           	      C   sd   dt | }ddi}|du rt |d< n||d< t |t |d}| jtj|t|||dS )a  
        havip bind public_ip.

        :param havip_id:
            The id of the specified havip.
        :type havip_id: string

        :param public_ip_address:
            The option param to describe public_ip.
        :type description: string

        :param version:
            API version.
        :type version: string

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r0   s   bindPublicIpNr!   )r<   ZpublicIpAddressr"   r5   )	r   r/   r?   r)   r(   r   r   r   r   r   r   r   havip_bind_public_ipU  s   z HavipClient.havip_bind_public_ipc                 C   s\   dt | }ddi}|du rt |d< n||d< dt |i}| jtj|t|||dS )a5  
        havip unbind public_ip.

        :param havip_id:
            The id of the specified havip.
        :type havip_id: string

        :param version:
            API version.
        :type version: string

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r0   s   unbindPublicIpNr!   r/   r"   r5   )r   r/   r)   r(   r   r   r   r   r   r   r   havip_unbind_public_ip  s   
z"HavipClient.havip_unbind_public_ipr
   )NNNNN)r   NNN)NN)NNN)__name__
__module____qualname____doc__r   r   r   r   r   bytesstrr*   r.   r3   r7   r8   r=   r>   r@   rA   r   r   r   r   r	   "   s`    


37

(,-r	   c                   C   s   t t S )z
    The default method to generate the random string for client_token
    if the optional parameter client_token is not specified by the user.

    :return:
    :rtype string
    )rG   uuiduuid4r   r   r   r   generate_client_token_by_uuid  s   rJ   )rE   r   r&   loggingrH   Zbaidubcer   Zbaidubce.authr   Zbaidubce.httpr   r   r   Zbaidubce.utilsr   r   	getLoggerrB   Z_loggerr   r	   rJ   r#   r   r   r   r   <module>   s&   
   