§
    AxÅj/9  ã            -       óf  — d 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 ddlmZ dd
lmZ ddlm
Z dd	lmZ dPdee         defd„ZdPdedee         defd„ZdPdee         defd„ZdQdededee         fd„ZdPdee         defd„ZdPdedee         fd„Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dRdedee         dee         ded ed!ed"ee         d#ee         d$ed%ed&ee         d'ed(ed)ed*ee         d+ed,ee         d-ee         d.ee         d/ee         d0ee         def,d1„Z defd2„Z!ded$efd3„Z"defd4„Z#	 	 	 	 	 	 	 	 dSdeded7ed&ed%ed+ed*ed,ed8ed9efd:„Z$defd;„Z%	 	 	 	 	 	 	 	 	 	 	 dTded-edAed.edBedCedDedEedFedGed/ed$efdH„Z&dIed-efdJ„Z'dedKedLefdM„Z(d9edKedLefdN„Z)d9efdO„Z*dS )Uz%
Runpod | API Wrapper | CTL Commands
é    )ÚOptionalé   )Úrun_graphql_query)Úcontainer_register_auth)Ú	endpoints)Úpods)Ú	templates)Úuser)ÚgpusNÚapi_keyÚreturnc                 óX   — t          t          j        | ¬¦  «        }|d         d         }|S )z†
    Get the current user with optional API key override.
    
    Args:
        api_key: Optional API key to use for this query.
    ©r   ÚdataÚmyself)r   Úuser_queriesÚ
QUERY_USER©r   Úraw_responseÚcleaned_returns      úHC:\Projects\Historical\venv\Lib\site-packages\runpod/api/ctl_commands.pyÚget_userr      s.   € õ %¥\Ô%<ÀgÐNÑNÔN€LØ! &Ô)¨(Ô3€NØÐó    Úpubkeyc                 óh   — t          t          j        | ¦  «        |¬¦  «        }|d         d         }|S )z�
    Update the current user

    Args:
        pubkey: the public key of the user
        api_key: Optional API key to use for this query.
    r   r   ÚupdateUserSettings)r   Úuser_mutationsÚgenerate_user_mutation)r   r   r   r   s       r   Úupdate_user_settingsr   !   sA   € õ %ÝÔ-¨fÑ5Ô5Øðñ ô €Lð " &Ô)Ð*>Ô?€NØÐr   c                 óX   — t          t          j        | ¬¦  «        }|d         d         }|S )zc
    Get all GPU types
    
    Args:
        api_key: Optional API key to use for this query.
    r   r   ÚgpuTypes)r   r   ÚQUERY_GPU_TYPESr   s      r   Úget_gpusr#   1   s.   € õ %¥TÔ%9À7ÐKÑKÔK€LØ! &Ô)¨*Ô5€NØÐr   Úgpu_idÚgpu_quantityc                 óº   — t          t          j        | |¦  «        |¬¦  «        }|d         d         }t          |¦  «        dk     rt	          d¦  «        ‚|d         S )zÄ
    Get a specific GPU type

    Args:
        gpu_id: the id of the gpu
        gpu_quantity: how many of the gpu should be returned
        api_key: Optional API key to use for this query.
    r   r   r!   r   zSNo GPU found with the specified ID, run runpod.get_gpus() to get a list of all GPUsr   )r   r   Úgenerate_gpu_queryÚlenÚ
ValueError)r$   r%   r   r   r   s        r   Úget_gpur*   =   ss   € õ %ÝÔ ¨Ñ5Ô5Øðñ ô €Lð
 " &Ô)¨*Ô5€Nå
ˆ>ÑÔ˜QÒÐÝð>ñ
ô 
ð 	
ð
 ˜!ÔÐr   c                 ód   — t          t          j        | ¬¦  «        }|d         d         d         }|S )z^
    Get all pods
    
    Args:
        api_key: Optional API key to use for this query.
    r   r   r   r   )r   Úpod_queriesÚ	QUERY_POD)r   Ú
