using System; using System.Collections.Generic; using System.Management.Automation; using PSProxmox.IPAM; using PSProxmox.Models; namespace PSProxmox.Cmdlets { /// /// Gets IP address pools. /// The Get-ProxmoxIPPool cmdlet retrieves IP address pools used with Proxmox VE virtual machines. /// /// Get all IP pools /// $pools = Get-ProxmoxIPPool /// /// /// Get a specific IP pool by name /// $pool = Get-ProxmoxIPPool -Name "Production" /// /// [Cmdlet(VerbsCommon.Get, "ProxmoxIPPool")] [OutputType(typeof(ProxmoxIPPool))] public class GetProxmoxIPPoolCmdlet : PSCmdlet { private static readonly IPAMManager _ipamManager = new IPAMManager(); /// /// The name of the IP pool to retrieve. /// [Parameter(Mandatory = false, Position = 0)] public string Name { get; set; } /// /// Processes the cmdlet. /// protected override void ProcessRecord() { try { if (string.IsNullOrEmpty(Name)) { // Get all pools var pools = new List(); foreach (var pool in _ipamManager.GetPools()) { pools.Add(ProxmoxIPPool.FromIPPool(pool)); } WriteObject(pools, true); } else { // Get a specific pool var pool = _ipamManager.GetPool(Name); WriteObject(ProxmoxIPPool.FromIPPool(pool)); } } catch (Exception ex) { WriteError(new ErrorRecord(ex, "GetProxmoxIPPoolError", ErrorCategory.InvalidOperation, Name)); } } } }