o
    #j46                     @   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 ROUTE.
    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e	e
fddddZee	e
fe	e
fe	e
fe	e
fe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d				d!ddZdS )"RouteClientz'
        Route base sdk client
        s   /v1Nc                 C   s   t j| | d S N)r   BceBaseClient__init__)selfconfig r   e/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/baidubce/services/route/route_client.pyr   (   s   zRouteClient.__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RouteClient._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RouteClient._send_request)route_table_idsource_addressdestination_addressdescription c                 C   s   d}i }|	du rt  |d< n|	|d< t|t|t|t|d}|dur0t||d< |dur;t||d< |durFt||d< |durUdd	 |D }||d
< | jtj|t|||
dS )a  
        Create a route with the specified options.

        :param route_table_id:
            The id of the route table.
        :type route_table_id: string

        :param source_address:
            The source address of the route.
        :type source_address: string

        :param destination_address:
            The destination address of the route
        :type destination_address: string

        :param next_hop_type:
            route type
            the Bcc type is "custom";
            the VPN type is "vpn";
            the NAT type is "nat";
            the dedicatedGateway type is "dcGateway"; Multi-line mode does not require
            the PeerConn type is "peerConn";
            the ENIC type is "enic";
            the HaVip type is "havip";
            the ipv6Gateway type is "ipv6gateway";
            the local gateway type is "defaultGateway"
        :type next_hop_type: string

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

        :param next_hop_id:
            The next hop id
            when the nexthopType is "defaultGateway",this field can be empty
        :type next_hop_id: string
        :param next_hop_id:
            The next hop id
            when the nexthopType is "defaultGateway",this field can be empty
        :type next_hop_id: string

        :param next_hop_list:
            The optional list of dcGateway Multi-line mode route to create.
                - NextHop.nexthopId next hop dcGateway ID
                - NextHop.nexthopType Route type. Currently only supports dedicatedGateway type: "dcGateway"
                - NextHop.pathType Multiline mode. The value of load balancing is ecmp; the values of active and
                standby modes are ha:active and ha:standby, which represent the active and standby routes respectively
        :type next_hop_list: list<route_model.NextHop>

        :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
           /route/ruleN   clientToken)routeTableIdsourceAddressdestinationAddressr   nexthopType	nexthopId	ipVersionc                 S      g | ]}|j qS r   __dict__.0Znext_hopr   r   r   
<listcomp>       z,RouteClient.create_route.<locals>.<listcomp>nextHopListr   r   r   )generate_client_tokenr   convert_to_stringr   r   POSTjsondumps)r   r   r   r   next_hop_typer   next_hop_id
ip_version	next_hopsclient_tokenr   r   r   r   next_hop_listr   r   r   create_routeD   s,   DzRouteClient.create_route)vpc_idr   c                 C   s<   d}i }|dur||d< |dur||d< | j tj|||dS )a0  
        Get the detail information of route table for specific route table or/and vpc.

        :param vpc_id:
            the vpc id
            vpcId and routeTableId cannot be empty at the same time
        :type vpc_id: string

        :param route_table_id:
            the id of the route table
            vpcId and routeTableId cannot be empty at the same time
        :type route_table_id: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        s   /routeN   routeTableId   vpcIdr   r   r   r   GET)r   r=   r   r   r   r   r   r   r   	get_route   s   zRouteClient.get_route)versionr"   vpcIdmarkermaxKeysc                 C   s\   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< | j tj|||dS )a  
        Get the details of route rules in a specified route table or VPC.

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

        :param routeTableId:
            The ID of the route table. Either `routeTableId` or `vpcId` must be provided.
        :type routeTableId: string

        :param vpcId:
            The ID of the VPC. Either `routeTableId` or `vpcId` must be provided.
        :type vpcId: string

        :param marker:
            The marker for the start position of batch retrieval.
        :type marker: string

        :param maxKeys:
            The maximum number of entries per page (up to 1000).
        :type maxKeys: int

        :param config:
            BceClientConfiguration object.
        :type config: baidubce.BceClientConfiguration

        :return:
            A BceResponse object.
        :rtype: baidubce.bce_response.BceResponse
        r    Nr>   r?   s   markers   maxKeysr@   rA   )r   r"   rE   rF   rG   r   r   r   r   r   r   get_route_rule   s   !zRouteClient.get_route_rule)route_rule_idc                 C   sB   dt | }i }|du rt |d< n||d< | jtj|||dS )a   
        Delete the  specific route rule.

        :param route_rule_id:
            The id of the specified route table.
        :type route_rule_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 route_table_id: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
           /route/rule/%sNr!   r@   )r   convert_to_bytesr1   r   r   DELETEr   rI   r:   r   r   r   r   r   r   delete_route   s   zRouteClient.delete_routec                 C   sF   dt | }ddi}|du rt |d< n||d< | jtj|||dS )a6  
        In a multi-line master-slave routing mode, switching the main route to the backup route.

        :param route_rule_id:
            The id of the specified route table.
        :type route_rule_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
        rJ   s   switchRouteHANr!   r@   )r   rK   r1   r   r   PUTrM   r   r   r   switch_route  s   zRouteClient.switch_route)rI   r   c                 C   s   dt | }i }|	du rt |d< n|	|d< dt |i}|dur)t ||d< |dur4t ||d< |dur?t ||d< |durNdd	 |D }||d
< |durYt ||d< |durdt ||d< | jtj|t|||
dS )a  
        Update a route with the specified options.

        :param route_rule_id:
            The id of the route rule to be updated.
        :type route_rule_id: string

        :param source_address:
            The source address of the route.
        :type source_address: string

        :param destination_address:
            The destination address of the route.
        :type destination_address: string

        :param next_hop_type:
            Route type.
        :type next_hop_type: string

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

        :param next_hop_id:
            The next hop id.
        :type next_hop_id: string

        :param ip_version:
            IP version.
        :type ip_version: string

        :param next_hops:
            The optional list of next hops.
        :type next_hops: list<route_model.NextHop>

        :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
        rJ   Nr!   r   r%   r&   r'   c                 S   r(   r   r)   r+   r   r   r   r-   p  r.   z,RouteClient.update_route.<locals>.<listcomp>r/   r$   r#   r0   )	r   rK   r1   r2   r   r   rO   r4   r5   )r   rI   r   r   r6   r   r7   r8   r9   r:   r   r   r   r   r;   r   r   r   update_route)  s*   4
zRouteClient.update_router
   )NNNNN)Nr   NNNNN)NNN)NN)	NNNr   NNNNN)__name__
__module____qualname____doc__r   r   r   r   r   bytesstrr<   rC   intrH   rN   rP   rQ   r   r   r   r   r	   "   sB    


\ -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
    )rW   uuiduuid4r   r   r   r   generate_client_token_by_uuidz  s   r[   )rU   r   r4   loggingrY   Zbaidubcer   Zbaidubce.authr   Zbaidubce.httpr   r   r   Zbaidubce.utilsr   r   	getLoggerrR   _loggerr   r	   r[   r1   r   r   r   r   <module>   s$   
  Z