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:
@@ -1,27 +1,31 @@
|
||||
namespace PS.IPAM.Cmdlets;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Management.Automation;
|
||||
using PS.IPAM;
|
||||
using PS.IPAM.Helpers;
|
||||
|
||||
[Cmdlet(VerbsCommon.Remove, "Address", DefaultParameterSetName = "ByID")]
|
||||
public class RemoveAddressCmdlet : PSCmdlet
|
||||
/// <summary>
|
||||
/// Removes an IP address entry from phpIPAM.
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Remove, "Address", DefaultParameterSetName = "ById", SupportsShouldProcess = true)]
|
||||
public class RemoveAddressCmdlet : BaseCmdlet
|
||||
{
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
Position = 0,
|
||||
ParameterSetName = "ByID")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public int? Id { get; set; }
|
||||
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 0,
|
||||
ParameterSetName = "ByAddressObject")]
|
||||
ParameterSetName = "ById",
|
||||
HelpMessage = "The address ID to remove.")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
Position = 0,
|
||||
ParameterSetName = "ByAddressObject",
|
||||
HelpMessage = "The address object to remove.")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public Address? AddressObject { get; set; }
|
||||
|
||||
@@ -29,19 +33,17 @@ public class RemoveAddressCmdlet : PSCmdlet
|
||||
{
|
||||
try
|
||||
{
|
||||
int addressId;
|
||||
if (ParameterSetName == "ByID")
|
||||
{
|
||||
addressId = Id!.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
addressId = AddressObject!.Id;
|
||||
}
|
||||
var addressId = ParameterSetName == "ById" ? Id : AddressObject!.Id;
|
||||
var identifiers = new[] { addressId.ToString() };
|
||||
|
||||
var identifiers = new List<string> { addressId.ToString() };
|
||||
RequestHelper.InvokeRequest("DELETE", controllers.addresses, null, null, null, identifiers.ToArray())
|
||||
.GetAwaiter().GetResult();
|
||||
if (ShouldProcess($"Address ID: {addressId}", "Remove"))
|
||||
{
|
||||
RequestHelper.InvokeRequest(
|
||||
"DELETE", ApiController.Addresses, null, null, null, identifiers
|
||||
).GetAwaiter().GetResult();
|
||||
|
||||
WriteVerbose($"Address {addressId} removed successfully.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user