o
    #jf=                     @   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 )z1
This module provides a client class for SUBNET.
    N)bce_base_client)bce_v1_signer)bce_http_client)handler)http_methods)required)compatc                   @   sJ  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	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e	e
fee	e
fd		d&ddZee	e
fe	e
fedd%ddZee	e
fdd$dd ZdS )'SubnetClientz 
    Subnet base sdk client
    s   /v1Nc                 C   s   t j| | d S N)r   BceBaseClient__init__)selfconfig r   g/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/baidubce/services/subnet/subnet_client.pyr   (   s   zSubnetClient.__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SubnetClient._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SubnetClient._send_request)name	zone_namecidrvpc_idc                 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rC||d< |durK||d< |	durVt|	|d	< | jtj|t|||
d
S )a  
        Create a subnet with the specified options.

        :param name:
            The name of subnet that will be created.
        type name: string

        :param zone_name:
            The name of available zone which the subnet belong
            through listZones, we can get all available zone info at current region
            ee.g. "cn-gz-a"  "cn-gz-b"
        type zone_name: string

        :param cidr:
            The CIDR of this subnet.
        type cidr: string

        :param vpc_id:
            The id of vpc which this subnet belongs.
        type vpc_id: string

        :param subnet_type:
            The option param to describe the type of subnet create
        type subnet_type: string

        :param description:
            The option param to describe the subnet
        type description: string

        :param enable_ipv6:
            The option param to enable or disable ipv6 for the subnet
        :type enable_ipv6: boolean

        :param vpc_secondary_cidr:
            The secondary CIDR block of the VPC that the subnet belongs to.
        :type vpc_secondary_cidr: string

        :param client_token:
            An ASCII string whose length is less than 64.
            The request will be idempotent if clientToken is provided.
            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

        :param tags:
            List of tags to be bind
        :type tags: list

        :return:
        :rtype baidubce.bce_response.BceResponse
           /subnetN   clientToken)r   ZzoneNamer   ZvpcIdZ
subnetTypedescriptiontags
enableIpv6ZvpcSecondaryCidrr   r   r   generate_client_tokenr   convert_to_stringr   r   POSTjsondumps)r   r   r   r   r   subnet_typer!   client_tokenenable_ipv6Zvpc_secondary_cidrr   r"   r   r   r   r   r   r   create_subnetD   s.   <zSubnetClient.create_subnet)markerZmax_Keysr   r   r+   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< | j tj||	|d	S )
a  
        Return a list of subnets owned by the authenticated user.

        :param marker:
            The optional parameter marker specified in the original request to specify
            where in the results to begin listing.
            Together with the marker, specifies the list result which listing should begin.
            If the marker is not specified, the list result will listing from the first one.
        :type marker: string

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

        :param vpc_id:
            The id of the vpc
        :type vpc_id: string

        :param subnet_ids:
            The ids of the subnet

        :param zone_name:
            The name of available zone which the subnet belong
            through listZones, we can get all available zone info at current region
            ee.g. "cn-gz-a"  "cn-gz-b"
        :type zone_name: string

        :param subnet_type:
            The option param to describe the type of subnet to be created
        :type subnet_type: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   N   marker   maxKeyss   vpcIds	   subnetIdss   zoneNames
   subnetTyper   r   r   r   GET)
r   r/   max_keysr   Z
subnet_idsr   r+   r   r   r   r   r   r   list_subnets   s   -zSubnetClient.list_subnets)	subnet_idc                 C   s    dt | }| jtj||dS )a1  
        Get the detail information of a specified subnet.

        :param subnet_id:
            The id of the subnet.
        :type subnet_id: string

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        
   /subnet/%s)r   )r   convert_to_bytesr   r   r4   )r   r7   r   r   r   r   r   
