Refactor IPAM model classes to use records for Address, Subnetwork, Vlan, Vrf, Section, Tag, Domain, Nameserver, and Session; enhance documentation and implement value equality for records.

This commit is contained in:
2026-01-19 17:25:18 +03:00
parent 694822f0d6
commit f56784f2aa
44 changed files with 1601 additions and 1905 deletions

View File

@@ -1,20 +1,24 @@
namespace PS.IPAM.Cmdlets;
using System;
using System.Collections.Generic;
using System.Management.Automation;
using PS.IPAM;
using PS.IPAM.Helpers;
/// <summary>
/// Retrieves VLAN information from phpIPAM.
/// </summary>
[Cmdlet(VerbsCommon.Get, "Vlan", DefaultParameterSetName = "NoParams")]
[OutputType(typeof(Vlan))]
public class GetVlanCmdlet : PSCmdlet
public class GetVlanCmdlet : BaseCmdlet
{
[Parameter(
Mandatory = true,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
Position = 0,
ParameterSetName = "ByID")]
ParameterSetName = "ByID",
HelpMessage = "The VLAN ID.")]
[ValidateNotNullOrEmpty]
public int? Id { get; set; }
@@ -23,7 +27,8 @@ public class GetVlanCmdlet : PSCmdlet
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
Position = 0,
ParameterSetName = "ByNumber")]
ParameterSetName = "ByNumber",
HelpMessage = "The VLAN number.")]
[ValidateNotNullOrEmpty]
public int? Number { get; set; }
@@ -32,7 +37,8 @@ public class GetVlanCmdlet : PSCmdlet
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
Position = 0,
ParameterSetName = "ByL2Domain")]
ParameterSetName = "ByL2Domain",
HelpMessage = "The L2 domain ID to get VLANs from.")]
[ValidateNotNullOrEmpty]
public int? L2DomainId { get; set; }
@@ -41,7 +47,8 @@ public class GetVlanCmdlet : PSCmdlet
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
Position = 0,
ParameterSetName = "BySubnetObject")]
ParameterSetName = "BySubnetObject",
HelpMessage = "Get the VLAN associated with this subnet.")]
[ValidateNotNullOrEmpty]
public Subnetwork? SubnetObject { get; set; }
@@ -50,7 +57,8 @@ public class GetVlanCmdlet : PSCmdlet
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
Position = 0,
ParameterSetName = "ByDomainObject")]
ParameterSetName = "ByDomainObject",
HelpMessage = "Get VLANs in this L2 domain.")]
[ValidateNotNullOrEmpty]
public Domain? DomainObject { get; set; }
@@ -58,7 +66,7 @@ public class GetVlanCmdlet : PSCmdlet
{
try
{
var controller = controllers.vlan;
var controller = ApiController.Vlan;
var identifiers = new List<string>();
switch (ParameterSetName)
@@ -66,65 +74,44 @@ public class GetVlanCmdlet : PSCmdlet
case "ByID":
identifiers.Add(Id!.Value.ToString());
break;
case "ByNumber":
identifiers.Add("search");
identifiers.Add(Number!.Value.ToString());
break;
case "ByL2Domain":
controller = controllers.l2domains;
controller = ApiController.L2Domains;
identifiers.Add(L2DomainId!.Value.ToString());
identifiers.Add(subcontrollers.vlans.ToString());
identifiers.Add(ApiSubController.Vlans.ToString().ToLowerInvariant());
break;
case "BySubnetObject":
if (SubnetObject != null && SubnetObject.VlanId > 0)
{
identifiers.Add(SubnetObject.VlanId.ToString());
}
else
if (SubnetObject == null || SubnetObject.VlanId <= 0)
{
return;
}
identifiers.Add(SubnetObject.VlanId.ToString());
break;
case "ByDomainObject":
if (DomainObject != null)
{
var result = RequestHelper.InvokeRequest("GET", controllers.l2domains, types.Vlan, subcontrollers.vlans, null, new[] { DomainObject.Id.ToString() })
.GetAwaiter().GetResult();
if (result != null)
{
if (result is System.Collections.IEnumerable enumerable && !(result is string))
{
foreach (var item in enumerable)
{
WriteObject(item);
}
}
else
{
WriteObject(result);
}
}
var result = RequestHelper.InvokeRequest(
"GET", ApiController.L2Domains, ModelType.Vlan, ApiSubController.Vlans,
null, new[] { DomainObject.Id.ToString() }
).GetAwaiter().GetResult();
WriteResult(result);
}
return;
}
var vlanResult = RequestHelper.InvokeRequest("GET", controller, types.Vlan, null, null, identifiers.Count > 0 ? identifiers.ToArray() : null)
.GetAwaiter().GetResult();
var vlanResult = RequestHelper.InvokeRequest(
"GET", controller, ModelType.Vlan, null, null,
identifiers.Count > 0 ? identifiers.ToArray() : null
).GetAwaiter().GetResult();
if (vlanResult != null)
{
if (vlanResult is System.Collections.IEnumerable enumerable && !(vlanResult is string))
{
foreach (var item in enumerable)
{
WriteObject(item);
}
}
else
{
WriteObject(vlanResult);
}
}
WriteResult(vlanResult);
}
catch (Exception ex)
{