o
    e"                     @   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 )z.
This module provides a client class for VPC.
    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d
dddZee	e
fe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 )	VpcClientz
    VPC base sdk client
    s   /v1Nc                 C   s   t j| | d S N)r   BceBaseClient__init__)selfconfig r   PD:\Projects\ConvertPro\env\Lib\site-packages\baidubce/services/vpc/vpc_client.pyr   )   s   zVpcClient.__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VpcClient._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_request9   s   

zVpcClient._send_requestnamecidrc           	      C   sl   d}i }|du rt  |d< n||d< t|t|d}|dur(t||d< | jtj|t|||dS )a  
        The name of vpc to be created.

        :param name:
            The name of vpc to be created.
        :type name: string

        :param cidr:
            The CIDR of the vpc.
        :type cidr: string

        :param description:
            The description of the vpc.
        :type description: 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
           /vpcN   clientTokenr   description)r   r   r   )generate_client_tokenr   convert_to_stringr   r   POSTjsondumps)	r   r   r   r    client_tokenr   r   r   r   r   r   r   
create_vpcE   s   zVpcClient.create_vpc)markermax_KeysZ
is_Defaultc                 C   sL   d}i }|dur||d< |dur||d< |dur||d< | j tj|||dS )a  
        Return a list of vpcs 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 isDefault:
            The option param demotes whether the vpc is default vpc.
        :type isDefault: boolean

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
        r   Ns   markers   maxKeyss	   isDefaultr   r   )r   r   GET)r   r(   r)   Z	isDefaultr   r   r   r   r   r   	list_vpcss   s   zVpcClient.list_vpcs)vpc_idc                 C   s    dt | }| jtj||dS )a  
        Get the detail information of specified vpc.

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

        :param config:
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype baidubce.bce_response.BceResponse
           /vpc/%s)r   )r   convert_to_bytesr   r   r+   )r   r-   r   r   r   r   r   get_vpc   s   zVpcClient.get_vpcc                 C   sB   dt | }i }|du rt |d< n||d< | jtj|||dS )a  
        Delete the specified vpc owned by the user.All resource in the vpc must be deleted before the vpc itself
        can be deleted.

        :param vpc_id:
            The id of instance.
        :type vpc_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
        r.   Nr   r*   )r   r/   r!   r   r   DELETE)r   r-   r&   r   r   r   r   r   r   
delete_vpc   s   zVpcClient.delete_vpc)r-   r   c           	      C   sr   dt | }ddi}dt |i}|du rt |d< n||d< |dur+t ||d< | jtj|t|||dS )aD  
        Modify the special attribute to new value of the vpc owned by the user.

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

        :param name:
            The name of the specified vpc
        :type name: string

        :param description:
           The description of the vpc.
        :type description: 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
        r.   s   modifyAttributeNr   r   r    r*   )	r   r/   r"   r!   r   r   PUTr$   r%   )	r   r-   r   r    r&   r   r   r   r   r   r   r   
update_vpc   s   
zVpcClient.update_vpcr
   )NNNNN)NNN)NNNN)NN)__name__
__module____qualname____doc__r   r   r   r   r   bytesstrr'   intboolr,   r0   r2   r4   r   r   r   r   r	   "   s$    


-& 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
    )r:   uuiduuid4r   r   r   r   generate_client_token_by_uuid   s   r?   )r8   r   r$   loggingr=   Zbaidubcer   Zbaidubce.authr   Zbaidubce.httpr   r   r   Zbaidubce.utilsr   r   	getLoggerr5   Z_loggerr   r	   r?   r!   r   r   r   r   <module>   s"   
 _