raw_returnr   s      r   Úget_podsr/   V   s3   € õ #¥;Ô#8À'ÐJÑJÔJ€JØ Ô'¨Ô1°&Ô9€NØÐr   Úpod_idc                 ód   — t          t          j        | ¦  «        |¬¦  «        }|d         d         S )z‚
    Get a specific pod

    Args:
        pod_id: the id of the pod
        api_key: Optional API key to use for this query.
    r   r   Úpod)r   r,   Úgenerate_pod_query)r0   r   r   s      r   Úget_podr4   b   s;   € õ %ÝÔ& vÑ.Ô.Øðñ ô €Lð ˜Ô Ô&Ð&r   Ú ÚALLTú/runpod-volumeÚnameÚ
image_nameÚgpu_type_idÚ
cloud_typeÚsupport_public_ipÚ	start_sshÚdata_center_idÚcountry_codeÚ	gpu_countÚvolume_in_gbÚcontainer_disk_in_gbÚmin_vcpu_countÚmin_memory_in_gbÚdocker_argsÚportsÚvolume_mount_pathÚenvÚtemplate_idÚnetwork_volume_idÚallowed_cuda_versionsÚinstance_idc                 óš  — |s|st          d¦  «        ‚|�t          |¦  «         |dvrt          d¦  «        ‚|r1|€/t          ¦   «         }|d         D ]}|d         |k    r
|d         } nŒ|
€|€d}
t          t	          j        | ||||||||�|nd|	|
||||||||||||¦  «        ¦  «        }|�|d	         d
         }n|d	         d         }|S )a/  
    Create a pod

    :param name: the name of the pod
    :param image_name: the name of the docker image to be used by the pod
    :param gpu_type_id: the gpu type wanted by the pod (retrievable by get_gpus). If None, creates a CPU-only pod
    :param cloud_type: if secure cloud, community cloud or all is wanted
    :param data_center_id: the id of the data center
    :param country_code: the code for country to start the pod in
    :param gpu_count: how many gpus should be attached to the pod (ignored for CPU-only pods)
    :param volume_in_gb: how big should the pod volume be
    :param ports: the ports to open in the pod, example format - "8888/http,666/tcp"
    :param volume_mount_path: where to mount the volume?
    :param env: the environment variables to inject into the pod,
                for example {EXAMPLE_VAR:"example_value", EXAMPLE_VAR2:"example_value 2"}, will
                inject EXAMPLE_VAR and EXAMPLE_VAR2 into the pod with the mentioned values
    :param template_id: the id of the template to use for the pod
    :param min_download: minimum download speed in Mbps
    :param min_upload: minimum upload speed in Mbps
    :param instance_id: the id of a specific instance to deploy to (for CPU pods)
    :example:

    >>> # Create GPU pod
    >>> pod_id = runpod.create_pod("test", "runpod/stack", "NVIDIA GeForce RTX 3070")
    >>> # Create CPU pod
    >>> pod_id = runpod.create_pod("test", "runpod/stack")
    >>> # Create CPU pod on specific instance
    >>> pod_id = runpod.create_pod("test", "runpod/stack", instance_id="cpu3c-2-4")
    z1Either image_name or template_id must be providedN)r6   Ú	COMMUNITYÚSECUREz2cloud_type must be one of ALL, COMMUNITY or SECUREÚnetworkVolumesÚidÚdataCenterIdé
   r   ÚpodFindAndDeployOnDemandÚdeployCpuPod)r)   r*   r   r   Úpod_mutationsÚ generate_pod_deployment_mutation)r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   Úmin_downloadÚ
