using System; using System.Collections.Generic; using System.Management.Automation; using PSProxmox.Client; using PSProxmox.Session; namespace PSProxmox.Cmdlets { /// /// Removes a network interface from Proxmox VE. /// The Remove-ProxmoxNetwork cmdlet removes a network interface from Proxmox VE. /// /// Remove a network interface /// Remove-ProxmoxNetwork -Connection $connection -Node "pve1" -Interface "vmbr1" /// /// /// Remove a network interface using pipeline input /// Get-ProxmoxNetwork -Connection $connection -Node "pve1" -Interface "vmbr1" | Remove-ProxmoxNetwork -Connection $connection /// /// [Cmdlet(VerbsCommon.Remove, "ProxmoxNetwork", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] public class RemoveProxmoxNetworkCmdlet : PSCmdlet { /// /// The connection to the Proxmox VE server. /// [Parameter(Mandatory = true, Position = 0)] public ProxmoxConnection Connection { get; set; } /// /// The node where the network interface is located. /// [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)] public string Node { get; set; } /// /// The name of the interface to remove. /// [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)] public string Interface { get; set; } /// /// Processes the cmdlet. /// protected override void ProcessRecord() { try { var client = new ProxmoxApiClient(Connection, this); // Confirm removal if (!ShouldProcess($"Network interface {Interface} on node {Node}", "Remove")) { return; } // Remove the network interface WriteVerbose($"Removing network interface {Interface} on node {Node}"); client.Delete($"nodes/{Node}/network/{Interface}"); // Apply the network configuration client.Put($"nodes/{Node}/network", new Dictionary()); WriteVerbose($"Network interface {Interface} removed from node {Node}"); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "RemoveProxmoxNetworkError", ErrorCategory.OperationStopped, Interface)); } } } }