L’API de gestion des instances vous permet de créer, modifier, supprimer et administrer vos instances cloud programmatiquement. Toutes les opérations disponibles dans l’espace client sont accessibles via l’API.
# Lister toutes les instances
curl -X GET "https://api.m2s.cloud/v1/instances" \
-H "Authorization: Bearer YOUR_API_KEY"
# Avec pagination
curl -X GET "https://api.m2s.cloud/v1/instances?page=1&limit=20" \
-H "Authorization: Bearer YOUR_API_KEY"
# Filtrer par statut
curl -X GET "https://api.m2s.cloud/v1/instances?status=running" \
-H "Authorization: Bearer YOUR_API_KEY"
# Filtrer par région
curl -X GET "https://api.m2s.cloud/v1/instances?region=fr-par-1" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": [
{
"id": "i-abc123",
"name": "web-prod-01",
"status": "running",
"plan": "business",
"region": "fr-par-1",
"ip_address": "51.15.0.100",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-20T14:22:00Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 5,
"total_pages": 1
}
}
# Création simple
curl -X POST "https://api.m2s.cloud/v1/instances" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "web-prod-01",
"plan": "business",
"region": "fr-par-1",
"image": "ubuntu-22.04"
}'
# Création avancée avec SSH key et networking
curl -X POST "https://api.m2s.cloud/v1/instances" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "db-prod-01",
"plan": "performance",
"region": "fr-par-1",
"image": "ubuntu-22.04",
"ssh_keys": ["ssh-rsa AAAA..."],
"backup_enabled": true,
"monitoring_enabled": true,
"private_network": "pn-abc123",
"tags": ["production", "database"]
}'
{
"data": {
"id": "i-xyz789",
"name": "db-prod-01",
"status": "provisioning",
"plan": "performance",
"region": "fr-par-1",
"image": "ubuntu-22.04",
"created_at": "2024-01-20T15:00:00Z"
},
"message": "Instance en cours de création. Comptez 2-3 minutes."
}
| Plan | CPU | RAM | Prix/mois |
|---|---|---|---|
| starter | 1 vCPU | 2 Go | 5 € |
| business | 2 vCPU | 4 Go | 15 € |
| performance | 4 vCPU | 8 Go | 30 € |
| enterprise | 8 vCPU | 16 Go | 60 € |
# Détails d'une instance
curl -X GET "https://api.m2s.cloud/v1/instances/i-abc123" \
-H "Authorization: Bearer YOUR_API_KEY"
# Inclure les métriques
curl -X GET "https://api.m2s.cloud/v1/instances/i-abc123?include=metrics" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": {
"id": "i-abc123",
"name": "web-prod-01",
"status": "running",
"plan": "business",
"region": "fr-par-1",
"ip_address": "51.15.0.100",
"ipv6_address": "2001:bc8:1234::100",
"disk_size": 50,
"memory": 4096,
"vcpu": 2,
"image": "ubuntu-22.04",
"backup_enabled": true,
"monitoring_enabled": true,
"tags": ["production", "web"],
"created_at": "2024-01-15T10:30:00Z",
"metrics": {
"cpu_usage": 45.2,
"memory_usage": 62.8,
"disk_usage": 38.5,
"network_in": 1024000,
"network_out": 2048000
}
}
}
# Changer le plan (resize)
curl -X PATCH "https://api.m2s.cloud/v1/instances/i-abc123" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"plan": "performance"}'
# Mettre à jour les tags
curl -X PATCH "https://api.m2s.cloud/v1/instances/i-abc123" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"tags": ["production", "web", "frontend"]}'
# Activer les backups
curl -X PATCH "https://api.m2s.cloud/v1/instances/i-abc123" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"backup_enabled": true}'
Note
Le changement de plan (resize) nécessite un redémarrage de l’instance. L’API redémarrera automatiquement l’instance sauf si vous ajoutez "reboot": false.
# Démarrer une instance
curl -X POST "https://api.m2s.cloud/v1/instances/i-abc123/start" \
-H "Authorization: Bearer YOUR_API_KEY"
# Arrêter une instance (soft shutdown)
curl -X POST "https://api.m2s.cloud/v1/instances/i-abc123/stop" \
-H "Authorization: Bearer YOUR_API_KEY"
# Arrêt forcé (power off)
curl -X POST "https://api.m2s.cloud/v1/instances/i-abc123/poweroff" \
-H "Authorization: Bearer YOUR_API_KEY"
# Redémarrer
curl -X POST "https://api.m2s.cloud/v1/instances/i-abc123/reboot" \
-H "Authorization: Bearer YOUR_API_KEY"
# Rebuild (réinstaller)
curl -X POST "https://api.m2s.cloud/v1/instances/i-abc123/rebuild" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"image": "ubuntu-22.04"}'
# Supprimer une instance
curl -X DELETE "https://api.m2s.cloud/v1/instances/i-abc123" \
-H "Authorization: Bearer YOUR_API_KEY"
La suppression d’instance est irréversible. Assurez-vous d’avoir sauvegardé vos données. Les snapshots associés peuvent être conservés séparément.
#!/bin/bash
API_KEY="YOUR_API_KEY"
INSTANCE_ID="i-abc123"
TARGET_STATUS="running"
echo "Attente du statut '$TARGET_STATUS'..."
while true; do
STATUS=$(curl -s "https://api.m2s.cloud/v1/instances/$INSTANCE_ID" \
-H "Authorization: Bearer $API_KEY" | jq -r '.data.status')
echo "$(date +%T) - Statut: $STATUS"
if [ "$STATUS" = "$TARGET_STATUS" ]; then
echo "Instance $TARGET_STATUS !"
break
fi
sleep 5
done