49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
namespace PS.IPAM.Cmdlets;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Management.Automation;
|
|
using PS.IPAM.Helpers;
|
|
|
|
/// <summary>
|
|
/// Retrieves VRF information from phpIPAM.
|
|
/// </summary>
|
|
[Cmdlet(VerbsCommon.Get, "Vrf", DefaultParameterSetName = "NoParams")]
|
|
[OutputType(typeof(Vrf))]
|
|
public class GetVrfCmdlet : BaseCmdlet
|
|
{
|
|
[Parameter(
|
|
Mandatory = true,
|
|
ValueFromPipeline = true,
|
|
ValueFromPipelineByPropertyName = true,
|
|
Position = 0,
|
|
ParameterSetName = "ByID",
|
|
HelpMessage = "The VRF ID.")]
|
|
[ValidateNotNullOrEmpty]
|
|
public int? Id { get; set; }
|
|
|
|
protected override void ProcessRecord()
|
|
{
|
|
try
|
|
{
|
|
var identifiers = new List<string>();
|
|
|
|
if (Id.HasValue)
|
|
{
|
|
identifiers.Add(Id.Value.ToString());
|
|
}
|
|
|
|
var result = RequestHelper.InvokeRequest(
|
|
"GET", ApiController.Vrf, ModelType.Vrf, null, null,
|
|
identifiers.Count > 0 ? identifiers.ToArray() : null
|
|
).GetAwaiter().GetResult();
|
|
|
|
WriteResult(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WriteError(new ErrorRecord(ex, "GetVrfError", ErrorCategory.InvalidOperation, null));
|
|
}
|
|
}
|
|
}
|