min_uploadrL   Ú	user_infoÚnetwork_volumer   Úcleaned_responses                              r   Ú
create_podr]   q   sV  € ðp ð N˜kð NÝÐLÑMÔMÐMàÐÝ�ÑÔÐØÐ7Ð7Ð7ÝÐMÑNÔNÐNàð ˜^Ð3Ý‘J”Jˆ	Ø'Ð(8Ô9ð 	ð 	ˆNØ˜dÔ#Ð'8Ò8Ð8Ø!/°Ô!?�Ø�ð 9ð Ð#¨Ð(;Ø!Ðå$ÝÔ6ØØØØØØØØØ$Ð0ˆIˆI°dØØ ØØØØØØØØØ!ØØØñ/	
ô 	
ñô €Lð8 ÐØ'¨Ô/Ð0JÔKÐÐà'¨Ô/°Ô?ÐØÐr   c                 ód   — t          t          j        | ¦  «        ¦  «        }|d         d         }|S )zÀ
    Stop a pod

    :param pod_id: the id of the pod

    :example:

    >>> pod_id = runpod.create_pod("test", "runpod/stack", "NVIDIA GeForce RTX 3070")
    >>> runpod.stop_pod(pod_id)
    r   ÚpodStop)r   rV   Úgenerate_pod_stop_mutation)r0   r   r\   s      r   Ústop_podra   Þ   s2   € õ %¥]Ô%MÈfÑ%UÔ%UÑVÔV€Là# FÔ+¨IÔ6ÐØÐr   c                 óf   — t          t          j        | |¦  «        ¦  «        }|d         d         }|S )a"  
    Resume a pod

    :param pod_id: the id of the pod
    :param gpu_count: the number of GPUs to attach to the pod

    :example:

    >>> pod_id = runpod.create_pod("test", "runpod/stack", "NVIDIA GeForce RTX 3070")
    >>> runpod.stop_pod(pod_id)
    >>> runpod.resume_pod(pod_id)
    r   Ú	podResume)r   rV   Úgenerate_pod_resume_mutation)r0   r@   r   r\   s       r   Ú
resume_podre   ï   s;   € õ %ÝÔ2°6¸9ÑEÔEñô €Lð $ FÔ+¨KÔ8ÐØÐr   c                 óH   — t          t          j        | ¦  «        ¦  «         dS )zÊ
    Terminate a pod

    :param pod_id: the id of the pod

    :example:

    >>> pod_id = runpod.create_pod("test", "runpod/stack", "NVIDIA GeForce RTX 3070")
    >>> runpod.terminate_pod(pod_id)
    N)r   rV   Úgenerate_pod_terminate_mutation)r0   s    r   Úterminate_podrh     s#   € õ •mÔCÀFÑKÔKÑLÔLÐLÐLÐLr   rS   FÚdocker_start_cmdÚis_serverlessÚregistry_auth_idc
                 ót   — t          t          j        | |||||||||	¬¦
  «
        ¦  «        }
|
d         d         S )a¿  
    Create a template

    :param name: the name of the template
    :param image_name: the name of the docker image to be used by the template
    :param docker_start_cmd: the command to start the docker container with
    :param container_disk_in_gb: how big should the container disk be
    :param volume_in_gb: how big should the volume be
    :param ports: the ports to open in the pod, example format - "8888/http,666/tcp"
    :param volume_mount_path: where to mount the volume?
    :param env: the environment variables to inject into the pod,
                for example {EXAMPLE_VAR:"example_value", EXAMPLE_VAR2:"example_value 2"}, will
                inject EXAMPLE_VAR and EXAMPLE_VAR2 into the pod with the mentioned values
    :param is_serverless: is the template serverless?
    :param registry_auth_id: the id of the registry auth

    :example:

    >>> template_id = runpod.create_template("test", "runpod/stack", "python3 main.py")
    )
