hi
Just see the below if it helps and make the below as a executable one .
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
from datetime import datetime, timedelta
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', '<your-subscription-id>')
resource_group_name = '<your-resource-group-name>'
vm_name = '<your-vm-name>'
credential = DefaultAzureCredential()
compute_client = ComputeManagementClient(credential, subscription_id)
def check_spot_vm_eviction():
try:
vm_instance_view = compute_client.virtual_machines.instance_view(resource_group_name, vm_name)
for status in vm_instance_view.statuses:
if status.code == 'ProvisioningState/succeeded' and 'eviction' in status.display_status.lower():
return 1
return 0
except Exception as e:
print(f"Error checking Spot VM eviction: {e}")
return -1
if name == "main":
eviction_status = check_spot_vm_eviction()
print(eviction_status)