wip: add spot pod creation

- Add support for creating spot pods using the RunPod API.
- Implement `create_spot_pod` function in the `RunPod` client.
- Refactor RunPod client to handle different query types and response structures.
- Improve error handling and logging for GraphQL requests.
- Update example to demonstrate spot pod creation.

Co-authored-by: mahmmoud.hassanein <mahmmoud.hassanein@gmail.com>
This commit is contained in:
2025-01-20 21:34:16 +02:00
parent d54a1e5a34
commit 4422d67701
4 changed files with 180 additions and 138 deletions

View File

@@ -10,12 +10,40 @@ mut rp := runpod.get_or_create(
)!
// Create a new pod
pod_response := rp.create_pod(
name: 'RunPod Tensorflow'
image_name: 'runpod/tensorflow'
env: [
{"JUPYTER_PASSWORD": "rn51hunbpgtltcpac3ol"}
// pod_response := rp.create_on_demand_pod(
// name: 'RunPod Tensorflow'
// image_name: 'runpod/tensorflow'
// env: [
// runpod.EnvironmentVariableInput{
// key: 'JUPYTER_PASSWORD'
// value: 'rn51hunbpgtltcpac3ol'
// },
// ]
// )!
// println('Created pod with ID: ${pod_response.id}')
// create spot pod
// "mutation { podRentInterruptable( input: { bidPerGpu: 0.2, cloudType: SECURE, gpuCount: 1, volumeInGb: 40, containerDiskInGb: 40, minVcpuCount: 2, minMemoryInGb: 15, gpuTypeId: \"NVIDIA RTX A6000\", name: \"RunPod Pytorch\", imageName: \"runpod/pytorch\", dockerArgs: \"\", ports: \"8888/http\", volumeMountPath: \"/workspace\", env: [{ key: \"JUPYTER_PASSWORD\", value: \"vunw9ybnzqwpia2795p2\" }] } ) { id imageName env machineId machine { podHostId } } }"
spot_pod_resp := rp.create_spot_pod(
port: 1826
bid_per_gpu: 0.2
cloud_type: .secure
gpu_count: 1
volume_in_gb: 40
container_disk_in_gb: 40
min_vcpu_count: 2
min_memory_in_gb: 15
gpu_type_id: 'NVIDIA RTX A6000'
name: 'RunPod Pytorch'
image_name: 'runpod/pytorch'
docker_args: ''
ports: '8888/http'
volume_mount_path: '/workspace'
env: [
runpod.EnvironmentVariableInput{
key: 'JUPYTER_PASSWORD'
value: 'rn51hunbpgtltcpac3ol'
},
]
)!
println('Created pod with ID: ${pod_response.id}')
println('Created spot pod with ID: ${spot_pod_resp.id}')