API Endpoints Reference

Complete reference for all SNAP API endpoints.

Base URL

http://localhost:8000

Authentication

Most endpoints require authentication. Include the token in the Authorization header:

curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8000/api/endpoint

Checkpoint Endpoints

Create Checkpoint

POST /checkpoint/kubelet/checkpoint

Request Body:

{
  "pod_name": "test-app",
  "namespace": "default",
  "node_name": "worker-node-1",
  "container_name": "test-app",
  "cluster_name": "production-cluster"
}

Response:

{
  "success": true,
  "pod_id": "pod-12345",
  "container_ids": ["container-67890"],
  "checkpoint_path": "/app/checkpoints/test-app-12345.tar",
  "message": "Checkpoint created successfully"
}

Create Checkpoint and Push

POST /checkpoint/kubelet/checkpoint-and-push

Query Parameters:

Request Body:

{
  "namespace": "default",
  "cluster": "production-cluster",
  "registry": "nexus-registry",
  "image_name": "test-app-checkpoint",
  "tag": "latest"
}

List Checkpoints

GET /checkpoint/list

Response:

{
  "checkpoints": [
    {
      "id": "checkpoint-123",
      "pod_name": "test-app",
      "namespace": "default",
      "created_at": "2024-01-15T10:30:00Z",
      "size": "150MB",
      "status": "completed"
    }
  ]
}

Download Checkpoint

GET /checkpoint/download/{pod_name}/{filename}

Checkpoint Insights

POST /checkpoint/insights

Request Body:

{
  "checkpoint_path": "/app/checkpoints/test-app-12345.tar",
  "analysis_type": "volatility"
}

Cluster Endpoints

⚠️ Deprecated Endpoints

The following cluster endpoints have been deprecated and return deprecation messages:

❌ Enable Checkpointing (Deprecated)

POST /cluster/enable_checkpointing

Request Body:

{
  "cluster_name": "production-cluster",
  "node_names": ["worker-node-1", "worker-node-2"]
}

Response (Deprecated):

{
  "success": false,
  "message": "This endpoint is deprecated. Checkpointing is now handled automatically by the DaemonSet."
}

❌ Install runC (Deprecated)

POST /cluster/install_runc

Request Body:

{
  "cluster_name": "production-cluster",
  "runc_version": "1.2.4"
}

Response (Deprecated):

{
  "success": false,
  "message": "This endpoint is deprecated. runc installation is now handled automatically by the DaemonSet."
}

❌ Verify Checkpointing (Deprecated)

POST /cluster/verify_checkpointing

Request Body:

{
  "cluster_name": "production-cluster"
}

Response (Deprecated):

{
  "success": false,
  "message": "This endpoint is deprecated. Cluster verification is now handled automatically by the DaemonSet."
}

✅ Active Endpoints

Get Cluster Statistics

GET /cluster/statistics

Response:

{
  "total_clusters": 3,
  "active_clusters": 2,
  "total_checkpoints": 45,
  "total_nodes": 12
}

Get Cluster Status (from DaemonSet)

GET /cluster/status/{cluster_name}

Response:

{
  "cluster_name": "production-cluster",
  "status": "healthy",
  "nodes": [
    {
      "name": "worker-node-1",
      "status": "ready",
      "checkpointing_enabled": true,
      "runc_version": "1.2.4",
      "last_update": "2024-01-15T10:30:00Z"
    }
  ],
  "daemonset_status": "running",
  "last_update": "2024-01-15T10:30:00Z"
}

Registry Endpoints

Login to Registry

POST /registry/login

Request Body:

{
  "registry_config_name": "nexus-registry"
}

Create and Push Checkpoint Container

POST /registry/create_and_push_checkpoint_container

Request Body:

{
  "checkpoint_name": "test-app-checkpoint",
  "username": "admin",
  "pod_name": "test-app",
  "checkpoint_config_name": "default"
}

Configuration Endpoints

Registry Configuration

Create Registry Config

POST /config/registry/create

Request Body:

{
  "name": "nexus-registry",
  "url": "https://nexus.company.com",
  "username": "admin",
  "password": "password123",
  "verify_ssl": true
}

List Registry Configs

GET /config/registry/list

Update Registry Config

PUT /config/registry/update

Delete Registry Config

DELETE /config/registry/delete

Cluster Configuration

Create Cluster Config

POST /config/clusters/create

Request Body:

{
  "name": "production-cluster",
  "api_server_url": "https://api.cluster.com:6443",
  "auth_type": "kubeconfig",
  "kubeconfig_content": "base64-encoded-kubeconfig",
  "registry_name": "nexus-registry"
}

List Cluster Configs

GET /config/clusters/list

Update Cluster Config

PUT /config/clusters/update

Delete Cluster Config

DELETE /config/clusters/delete

User Configuration

Create User

POST /config/user/create

Request Body:

{
  "username": "admin",
  "password": "securepassword",
  "email": "admin@company.com",
  "role": "administrator"
}

Login User

POST /config/user/login

Request Body:

{
  "username": "admin",
  "password": "securepassword"
}

