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,24 +1,30 @@
|
||||
namespace PS.IPAM.Cmdlets;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Management.Automation;
|
||||
using PS.IPAM;
|
||||
using PS.IPAM.Helpers;
|
||||
|
||||
[Cmdlet("Assign", "Tag")]
|
||||
public class AssignTagCmdlet : PSCmdlet
|
||||
/// <summary>
|
||||
/// Assigns a tag to an address in phpIPAM.
|
||||
/// </summary>
|
||||
[Cmdlet("Assign", "Tag", SupportsShouldProcess = true)]
|
||||
[OutputType(typeof(Address))]
|
||||
public class AssignTagCmdlet : BaseCmdlet
|
||||
{
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 0)]
|
||||
Position = 0,
|
||||
HelpMessage = "The address to assign the tag to.")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public Address? AddressObject { get; set; }
|
||||
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
Position = 1)]
|
||||
Position = 1,
|
||||
HelpMessage = "The tag to assign.")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public Tag? Tag { get; set; }
|
||||
|
||||
@@ -26,14 +32,25 @@ public class AssignTagCmdlet : PSCmdlet
|
||||
{
|
||||
try
|
||||
{
|
||||
var identifiers = new List<string> { AddressObject!.Id.ToString() };
|
||||
var identifiers = new[] { AddressObject!.Id.ToString() };
|
||||
var body = new Dictionary<string, object>
|
||||
{
|
||||
{ "tag", Tag!.Id }
|
||||
["tag"] = Tag!.Id
|
||||
};
|
||||
|
||||
RequestHelper.InvokeRequest("PATCH", controllers.addresses, null, null, body, identifiers.ToArray())
|
||||
.GetAwaiter().GetResult();
|
||||
if (ShouldProcess($"Address {AddressObject.Ip}", $"Assign tag '{Tag.Type}'"))
|
||||
{
|
||||
RequestHelper.InvokeRequest(
|
||||
"PATCH", ApiController.Addresses, null, null, body, identifiers
|
||||
).GetAwaiter().GetResult();
|
||||
|
||||
// Return the updated address
|
||||
var address = RequestHelper.InvokeRequest(
|
||||
"GET", ApiController.Addresses, ModelType.Address, null, null, identifiers
|
||||
).GetAwaiter().GetResult();
|
||||
|
||||
WriteResult(address);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user