get_subnet   s   zSubnetClient.get_subnetc                 C   B   dt | }i }|du rt |d< n||d< | jtj|||dS )a  
        Delete the specified subnet owned by the user.
        :param subnet_id:
            The id of the subnet to be deleted.
        :type subnet_id: string

        :param client_token:
            An ASCII string whose length is less than 64.
            The request will be idempotent if clientToken is provided.
            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
        r8   Nr    r2   r   r9   r&   r   r   DELETE)r   r7   r,   r   r   r   r   r   r   delete_subnet   s   zSubnetClient.delete_subnet)r7   r   r!   c           
      C   s   dt | }ddi}dt |i}	|du rt |d< n||d< |dur+t ||	d< |dur3||	d< | jtj|t|	||dS )	a  
        Modify the special attribute to new value of the subnet owned by the user.

        :param subnet_id:
            The id of the specific subnet to be updated.
        :type subnet_id: string

        :param name:
            The name of the subnet
        :type name: string

        :param description:
            The option param to describe the subnet
        :type description: string

        :param enable_ipv6: 
            The option param to enable or disable ipv6 for the subnet
        :type enable_ipv6: boolean

        :param client_token:
            An ASCII string whose length is less than 64.
            The request will be idempotent if clientToken is provided.
            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
        r8   s   modifyAttributeNr   r    r!   r#   r2   )	r   r9   r'   r&   r   r   PUTr)   r*   )
r   r7   r   r!   r-   r,   r   r   r   r   r   r   r   update_subnet  s   "
zSubnetClient.update_subnet)r7   ip_cidr
ip_versionr!   c           
      C   sh   d}|du rdt  ind|i}t|t||d}	|dur&t||	d< | jtj|t|	||dS )a  
        Create a ipreserve segment with the specified options.

        :param subnet_id:
            The id of the subnet that the reserved subnet belongs to.
        :type subnet_id: string

        :param ip_cidr:
            The IP or CIDR of the reserved subnet.
        :type ip_cidr: string

        :param ip_version:
            The IP version, supports IPv4 and IPv6.
        :type ip_version: int

        :param description:
            The description of the reserved subnet.
        :type description: string

        :param client_token:
            An ASCII string whose length is less than 64.
            The request will be idempotent if the clientToken is provided.
            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
           /subnet/ipreserveNZclientToken)ZsubnetIdZipCidrZ	ipVersionr!   r$   r%   )
r   r7   rA   rB   r!   r,   r   r   r   r   r   r   r   create_subnet_ipreserveH  s   &z$SubnetClient.create_subnet_ipreserve)r7   r/   r5   c                 C   sL   d}i }|dur||d< |dur||d< |dur||d< | j tj|||dS )aj  
        List reserved within subnets.

        :param subnet_id:
            The id of the subnet.
        :type subnet_id: string

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

        :param max_keys:
            The optional parameter to specify the max number of list results to return.
        :type max_keys: int

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        rC   Ns   subnetIdr0   r1   r2   r3   )r   r7   r/   r5   r   r   r   r   r   r   list_subnet_ipreserve}  s   z"SubnetClient.list_subnet_ipreserve)ip_reserve_idc                 C   r;   )a  
        Delete the specified reserved subnet segment.

        :param ip_reserve_id:
            The ID of the reserved subnet to be deleted.
        :type ip_reserve_id: string

        :param client_token:
            An ASCII string whose length is less than 64.
            The request will be idempotent if clientToken is provided.
            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
        s   /subnet/ipreserve/%sNr    r2   r<   )r   rF   r,   r   r   r   r   r   r   delete_subnet_ipreserve  s   z$SubnetClient.delete_subnet_ipreserver
   )NNNNN)NNNNNNN)NN)NNNN)NNN)__name__
__module____qualname____doc__r   r   r   r   r   bytesstrr.   intr6   r:   r>   r@   rD   rE   rG   r   r   r   r   r	   "   s\    


X971"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
    )rM   uuiduuid4r   r   r   r   generate_client_token_by_uuid  s   rQ   )rK   r   r)   loggingrO   Zbaidubcer   Zbaidubce.authr   Zbaidubce.httpr   r   r   Zbaidubce.utilsr   r   	getLoggerrH   _loggerr   r	   rQ   r&   r   r   r   r   <module>   s&   
   $