r8   r9   ri   rB   rA   rG   rF   rH   rj   rk   r   ÚsaveTemplate)r   Útemplate_mutationsÚgenerate_pod_template)r8   r9   ri   rB   rA   rG   rF   rH   rj   rk   r   s              r   Úcreate_templaterp     sY   € õ@ %ÝÔ0ØØ!Ø-Ø!5Ø%Ø/ØØØ'Ø-ð	
ñ 	
ô 	
ñô €Lð ˜Ô Ô/Ð/r   c                  ó`   — t          t          j        ¦  «        } | d         d         d         }|S )z
    Get all endpoints
    r   r   r   )r   Úendpoint_queriesÚQUERY_ENDPOINT)r.   r   s     r   Úget_endpointsrt   D  s/   € õ #Õ#3Ô#BÑCÔC€JØ Ô'¨Ô1°+Ô>€NØÐr   Ú	AMPERE_16é   ÚQUEUE_DELAYé   é   Úgpu_idsÚ	locationsÚidle_timeoutÚscaler_typeÚscaler_valueÚworkers_minÚworkers_maxc                 óx   — t          t          j        | |||||||||	|
||¦  «        ¦  «        }|d         d         S )a™  
    Create an endpoint

    :param name: the name of the endpoint
    :param template_id: the id of the template to use for the endpoint
    :param gpu_ids: the ids of the GPUs to use for the endpoint
    :param network_volume_id: the id of the network volume to use for the endpoint
    :param locations: the locations to use for the endpoint
    :param idle_timeout: the idle timeout for the endpoint
    :param scaler_type: the scaler type for the endpoint
    :param scaler_value: the scaler value for the endpoint
    :param workers_min: the minimum number of workers for the endpoint
    :param workers_max: the maximum number of workers for the endpoint
    :param allowed_cuda_versions: Comma-separated list of allowed CUDA versions (e.g., ["12.4", "12.5"]).
    :param gpu_count: the number of GPUs to use for the endpoint

    :example:

    >>> endpoint_id = runpod.create_endpoint("test", "template_id")
    r   ÚsaveEndpoint)r   Úendpoint_mutationsÚgenerate_endpoint_mutation)r8   rI   rz   rJ   r{   r|   r}   r~   r   r€   Ú	flashbootrK   r@   r   s                 r   Úcreate_endpointr†   M  s]   € õF %ÝÔ5ØØØØØØØØØØØØ!Øñ	
ô 	
ñô €Lð$ ˜Ô Ô/Ð/r   Úendpoint_idc                 ób   — t          t          j        | |¦  «        ¦  «        }|d         d         S )zù
    Update an endpoint template

    :param endpoint_id: the id of the endpoint
    :param template_id: the id of the template to use for the endpoint

    :example:

    >>> endpoint_id = runpod.update_endpoint_template("test", "template_id")
    r   ÚupdateEndpointTemplate)r   rƒ   Ú!update_endpoint_template_mutation)r‡   rI   r   s      r   Úupdate_endpoint_templater‹   …  s6   € õ %ÝÔ<¸[È+ÑVÔVñô €Lð ˜ÔÐ 8Ô9Ð9r   ÚusernameÚpasswordc                 ód   — t          t          j        | ||¦  «        ¦  «        }|d         d         S )aP  
    Create a container registry authentication.

    Args:
        name (str): The name of the container registry.
        username (str): The username for authentication.
        password (str): The password for authentication.

    Returns:
        dict: The response data containing the saved container registry authentication.
    r   ÚsaveRegistryAuth)r   Ú!container_register_auth_mutationsÚ generate_container_registry_auth)r8   rŒ   r�   r   s       r   Úcreate_container_registry_authr’   —  s=   € õ %Ý)ÔJØ�(˜Hñ	
ô 	
ñô €Lð
 ˜ÔÐ 2Ô3Ð3r   c                 ód   — t          t          j        | ||¦  «        ¦  «        }|d         d         S )aj  
    Update a container registry authentication.

    Args:
        registry_auth_id (str): The id of the container registry authentication
        username (str): The username for authentication.
        password (str): The password for authentication.

    Returns:
        dict: The response data containing the updated container registry authentication.
    r   ÚupdateRegistryAuth)r   r�   Úupdate_container_registry_auth)rk   rŒ   r�   r   s       r   r•   r•   «  s=   € õ %Ý)ÔHØ˜h¨ñ	
ô 	
ñô €Lð
 ˜ÔÐ 4Ô5Ð5r   c                 ó`   — t          t          j        | ¦  «        ¦  «        }|d         d         S )z�
    Delete a container registry authentication.

    Args:
        registry_auth_id (str): The id of the container registry authentication
    r   ÚdeleteRegistryAuth)r   r�   Údelete_container_registry_auth)rk   r   s     r   r˜   r˜   ¿  s9   € õ %Ý)ÔHØñ	
