o
    #j                      @   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 )z.
This module provides a client class for EIP.
    N)utils)bce_v1_signer)BceBaseClient)bce_http_client)handler)http_methods)	EipStatusc                   @   sh  e Zd ZdZdZdZdZd@ddZ					dAdd	Z		dBd
dZ			dCddZ
		dDddZdBddZ		dCddZdBddZdBddZdBddZdBddZ			dEddZdFdd ZdGd"d#ZdBd$d%ZdBd&d'ZdBd(d)ZdBd*d+ZdBd,d-Z	dBd.d/ZdBd0d1ZdBd2d3ZdBd4d5Z					dHd6d7Zed8d9 Z ed@d:d;Z!d<d= Z"		dId>d?Z#dS )J	EipClientz
    eip sdk client
    s   /v1s   /eipz	/transferNc                 C   s   t | | dS )zV
        :type config: baidubce.BceClientConfiguration
        :param config:
        N)r   __init__)selfconfig r   a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/baidubce/services/eip/eip_client.pyr
   -   s   zEipClient.__init__c                 C   s   d|i}|dur||d< |dur||d< |dur||d< |dur$||d< |dur,||d< |dur4||d< |	dur<|	|d	< |
durD|
|d
< |du rPddd|d< n|j |j|j|jdd|d< |  }|du rk|  }d|i}| jtj|t	
|||dS )a  
        Create an eip with the specified options.

        :type bandwidth_in_mbps: int
        :param bandwidth_in_mbps: specify the bandwidth in Mbps

        :type name: string
        :param name: name of eip. The optional parameter

        :type billing: Billing
        :param billing: billing information. The optional parameter

        :type route_type: string
        :param route_type: route type (BGP or BGP_S)

        :type ip_version: string
        :param ip_version: IP version (ipv4 or ipv6), default ipv4

        :type tags: list
        :param tags: list of tag key-value pairs

        :type resource_group_id: string
        :param resource_group_id: resource group ID

        :type auto_renew_time_unit: string
        :param auto_renew_time_unit: auto renew time unit (month or year)

        :type auto_renew_time: int
        :param auto_renew_time: auto renew time length

        :type delete_protect: bool
        :param delete_protect: enable delete protection

        :type client_token: string
        :param client_token: idempotent token

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: created eip address, for example,{"eip":"x.x.x.x"}
        ZbandwidthInMbpsNnameZ	routeTypeZ	ipVersiontagsZresourceGroupIdautoRenewTimeUnitautoRenewTimedeleteProtectZPostpaidZByBandwidth)paymentTimingbillingMethodbillingZreservationLengthZreservationTimeUnit)r   r   reservation   clientTokenbodyparamsr   )Zpayment_timingZbilling_methodreservation_lengthreservation_time_unit	_get_path_generate_default_client_token_send_requestr   POSTjsondumps)r   Zbandwidth_in_mbpsr   r   Z
route_type
ip_versionr   Zresource_group_idauto_renew_time_unitauto_renew_timedelete_protectclient_tokenr   r   pathr   r   r   r   
create_eip4   sJ   /


zEipClient.create_eipc                 C   sN   d|i}t |  |}|du r|  }d|d}| jtj||t||dS )a  
        Resizing eip

        :type eip: string
        :param eip: eip address to be resized

        :type new_bandwidth_in_mbps: int
        :param new_bandwidth_in_mbps: specify new bandwidth in Mbps for eip

        :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: BceResponse
        ZnewBandwidthInMbpsN    )s   resizer   r   r   r   	r   
append_urir   r    r!   r   PUTr#   r$   )r   eipZnew_bandwidth_in_mbpsr)   r   r   r*   r   r   r   r   
resize_eip   s   
zEipClient.resize_eipc                 C   sx   |du rdddddii}ndd|j |jdii}t|  |}|du r)|  }d|d}| jtj||t	
||d	S )
aQ  
        PurchaseReserved eip with fixed duration,only Prepaid eip can do this

        :type eip: string
        :param eip: eip address to be renewed

        :type billing: Billing
        :param billing: billing information. The optional parameter,
         default reservationLength is 1

        :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: BceResponse
        Nr   r      ZMonthr   r,   )s   purchaseReservedr   r-   )r   r   r   r/   r   r    r!   r   r0   r#   r$   )r   r1   r   r)   r   r   r*   r   r   r   r   purchase_reserved_eip   s0   

