using System.Management.Automation; using PSProxmoxVE.Core.Models.Vms; using PSProxmoxVE.Core.Services; namespace PSProxmoxVE.Cmdlets.Containers { /// /// Removes an LXC container from a Proxmox VE node. /// /// Deletes an LXC container and, optionally, all associated storage. /// This operation is destructive and requires confirmation unless -Force is specified. /// /// [Cmdlet(VerbsCommon.Remove, "PveContainer", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] [OutputType(typeof(PveTask))] public sealed class RemovePveContainerCmdlet : PveCmdletBase { /// /// /// The node on which the container resides. Accepts pipeline input from a PveNode object's Name property. /// /// [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)] public string Node { get; set; } = string.Empty; /// /// The ID of the container to remove. Accepts pipeline input. /// [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)] public int VmId { get; set; } /// /// /// When specified, also removes the container from HA resource configuration and replication jobs. /// /// [Parameter(Mandatory = false)] public SwitchParameter Purge { get; set; } /// /// /// When specified, bypasses locks and forces removal even if a lock is set on the container. /// /// [Parameter(Mandatory = false)] public SwitchParameter Force { get; set; } /// /// When specified, waits for the removal task to complete before returning. /// [Parameter(Mandatory = false)] public SwitchParameter Wait { get; set; } protected override void ProcessRecord() { if (!ShouldProcess($"Container {VmId} on node '{Node}'", "Remove-PveContainer")) return; var session = GetSession(); var containerService = new ContainerService(); var task = containerService.RemoveContainer(session, Node, VmId, Purge.IsPresent); if (Wait.IsPresent) { var taskService = new TaskService(); task = taskService.WaitForTask(session, task.Node ?? Node, task.Upid!, null, null, null); } WriteObject(task); } } }