Vm delete

From RHEcosystemAppEng/agentic-plugins · View interactive version

Vm delete is an AI agent skill from the GitHub repository RHEcosystemAppEng/agentic-plugins. Permanently delete virtual machines and their associated resources from OpenShift Virtualization. Use when: - "Delete VM [name]" - "Remove virtual machine [name]" - "Destroy VM [name]" - "Clean up VM [name]" This skill handles permanent VM deletion with strict safety confirmations and typed verifica

How to use this skill

Skill file

/vm-delete Skill

Permanently delete virtual machines and their associated resources (storage, DataVolumes) from OpenShift Virtualization clusters. This skill enforces strict safety protocols including typed confirmation and pre-deletion validation.

Prerequisites

Required MCP Server: openshift-virtualization (OpenShift MCP Server)

Required MCP Tools:

Required Environment Variables:

Required Cluster Setup:

Prerequisite Verification

Before executing:

  1. Check openshift-virtualization exists in mcps.json → If missing, report setup
  2. Verify KUBECONFIG is set (presence only, never expose value) → If missing, report
  3. Check RBAC permissions (optional) → Verify delete permissions for VirtualMachine and PVC

Human Notification Protocol: ❌ Cannot execute vm-delete: MCP server not available. Setup: Add to mcps.json, set KUBECONFIG, restart Claude Code. Docs: https://github.com/openshift/openshift-mcp-server

⚠️ SECURITY: Never display KUBECONFIG path or credential values.

When to Use This Skill

Trigger when:

User phrases:

Do NOT use when:

Workflow

Step 1: Gather and Validate

CRITICAL: Complete ALL validation BEFORE user confirmation.

Required from user: VM Name, Namespace

1.1: Verify VM Exists

MCP Tool: resources_get (apiVersion="kubevirt.io/v1", kind="VirtualMachine", namespace=<ns>, name=<vm>)

Errors:

1.2: Check Protection Label

Check metadata.labels for protected: "true".

If protected: Report: ❌ Cannot Delete Protected VM. VM has protected label. Remove: oc label vm <vm> -n <ns> protected-. Operation cancelled. STOP workflow.

1.3: Check Running State

Check status.printableStatus (Running/Starting/Migrating = running, Stopped/Halted = stopped).

If running: Report: ⚠️ VM Running. Must stop before deletion. Options: stop-and-delete / cancel Wait for response.

1.4: Stop VM (if applicable)

ONLY if user chose "stop-and-delete".

MCP Tool: vm_lifecycle (namespace=<ns>, name=<vm>, action="stop")

Report: ⏸️ Stopping VM... Wait 10-30s. Wait 10s, verify stopped.

1.5: Discover Storage

MCP Tool: resources_list

DataVolumes: apiVersion="cdi.kubevirt.io/v1beta1", kind="DataVolume", namespace=<ns>, labelSelector="vm.kubevirt.io/name=<vm>"

PVCs (if no DVs): apiVersion="v1", kind="PersistentVolumeClaim", namespace=<ns>, labelSelector="vm.kubevirt.io/name=<vm>"

Parse: Extract names, calculate total storage size.

Step 2: Present Scope and Get Options

Display deletion scope in this format:

## ⚠️ VM Deletion - Review Scope

**VM**: `<vm>` | **Namespace**: `<ns>` | **Status**: <Stopped/Running>

**Resources**: VM `<vm>` (Age: <age>, vCPU: <cpu>, Memory: <mem>)
**Storage**: DataVolume `<dv>` (30Gi), PVC `<pvc>` (30Gi) - Total: 30Gi
OR **Storage**: None (ephemeral)

### Deletion Options
**1: VM Only** - Preserves storage for reuse
**2: VM + Storage** ← Recommended (test/dev) - Frees storage
**3: Cancel**

Select (1, 2, or 3):

Wait for selection. Handle: 3→Cancel, 1→delete_storage=false, 2→delete_storage=true

Step 3: Typed Confirmation (MANDATORY)

CRITICAL: User MUST type exact VM name.

Display typed confirmation prompt (adjust based on delete_storage flag):

## 🔴 PERMANENT DELETION - Typed Confirmation Required

**CANNOT BE UNDONE**

**Will delete**:
✗ VirtualMachine: `<vm>` (namespace: `<ns>`)
[If delete_storage=true, show:]
✗ DataVolume: `<dv>` | ✗ PVC: `<pvc>` | ✗ All data lost
[If delete_storage=false, show:]
✓ Storage PRESERVED

Type `<vm>` to confirm: _____

Validation:

Step 4: Execute Deletion

ONLY AFTER: ✓ Validation ✓ Option selected ✓ Typed name confirmed

4.1: Delete VM

MCP Tool: resources_delete (apiVersion="kubevirt.io/v1", kind="VirtualMachine", namespace=<ns>, name=<vm>)

Errors: Fails → Report, don't delete storage; Not found → Continue

Report: 🗑️ Deleting VM... ✓ Deleted

4.2: Delete Storage (if delete_storage=true)

For each DataVolume:

MCP Tool: resources_delete (apiVersion="cdi.kubevirt.io/v1beta1", kind="DataVolume", namespace=<ns>, name=<dv>)

For each PVC:

MCP Tool: resources_delete (apiVersion="v1", kind="PersistentVolumeClaim", namespace=<ns>, name=<pvc>)

Errors: Report which failed, continue with others

Report: 🗑️ Deleting storage... ✓ DV deleted (storage freed) ✓ PVC deleted