Response:

{
  "success": true,
  "token": "jwt-token-here",
  "user": {
    "username": "admin",
    "role": "administrator"
  }
}

Automation Endpoints

Trigger Automation

POST /automation/trigger

Request Body:

{
  "pod_name": "test-app",
  "namespace": "default",
  "node_name": "worker-node-1",
  "container_name": "test-app",
  "cluster_name": "production-cluster",
  "registry": "nexus-registry",
  "username": "admin",
  "password": "password123"
}

Operator Endpoints

Start SnapWatcher

POST /operator/start

Request Body:

{
  "cluster_name": "production-cluster",
  "cluster_config": {
    "api_server_url": "https://api.cluster.com:6443",
    "auth_type": "kubeconfig"
  },
  "scope": "cluster",
  "namespace": "snap",
  "auto_delete_pod": true
}

Stop SnapWatcher

POST /operator/stop

Request Body:

{
  "cluster_name": "production-cluster"
}

Get Operator Status

GET /operator/status

Response:

{
  "running": true,
  "active_watchers": [
    {
      "cluster_name": "production-cluster",
      "status": "active",
      "started_at": "2024-01-15T10:00:00Z"
    }
  ]
}

SnapWatcher Management Endpoints

Create SnapWatcher

POST /operator/snapwatcher

Request Body:

{
  "name": "production-watcher",
  "cluster_name": "production-cluster",
  "cluster_config": {
    "api_server_url": "https://api.cluster.com:6443",
    "auth_type": "kubeconfig"
  },
  "scope": "cluster",
  "namespace": "snap",
  "trigger": "startupProbe",
  "auto_delete_pod": true
}

Get SnapWatcher Status

GET /operator/snapwatcher/{watcher_name}/status

Response:

{
  "name": "production-watcher",
  "cluster_name": "production-cluster",
  "cluster_config": {
    "api_server_url": "https://api.cluster.com:6443",
    "auth_type": "kubeconfig"
  },
  "scope": "cluster",
  "namespace": "snap",
  "trigger": "startupProbe",
  "status": "running",
  "auto_delete_pod": true,
  "thread_alive": true,
  "last_update": "2024-01-15T10:30:00Z",
  "created_at": "2024-01-15T10:00:00Z"
}

Start SnapWatcher

POST /operator/snapwatcher/{watcher_name}/start

Stop SnapWatcher

POST /operator/snapwatcher/{watcher_name}/stop

Delete SnapWatcher

DELETE /operator/snapwatcher/{watcher_name}

Get All Watchers Status

GET /operator/watchers/status

Response:

{
  "success": true,
  "active_watchers": 2,
  "watchers": {
    "production-watcher": {
      "running": true,
      "cluster_name": "production-cluster",
      "scope": "cluster",
      "namespace": "snap",
      "thread_alive": true
    }
  }
}

SnapHook Endpoints

Create SnapHook

POST /snaphook

Request Body:

{
  "name": "production-snaphook",
  "cluster_name": "production-cluster",
  "cluster_config": {
    "api_server_url": "https://api.cluster.com:6443"
  },
  "webhook_url": "https://snap.company.com/webhook",
  "namespace": "snap",
  "cert_expiry_days": 365
}

Start SnapHook

POST /snaphook/{name}/start

Stop SnapHook

POST /snaphook/{name}/stop

List SnapHooks

GET /snaphook/list

WebSocket Endpoints

Progress Updates

WS /ws/progress

Connection:

const ws = new WebSocket('ws://localhost:8000/ws/progress');
ws.onmessage = function(event) {
  const data = JSON.parse(event.data);
  console.log('Progress:', data);
};

Error Responses

All endpoints may return error responses in this format:

{
  "success": false,
  "error": "Error message",
  "details": "Detailed error information",
  "code": "ERROR_CODE"
}

Common Error Codes

Rate Limiting

API requests are rate-limited:

Rate limit headers are included in responses:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1642233600

Examples

Complete Checkpoint Workflow

# 1. Create checkpoint
CHECKPOINT_RESPONSE=$(curl -X POST "http://localhost:8000/checkpoint/kubelet/checkpoint" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "pod_name": "test-app",
    "namespace": "default",
    "node_name": "worker-node-1",
    "container_name": "test-app",
    "cluster_name": "production-cluster"
  }')

# 2. Convert to image
curl -X POST "http://localhost:8000/registry/create_and_push_checkpoint_container" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "checkpoint_name": "test-app-checkpoint",
    "username": "admin",
    "pod_name": "test-app",
    "checkpoint_config_name": "default"
  }'

Cluster Management

# Check cluster status (from DaemonSet)
curl -X GET "http://localhost:8000/cluster/status/production-cluster" \
  -H "Authorization: Bearer $TOKEN"

# Get cluster statistics
curl -X GET "http://localhost:8000/cluster/statistics" \
  -H "Authorization: Bearer $TOKEN"

# Deploy cluster monitor DaemonSet
kubectl apply -f SnapApi/snap-cluster-monitor-daemonset.yaml