using System;
using System.Management.Automation;
using PSProxmox.IPAM;
using PSProxmox.Models;
namespace PSProxmox.Cmdlets
{
///
/// Creates a new IP address pool.
/// The New-ProxmoxIPPool cmdlet creates a new IP address pool for use with Proxmox VE virtual machines.
///
/// Create a new IP pool
/// $pool = New-ProxmoxIPPool -Name "Production" -CIDR "192.168.1.0/24" -ExcludeIPs "192.168.1.1", "192.168.1.254"
///
///
[Cmdlet(VerbsCommon.New, "ProxmoxIPPool")]
[OutputType(typeof(ProxmoxIPPool))]
public class NewProxmoxIPPoolCmdlet : PSCmdlet
{
private static readonly IPAMManager _ipamManager = new IPAMManager();
///
/// The name of the IP pool.
///
[Parameter(Mandatory = true, Position = 0)]
public string Name { get; set; }
///
/// The CIDR notation of the IP pool (e.g., 192.168.1.0/24).
///
[Parameter(Mandatory = true, Position = 1)]
public string CIDR { get; set; }
///
/// IP addresses to exclude from the pool.
///
[Parameter(Mandatory = false)]
public string[] ExcludeIPs { get; set; }
///
/// Processes the cmdlet.
///
protected override void ProcessRecord()
{
try
{
var pool = _ipamManager.CreatePool(Name, CIDR, ExcludeIPs);
WriteObject(ProxmoxIPPool.FromIPPool(pool));
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, "NewProxmoxIPPoolError", ErrorCategory.InvalidOperation, Name));
}
}
}
}