Step 5: Report Results

Success (with storage):

## ✓ VM Deleted (Complete Cleanup)
**Deleted**: VM + DataVolume + PVC | **Freed**: <size>
**Impact**: Permanent removal. Cannot recover.
**Verify**: "List VMs in namespace <ns>" - VM should not appear

Success (storage preserved):

## ✓ VM Deleted (Storage Preserved)
**Deleted**: VM | **Preserved**: DataVolume + PVC (<size>)
**Reuse**: Create new VM with existing DV/PVC
**Delete later**: `oc delete datavolume <dv> -n <ns>`

Partial failure (storage failed):

OPTIONAL: Read storage-errors.md for PVC cleanup. Output: "Consulted storage-errors.md for failure."

## ⚠️ Partial Deletion
**Deleted**: VM | **Failed**: DV/PVC (error: <error>)
**Action**: Manual cleanup: `oc delete datavolume <dv> -n <ns>`

Complete failure:

OPTIONAL: Read lifecycle-errors.md for deletion failures. Output: "Consulted lifecycle-errors.md for failure causes."

## ❌ VM Deletion Failed
**Error**: <error>
**Troubleshooting**: Check permissions, verify VM exists, check finalizers (see lifecycle-errors.md)

Common Issues

Issue 1: VM Not Found

Error: "VirtualMachine not found"

Solution: Verify name/namespace with vm-inventory. Check spelling.

Issue 2: RBAC Permissions

Error: "Forbidden: Cannot delete VirtualMachines"

Solution: Verify delete permissions for VirtualMachine and PVC. Contact admin. Check: oc auth can-i delete virtualmachines -n <ns>

Issue 3: VM Has Finalizers

Error: "VM deletion blocked by finalizers"

Solution: Consult lifecycle-errors.md "VM Stuck in Terminating" for MCP-first approach using resources_get to check finalizers, resources_create_or_update to remove if needed.

Issue 4: Storage Deletion Failure

Error: "PVC deletion failed: resource in use"

Solution: Verify VM deleted first. Consult storage-errors.md for MCP-first diagnostics using pods_list_in_namespace to check mounts, resources_get for PVC status.

Issue 5: Confirmation Mismatch

Error: "Names do not match"

Solution: Type exact VM name (case-sensitive). Copy-paste from deletion scope. Retry.

Issue 6: Protected VM

Error: "VM has protected label"

Solution: Remove: oc label vm <vm> -n <ns> protected-. Retry deletion.

Dependencies

Required MCP Servers

Required MCP Tools

Related Skills

Reference Documentation

Critical: Human-in-the-Loop Requirements

CRITICAL: IRREVERSIBLE operations. You MUST:

  1. Pre-Deletion Validation (Execute FIRST)
  1. Safety Checks
  1. Typed Confirmation (MANDATORY)
  1. Deletion Options
  1. Never Auto-Execute

Why: Permanent data loss, service impact, accidental deletion prevention

Security Considerations

Example Usage

Example 1: Complete Deletion (VM + Storage)

User: "Delete test-vm in dev"
Agent: [Validates ✓, discovers 30Gi storage]
       [Shows deletion scope - see Step 2 format]
User: "2" [VM+Storage]
Agent: [Shows typed confirmation - see Step 3 format]
User: "test-vm"
Agent: [Executes: VM ✓, DV ✓, PVC ✓]
       [Shows success report - see Step 5 format]
## ✓ VM Deleted (Complete Cleanup) | Freed: 30Gi

Example 2: VM Only (Preserve Storage)

User: "Remove web-server but keep storage"
Agent: [Validates, shows scope]
User: "1" [VM only]
Agent: [Typed confirmation]
User: "web-server"
Agent: [Executes deletion]
## ✓ VM Deleted (Storage Preserved) | Preserved: 50Gi

Example 3: Protected VM (Blocked)

User: "Delete production-db"
Agent: [Validates: protected label found]
❌ Cannot Delete Protected VM. Remove label: oc label vm production-db protected-

Example 4: Running VM (Stop First)

User: "Delete api-server"
Agent: [Validates: VM running]
⚠️ VM Running. Options: stop-and-delete / cancel
User: "stop-and-delete"
Agent: [Stops VM, waits, continues with deletion]

Example 5: User Cancels

User: "Delete test-vm"
Agent: [Shows typed confirmation]
Type `test-vm` to confirm:
User: "wait, cancel"
❌ Confirmation Failed. You typed: wait, cancel. Expected: test-vm. Cancelled.

Example 6: Dry-Run Preview

User: "What would be deleted if I delete test-vm?"
Agent: [Execute Step 1-2 only, stop before confirmation]
## 🔍 Deletion Preview
**Would delete (Option 2)**: VM + DV + PVC (30Gi freed)
This is preview only. No resources deleted.

Advanced Features

Batch Deletion

Delete multiple VMs: "Delete VMs test-01, test-02, test-03 in dev" → Process each VM individually through the full workflow (Steps 1-5), requiring typed confirmation of each VM name separately. Never use a generic batch confirmation — each VM must be confirmed by its exact name.

Dry-Run Mode

Show deletion scope without executing: Execute Step 1-2, skip Steps 3-4. User request: "Show what would be deleted if I delete VM xyz"

Protected VM Label

Automatic enforcement: If VM has protected: "true" label, refuse deletion in Step 1.2. Example YAML: metadata.labels.protected: "true"

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.