zEipClient.purchase_reserved_eipc           	      C   sh   |du rd}|du rd}||d}t |  |}|du r!|  }d|d}| jtj||t||dS )a  
        Enable auto renew for specified EIP.

        :type eip: string
        :param eip: eip address to be enable to auto-renew.

        :type auto_renew_time_unit: string
        :param auto_renew_time_unit: time unit of auto_renew_time, default 'Month'.

        :type auto_renew_time: int
        :param auto_renew_time: the unit of time for auto renew,
        default auto_renew_time is 1

        :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: BceResponse
        Nmonthr3   )r   r   r,   )s   startAutoRenewr   r-   r.   )	r   r1   r&   r'   r)   r   r   r*   r   r   r   r   start_auto_renew_eip   s    
zEipClient.start_auto_renew_eipc                 C   >   t |  |}|du r|  }d|d}| jtj|||dS )a  
        Disable auto renew for specified EIP.

        :type eip: string
        :param eip: eip address to be disable to auto-renew.

        :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: BceResponse
        Nr,   )s   stopAutoRenewr   r   r   r   r/   r   r    r!   r   r0   r   r1   r)   r   r*   r   r   r   r   stop_auto_renew_eip  s   zEipClient.stop_auto_renew_eipc           
      C   s`   ||d}|dur||d< t |  |}|du r|  }d|d}	| jtj||	t||dS )a  
        bind the eip to a specified instanceId and instanceType

        :type eip: string
        :param eip: eip address to be bound

        :type instance_type: string
        :param instance_type: type of instance to be bound(BCC BLB et.)

        :type instance_id: string
        :param instance_id: id of instance to be bound

        :type instance_ip: string
        :param instance_ip: specific IP address within the instance to bind

        :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: BceResponse
        )ZinstanceTypeZ
instanceIdNZ
instanceIpr,   )s   bindr   r-   r.   )
r   r1   instance_typeinstance_idZinstance_ipr)   r   r   r*   r   r   r   r   bind_eip)  s   
zEipClient.bind_eipc                 C   r7   )a  
        unbind the eip from a specified instance

        :type eip: string
        :param eip: eip address to be unbound

        :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: BceResponse
        Nr,   )s   unbindr   r8   r9   r:   r   r   r   
unbind_eipS  s   zEipClient.unbind_eipc                 C   s<   t |  |}|du r|  }d|i}| jtj|||dS )a2  
        release the eip(delete operation)
        Only the Postpaid instance or Prepaid which is expired can be released.
        if the eip has been bound, must unbind before releasing.

        :type eip: string
        :param eip: eip address to be released

        :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: BceResponse
        Nr   r8   r   r/   r   r    r!   r   DELETEr:   r   r   r   release_eipm  s   zEipClient.release_eipc                 C   r7   )a  
        turn on EIP pass through with the specific parameters.

        :type eip: string
        :param eip: the specific EIP.

        :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: None

        :return: BceResponse
        Nr,   )s   directr   r8   r9   r:   r   r   r   
direct_eip     zEipClient.direct_eipc                 C   r7   )a  
        Remove the direction of an EIP from a specific instance.
        
        :type eip: string
        :param eip: the EIP address to undirect.

        :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: None

        :return: BceResponse
        Nr,   )s   unDirectr   r8   r9   r:   r   r   r   undirect_eip  rD   zEipClient.undirect_eip  c                 C   s   |   }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur4t|tr4|j|d< |dur<||d< |durD||d< |durL||d	< |	durT|	|d
< | jtj|||
dS )a
  
        get a list of eip owned by the authenticated user and specified
        conditions. we can Also get a single eip function  through this
        interface by eip condition

        :type eip: string
        :param eip: eip address condition

        :type instance_type: string
        :param instance_type: bound instance type condition

        :type instance_id: string
        :param instance_id: bound instance id condition
        if query by the instanceId or instanceType condition, must provides
         both of them at the same time

        :type status: string
        :param status of eip condition
        if query by the status condition, must provides

        :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 name: string
        :param name: eip name condition

        :type eip_ids: string
        :param eip_ids: comma-separated EIP IDs for batch query

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: list of eip model, for example:
                {
                    "eipList": [
                        {
                            "name":"eip-xxxxxxx-1",
                            "eip": "x.x.x.x",
                            "status":"binded",
                            "instanceType": "BCC",
                            "instanceId": "i-xxxxxxx",
                            "bandwidthInMbps": 5,
                            "paymentTiming":"Prepaid",
                            "billingMethod":"ByBandwidth",
                            "createTime":"2016-03-08T08:13:09Z",
                            "expireTime":"2016-04-08T08:13:09Z"
                        },
                        {
                            "name":"eip-xxxxxxx-1",
                            "eip": "x.x.x.x",
                            "status":"binded",
                            "instanceType": "BCC",
                            "instanceId": "i-xxxxxxx",
                            "bandwidthInMbps": 1,
                            "paymentTiming":"Postpaid",
                            "billingMethod":"ByTraffic",
                            "createTime":"2016-03-08T08:13:09Z",
                            "expireTime":null
                        },
                    ],
                    "marker":"eip-xxxxxxx-1",
                    "isTruncated": true,
                    "nextMarker": "eip-DCB50387",
                    "maxKeys": 2
                }
        N   eips   instanceTypes
   instanceId   name   status   marker   maxKeyss	   ipVersions   eipIdsr8   )r   
isinstancer   valuer!   r   GET)r   r1   r<   r%   r=   statusmarkermax_keysr   Zeip_idsr   r*   r   r   r   r   	list_eips  s.   J
zEipClient.list_eipsc                 C   sh   t |  d}i }|dur||d< |dur||d< |dur"||d< |dur*||d< | jtj|||dS )aQ  
        list all EIP in the recycle bin with the specific parameters.

        :type eip: string
        :param eip: eip address condition

        :type name: string
        :param name: eip name condition

        :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: None

        :return: list of eip model, for example:
                {
                    "eipList": [
                        {
                            "name":"eip-xxxxxxx-1",
                            "eip": "x.x.x.x",
                            "eip_id":"ip-xxxxxxxx",
                            "status": "paused",
                            "route_type": "BGP",
                            "bandwidth_in_mbps": 5,
                            "payment_timing":"Prepaid",
                            "billing_method":"ByBandwidth",
                            "recycle_time":"2016-03-08T08:13:09Z",
                            "scheduled_delete_time":"2016-04-08T08:13:09Z"
                        },
                        {
                            "name":"eip-xxxxxxx-2",
                            "eip": "x.x.x.x",
                            "eip_id":"ip-xxxxxxxx",
                            "status": "paused",
                            "route_type": "BGP",
                            "bandwidth_in_mbps": 10,
                            "payment_timing":"Postpaid",
                            "billing_method":"ByBandwidth",
                            "recycle_time":"2016-03-08T08:13:09Z",
                            "scheduled_delete_time":"2016-04-08T08:13:09Z"
                        },
                    ],
                    "marker":"ip-xxxxxxxx",
                    "is_truncated": true,
                    "max_keys": 1000
                }
        recycleNrG   rH   rJ   rK   r8   )r   r/   r   r!   r   rN   )r   r1   r   rP   rQ   r   r*   r   r   r   r   list_eip_recycle  s   6zEipClient.list_eip_recycleFc                 C   s>   t |  |}|du r|  }||d}| jtj|||dS )a  
        delete an EIP with additional options.

        :type eip: string
        :param eip: the EIP address to delete.

        :type release_to_recycle: bool
        :param release_to_recycle: flag to release EIP to recycle bin.

        :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: BceResponse
        N)r   s   releaseToRecycler8   r@   )r   r1   Zrelease_to_recycler)   r   r*   r   r   r   r   optional_delete_eip^  s   zEipClient.optional_delete_eipc                 C   s@   t |  d|}|du r|  }d|d}| jtj|||dS )a  
        restore an EIP from the recycle bin.

        :type eip: string
        :param eip: eip address to be restored from recycle bin.

        :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: BceResponse
        rS   Nr,   )s   restorer   r8   r9   r:   r   r   r   restore_recycle_eip|  s   zEipClient.restore_recycle_eipc                 C   >   t |  d|}|du r|  }d|i}| jtj|||dS )a  
        delete an EIP from the recycle bin.

        :type eip: string
        :param eip: eip address to be delete from recycle bin.

        :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: BceResponse
        rS   Nr   r8   r@   r:   r   r   r   delete_recycle_eip  s   zEipClient.delete_recycle_eipc           	      C   sP   ||d}t |  |}|du r|  }d|d}| jtj||t||dS )a  
        Change EIP billing method from postpaid to prepaid.

        :type eip: string
        :param eip: eip address to change billing method

        :type purchase_length: int
        :param purchase_length: purchase duration in months (1-9, 12, 24, 36)

        :type bandwidth: int
        :param bandwidth: bandwidth for prepaid EIP

        :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: BceResponse
        )ZpurchaseLengthZ	bandWidthNs	   TO_PREPAY)s   actionr   r-   r.   )	r   r1   Zpurchase_length	bandwidthr)   r   r   r*   r   r   r   r   change_eip_to_prepay  s   
zEipClient.change_eip_to_prepayc                 C   rW   )a  
        Refund a prepaid EIP.

        :type eip: string
        :param eip: eip address to refund

        :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: BceResponse
        ZrefundNr   r8   r9   r:   r   r   r   refund_prepay_eip  s   zEipClient.refund_prepay_eipc                 C   sN   d|i}t |  |d}|du r|  }d|i}| jtj||t||dS )a  
        Update EIP delete protection setting.

        :type eip: string
        :param eip: eip address to update

        :type delete_protect: bool
        :param delete_protect: enable or disable delete protection

        :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: BceResponse
        r   Nr   r-   r.   )r   r1   r(   r)   r   r   r*   r   r   r   r   update_eip_delete_protect  s   
z#EipClient.update_eip_delete_protectc           	      C   sR   |||d}t | tj}|du r|  }d|i}| jtj|t	
|||dS )a  
        Create an EIP resource transfer task to transfer resources from one account to another.

        :type transfer_type: string
        :param transfer_type: Transfer resource type, should be 'eip'

        :type transfer_resource_list: list
        :param transfer_resource_list: List of resource short IDs to transfer, max 30 items

        :type to_user_id: string
        :param to_user_id: Target account ID

        :type client_token: string
        :param client_token: Idempotent token. If not specified, a random string will be generated.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: BceResponse
        )ZtransferTypeZtransferResourceListZtoUserIdNr   r   )r   r/   r   r	   transfer_prefixr    r!   r   r"   r#   r$   )	r   Ztransfer_typeZtransfer_resource_listZ
to_user_idr)   r   r   r*   r   r   r   r   create_eip_transfer  s   
zEipClient.create_eip_transferc                 C   P   d|i}t | tj}|du r|  }d|d}| jtj|t	
|||dS )a  
        Cancel EIP resource transfer tasks.

        :type transfer_id_list: list
        :param transfer_id_list: List of transfer task IDs to cancel, max 30 items

        :type client_token: string
        :param client_token: Idempotent token. If not specified, a random string will be generated.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: BceResponse
        transferIdListNr,   )s   cancelr   r   r   r/   r   r	   r]   r    r!   r   r0   r#   r$   r   Ztransfer_id_listr)   r   r   r*   r   r   r   r   cancel_eip_transfer7     
zEipClient.cancel_eip_transferc                 C   r_   )a  
        Reject EIP resource transfer tasks.

        :type transfer_id_list: list
        :param transfer_id_list: List of transfer task IDs to reject, max 30 items

        :type client_token: string
        :param client_token: Idempotent token. If not specified, a random string will be generated.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: BceResponse
        r`   Nr,   )s   rejectr   r   ra   rb   r   r   r   reject_eip_transferX  rd   zEipClient.reject_eip_transferc                 C   r_   )a  
        Accept EIP resource transfer tasks.

        :type transfer_id_list: list
        :param transfer_id_list: List of transfer task IDs to accept, max 30 items

        :type client_token: string
        :param client_token: Idempotent token. If not specified, a random string will be generated.

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: BceResponse
        r`   Nr,   )s   acceptr   r   ra   rb   r   r   r   accept_eip_transfery  rd   zEipClient.accept_eip_transferc                 C   s   t | tj}i }|dur||d< |dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d< |durK||d	< |	durS|	|d
< | jtj|||
dS )a  
        List EIP resource transfer tasks.

        :type max_keys: int
        :param max_keys: Maximum number of items per page, default 10

        :type marker: string
        :param marker: Pagination marker

        :type direction: string
        :param direction: 'sent' for initiated by me, 'received' for received by me

        :type transfer_type: string
        :param transfer_type: Transfer resource type

        :type transfer_id: string
        :param transfer_id: Transfer ID for exact query, multiple IDs separated by '_'

        :type status: string
        :param status: Status filter, default 'all'

        :type fuzzy_transfer_id: string
        :param fuzzy_transfer_id: Transfer ID fuzzy query

        :type fuzzy_instance_id: string
        :param fuzzy_instance_id: Instance ID fuzzy query

        :type fuzzy_instance_name: string
        :param fuzzy_instance_name: Instance name fuzzy query

        :type fuzzy_instance_ip: string
        :param fuzzy_instance_ip: Instance IP fuzzy query

        :type config: baidubce.BceClientConfiguration
        :param config:

        :return: list of transfer tasks, for example:
                {
                    "transferList": [...],
                    "marker": "tf-1l4m5etb",
                    "isTruncated": false,
                    "nextMarker": "...",
                    "maxKeys": 10
                }
        NrK   rJ   s	   directions
   transferIdrI   s   fuzzyTransferIds   fuzzyInstanceIds   fuzzyInstanceNames   fuzzyInstanceIpr8   )r   r/   r   r	   r]   r!   r   rN   )r   rQ   rP   	directionZtransfer_idrO   Zfuzzy_transfer_idZfuzzy_instance_idZfuzzy_instance_nameZfuzzy_instance_ipr   r*   r   r   r   r   list_eip_transfer  s0   2
zEipClient.list_eip_transferc                   C   s   t  S )z/
        default client token by uuid1
        )uuiduuid1r   r   r   r   r      s   z(EipClient._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)rk   r   r   r   r     s   zEipClient._get_pathc                 C   s(   |du r| j S t| j }|| |S )zh

        :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EipClient._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)rn   r   Z
parse_jsonr   send_requestr   signZparse_error)r   Zhttp_methodr*   r   headersr   r   Zbody_parserr   r   r   r!     s   

zEipClient._send_request)N)NNNNNNNNNNN)NN)NNN)NNNN)
NNNNNNrF   NNN)NNNrF   N)FNN)
NNNNNNNNNN)NNNNN)$__name__
__module____qualname____doc__rl   rk   r]   r
   r+   r2   r4   r6   r;   r>   r?   rB   rC   rE   rR   rT   rU   rV   rX   rZ   r[   r\   r^   rc   re   rf   rh   staticmethodr    r   rn   r!   r   r   r   r   r	   %   sv    

[
!
1

*

*




a
B



%
!

)
!
!!
L
	r	   )ru   rm   r#   loggingri   Zbaidubcer   Zbaidubce.authr   Zbaidubce.bce_base_clientr   Zbaidubce.httpr   r   r   Zbaidubce.services.eip.modelr   	getLoggerrr   _loggerr	   r   r   r   r   <module>   s   