ô 	
ñô €Lð
 ˜ÔÐ 4Ô5Ð5r   )N)r   N)r5   Nr6   TTNNr   r   Nr   r   r5   Nr7   NNNNNNN)NrS   NNNNFN)ru   NNrv   rw   rx   r   ry   FNr   )+Ú__doc__Útypingr   Úgraphqlr   Ú	mutationsr   r�   r   rƒ   r   rV   r	   rn   r
   r   Úqueriesrr   r   r,   r   ÚstrÚdictr   r   r#   Úintr*   r/   r4   ÚboolÚlistr]   ra   re   rh   rp   rt   r†   r‹   r’   r•   r˜   © r   r   ú<module>r¤      s»  ððð ð Ð Ð Ð Ð Ð à &Ð &Ð &Ð &Ð &Ð &Ø SÐ SÐ SÐ SÐ SÐ SØ 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø -Ð -Ð -Ð -Ð -Ð -Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ø )Ð )Ð )Ð )Ð )Ð )ð	ð 	�h˜s”mð 	¨tð 	ð 	ð 	ð 	ðð  ð ¨x¸¬}ð Èð ð ð ð ð 	ð 	�h˜s”mð 	¨tð 	ð 	ð 	ð 	ðð �Cð  sð ¸À#¼ð ð ð ð ð2	ð 	�h˜s”mð 	¨tð 	ð 	ð 	ð 	ð'ð '�Cð ' (¨3¤-ð 'ð 'ð 'ð 'ð" !#Ø!%ØØ"ØØ$(Ø"&ØØØ*.ØØØØØ-ØØ!%Ø'+Ø,0ØØØ!%ð/jð jØ
ðjà˜”ðjð ˜#”ðjð ð	jð
 ðjð ðjð ˜S”Mðjð ˜3”-ðjð ðjð ðjð # 3œ-ðjð ðjð ðjð ðjð �CŒ=ðjð  ð!jð" 
�$Œð#jð$ ˜#”ð%jð&   ”}ð'jð( $ Dœ>ð)jð. ˜#”ð/jð0 
ð1jð jð jð jðZ�Sð ð ð ð ð"�sð  sð ð ð ð ð*M˜#ð Mð Mð Mð Mð" !Ø "ØØ!ØØØØ ð/0ð /0Ø
ð/0àð/0ð ð/0ð ð	/0ð
 ð/0ð ð/0ð ð/0ð 
ð/0ð ð/0ð ð/0ð /0ð /0ð /0ðd�tð ð ð ð ð Ø!ØØØ$ØØØØØ!%Øð50ð 50Ø
ð50àð50ð ð50ð ð	50ð
 ð50ð ð50ð ð50ð ð50ð ð50ð ð50ð ð50ð ð50ð 50ð 50ð 50ðp:¨#ð :¸Cð :ð :ð :ð :ð$4¨ð 4¸ð 4Àsð 4ð 4ð 4ð 4ð(6°Sð 6ÀCð 6ÐSVð 6ð 6ð 6ð 6ð(6°Sð 6ð 6ð 6ð 6ð 6ð 6r   