Fixes, added session class
This commit is contained in:
@@ -23,6 +23,7 @@ public class Address {
|
||||
public string FirewallAddressObject { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public int CustomerId { get; }
|
||||
public Object? ExtendedData { get; }
|
||||
|
||||
public Address(
|
||||
int id,
|
||||
@@ -44,7 +45,8 @@ public class Address {
|
||||
int PTR,
|
||||
string firewallAddressObject,
|
||||
DateTime? editDate,
|
||||
int customer_id
|
||||
int customer_id,
|
||||
Object? extendedData
|
||||
) {
|
||||
this.Id = id;
|
||||
this.SubnetId = subnetId;
|
||||
@@ -66,6 +68,7 @@ public class Address {
|
||||
this.FirewallAddressObject = firewallAddressObject;
|
||||
this.EditDate = editDate;
|
||||
this.CustomerId = customer_id;
|
||||
this.ExtendedData = extendedData;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
|
||||
@@ -12,6 +12,7 @@ public class Section {
|
||||
public string SubnetOrdering { get; }
|
||||
public int Order { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public bool ShowSubnet { get; }
|
||||
public bool ShowVlan { get; }
|
||||
public bool ShowVRF { get; }
|
||||
public bool ShowSupernetOnly { get; }
|
||||
@@ -27,6 +28,7 @@ public class Section {
|
||||
string subnetOrdering,
|
||||
int order,
|
||||
DateTime? editDate,
|
||||
bool showSubnet,
|
||||
bool showVlan,
|
||||
bool showVRF,
|
||||
bool showSupernetOnly,
|
||||
@@ -41,6 +43,7 @@ public class Section {
|
||||
this.SubnetOrdering = subnetOrdering;
|
||||
this.Order = order;
|
||||
this.EditDate = editDate;
|
||||
this.ShowSubnet = showSubnet;
|
||||
this.ShowVlan = showVlan;
|
||||
this.ShowVRF = showVRF;
|
||||
this.ShowSupernetOnly = showSupernetOnly;
|
||||
|
||||
32
classlib/class/session.cs
Normal file
32
classlib/class/session.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace PS.IPAM;
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class Session {
|
||||
public AuthType AuthType { get; }
|
||||
public string Token { get; }
|
||||
public string AppID { get; }
|
||||
public string URL { get; }
|
||||
public DateTime? Expires { get; }
|
||||
public Object? Credentials { get; }
|
||||
public Session(
|
||||
AuthType authType,
|
||||
string token,
|
||||
string appId,
|
||||
string url,
|
||||
DateTime? expires,
|
||||
Object? credentials
|
||||
) {
|
||||
AuthType = authType;
|
||||
Token = token;
|
||||
AppID = appId;
|
||||
URL = url;
|
||||
Expires = expires;
|
||||
Credentials = credentials;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public class Vrf {
|
||||
public string Description { get; }
|
||||
public string Sections { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
public Object? ExtendedData { get; }
|
||||
|
||||
public Vrf(
|
||||
int id,
|
||||
@@ -16,7 +17,8 @@ public class Vrf {
|
||||
string rd,
|
||||
string description,
|
||||
string sections,
|
||||
DateTime? editDate
|
||||
DateTime? editDate,
|
||||
Object? custom_fields
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
@@ -24,6 +26,7 @@ public class Vrf {
|
||||
this.Description = description;
|
||||
this.Sections = sections;
|
||||
this.EditDate = editDate;
|
||||
this.ExtendedData = custom_fields;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
8
classlib/enum/authType.cs
Normal file
8
classlib/enum/authType.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace PS.IPAM;
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public enum AuthType {
|
||||
credentials,
|
||||
token
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace PS.IPAM;
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public enum methods {
|
||||
GET,
|
||||
POST,
|
||||
PATCH,
|
||||
DELETE
|
||||
}
|
||||
@@ -2,7 +2,8 @@ function Invoke-Request {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[parameter(Mandatory=$true)]
|
||||
[PS.IPAM.methods]
|
||||
[ValidateSet("GET","POST","PATCH","DELETE")]
|
||||
[string]
|
||||
$Method,
|
||||
[parameter(Mandatory=$true)]
|
||||
[PS.IPAM.controllers]
|
||||
@@ -27,7 +28,7 @@ function Invoke-Request {
|
||||
|
||||
$Controller = $Controller
|
||||
|
||||
$_uri = "$($script:ipamURL)/api/$($script:ipamAppID)/$Controller"
|
||||
$_uri = "$($script:psipamSession.URL)/api/$($script:psipamSession.AppID)/$Controller"
|
||||
if ($SubController) { $_uri += "/$SubController" }
|
||||
if ($Identifiers) { $_uri += "/$($Identifiers -join '/')/" }
|
||||
|
||||
@@ -35,9 +36,9 @@ function Invoke-Request {
|
||||
"Accept" = "application/json"
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
switch ($script:ipamAuthType) {
|
||||
"Credentials" { $_headers.Add("token", $script:ipamToken) }
|
||||
"Token" { $_headers.Add("phpipam-token", $script:ipamToken) }
|
||||
switch ($script:psipamSession.AuthType) {
|
||||
"Credentials" { $_headers.Add("token", $script:psipamSession.Token) }
|
||||
"Token" { $_headers.Add("phpipam-token", $script:psipamSession.Token) }
|
||||
}
|
||||
|
||||
$_arguments = @{
|
||||
@@ -46,7 +47,7 @@ function Invoke-Request {
|
||||
Headers = $_headers
|
||||
}
|
||||
|
||||
if ($Method -eq [PS.IPAM.methods]::POST -or $Method -eq [PS.IPAM.methods]::PATCH) {
|
||||
if ($Method -eq "POST" -or $Method -eq "PATCH") {
|
||||
if ($Params -is [PSCustomObject]) {
|
||||
$_params = @{};
|
||||
$Params | Get-Member -MemberType *Property | Where-Object {
|
||||
@@ -57,23 +58,40 @@ function Invoke-Request {
|
||||
$_arguments.Add("Body",($_params | ConvertTo-Json))
|
||||
}
|
||||
|
||||
$_response = Invoke-RestMethod @_arguments
|
||||
Write-Verbose -Message "Invoking web request to $($_uri), with method $($_arguments.Method), headers: $($_arguments.Headers)"
|
||||
|
||||
$_response = Invoke-RestMethod @_arguments
|
||||
|
||||
if ($_response.code -match "20\d") {
|
||||
if ($Type -is [PS.IPAM.types]) {
|
||||
switch ($Type) {
|
||||
"vlan" {
|
||||
"address" {
|
||||
$_paramList = @("id","subnetId","ip","is_gateway","description","hostname","mac","owner","tag","deviceId","location","port","note","lastSeen","excludePing","PTRignore","PTR","firewallAddressObject","editDate","customer_id")
|
||||
|
||||
$_response.data | ForEach-Object {
|
||||
New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@($_.psobject.properties.value[0..6]) + ($_ | Select-Object -Property custom_* -ExcludeProperty custom_*))
|
||||
New-Object -TypeName ([PS.IPAM.Address]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||
}; break
|
||||
}
|
||||
"vlan" {
|
||||
$_paramList = @("vlanId","domainId","name","number","description","editDate","customer_id","custom_fields")
|
||||
|
||||
$_response.data | ForEach-Object {
|
||||
New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||
}; break
|
||||
}
|
||||
"subnetwork" {
|
||||
$_response.data | ForEach-Object {
|
||||
New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty custom_*))
|
||||
New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||
}; break
|
||||
}
|
||||
"vrf" {
|
||||
$_response.data | ForEach-Object {
|
||||
New-Object -TypeName ([PS.IPAM.Vrf]) -ArgumentList (@($_.psobject.properties.value[0..5]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||
}; break
|
||||
}
|
||||
Default { $_response.data | ForEach-Object { New-Object -TypeName ("PS.IPAM.$Type") -ArgumentList $_.psobject.properties.value } }
|
||||
}
|
||||
|
||||
} else {
|
||||
return $_response.data
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ function Test-Session {
|
||||
param (
|
||||
|
||||
)
|
||||
if ($script:ipamToken) {
|
||||
if ($script:ipamExpires -eq "Never") {
|
||||
if ($script:psipamSession) {
|
||||
if ($null -eq $script:psipamSession.Expires) {
|
||||
return "Valid"
|
||||
} else {
|
||||
if ($script:ipamExpires -lt (Get-Date)) {
|
||||
if ($script:psipamSession.Expires -lt (Get-Date)) {
|
||||
return "Expired"
|
||||
} else {
|
||||
return "Valid"
|
||||
|
||||
@@ -9,10 +9,10 @@ function Update-Session {
|
||||
throw "No session available!"
|
||||
}
|
||||
if ($_tokenStatus -eq "Valid") {
|
||||
return (Invoke-Request -Method PATCH -Controller user).expires
|
||||
return (Invoke-Request -Method [ps.ipam.methods]::PATCH -Controller [ps.ipam.controllers]::user).expires
|
||||
}
|
||||
if ($_tokenStatus -eq "Expired" -or $Force) {
|
||||
New-Session -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials
|
||||
return $script:ipamExpires
|
||||
New-Session -URL $script:psipamSession.URL -AppID $script:psipamSession.AppID -Credentials $script:psipamSession.Credentials
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,25 @@ function Get-Address {
|
||||
[OutputType([PS.IPAM.address])]
|
||||
param (
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByIP")]
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="BySubnetId")]
|
||||
[ValidateScript({[ipaddress] $_})]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[ipaddress]
|
||||
$IP,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByHostName")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$HostName,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByTag")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$TagId,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetId")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$SubnetId,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetCIDR")]
|
||||
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
|
||||
@@ -36,7 +32,7 @@ function Get-Address {
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = [PS.IPAM.controllers]::addresses
|
||||
Method = [PS.IPAM.methods]::GET
|
||||
Method = "GET"
|
||||
Type = [PS.IPAM.types]::address
|
||||
}
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
|
||||
@@ -7,9 +7,8 @@ function Get-FirstFreeIP {
|
||||
[string]
|
||||
$CIDR,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
@@ -19,7 +18,7 @@ function Get-FirstFreeIP {
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = [PS.IPAM.controllers]::subnets
|
||||
Method = [PS.IPAM.methods]::GET
|
||||
Method = "GET"
|
||||
}
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"ByID" { $_subnetId = $Id; break }
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
function Get-L2Domain {
|
||||
[CmdletBinding(DefaultParameterSetName="NoParams")]
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
[OutputType([PS.IPAM.Domain])]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[int]
|
||||
$Id
|
||||
@@ -11,16 +10,11 @@ function Get-L2Domain {
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = [PS.IPAM.controllers]::l2domains
|
||||
Method = [PS.IPAM.methods]::GET
|
||||
Method = "GET"
|
||||
Type = [PS.IPAM.types]::Domain
|
||||
}
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"ByID" {
|
||||
$_identifiers = @($Id)
|
||||
}
|
||||
}
|
||||
|
||||
$_identifiers = @($Id)
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
Invoke-Request @_params
|
||||
|
||||
@@ -2,9 +2,8 @@ function Get-Nameserver {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id
|
||||
)
|
||||
process {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
function Get-Section {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
[CmdletBinding(DefaultParameterSetName="NoParams")]
|
||||
[OutputType([PS.IPAM.Section])]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByName")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
@@ -12,12 +12,10 @@ function Get-Section {
|
||||
$Name
|
||||
)
|
||||
process {
|
||||
[string[]]$visiblePropertiesList = @('Id','Name','Description')
|
||||
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
|
||||
|
||||
$_params = @{
|
||||
Controller = "sections"
|
||||
Controller = [PS.IPAM.controllers]::sections
|
||||
Method = "GET"
|
||||
Type = [PS.IPAM.types]::Section
|
||||
}
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"ByID" { $_identifiers = @($Id) }
|
||||
@@ -25,8 +23,7 @@ function Get-Section {
|
||||
}
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
Invoke-Request @_params | `
|
||||
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
|
||||
Invoke-Request @_params
|
||||
}
|
||||
}
|
||||
Export-ModuleMember Get-Section
|
||||
@@ -8,16 +8,14 @@ function Get-Subnet {
|
||||
[string]
|
||||
$CIDR,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionId")]
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="ByVlanNumber")]
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanId")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$SectionId,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionName")]
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3,ParameterSetName="ByVlanNumber")]
|
||||
@@ -26,25 +24,21 @@ function Get-Subnet {
|
||||
[string]
|
||||
$SectionName,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVrfId")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$VrfId,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanId")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$VlanId,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanNumber")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$VlanNumber,
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanNumber")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$VlanDomain,
|
||||
[int]
|
||||
$VlanDomainId,
|
||||
[parameter(Mandatory=$false,ParameterSetName="ByID")]
|
||||
[switch]
|
||||
$Slaves,
|
||||
@@ -55,7 +49,7 @@ function Get-Subnet {
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = [PS.IPAM.controllers]::subnets
|
||||
Method = [PS.IPAM.methods]::GET
|
||||
Method = "GET"
|
||||
Type = [PS.IPAM.types]::Subnetwork
|
||||
}
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
|
||||
@@ -3,9 +3,8 @@ function Get-Tag {
|
||||
[OutputType([PS.IPAM.Tag])]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
@@ -19,7 +18,7 @@ function Get-Tag {
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = [PS.IPAM.controllers]::addresses
|
||||
Method = [PS.IPAM.methods]::GET
|
||||
Method = "GET"
|
||||
Type = [PS.IPAM.types]::tag
|
||||
}
|
||||
$_identifiers = @("tags")
|
||||
|
||||
@@ -3,29 +3,30 @@ function Get-Vlan {
|
||||
[OutputType([PS.IPAM.Vlan])]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByNumber")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Number,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByL2Domain")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$L2DomainId,
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PS.IPAM.Subnetwork]
|
||||
$SubnetObject
|
||||
$SubnetObject,
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByDomainObject")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PS.IPAM.Domain]
|
||||
$DomainObject
|
||||
)
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = [PS.IPAM.controllers]::vlan
|
||||
Method = [PS.IPAM.methods]::GET
|
||||
Method = "GET"
|
||||
Type = [PS.IPAM.types]::Vlan
|
||||
}
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
@@ -46,6 +47,9 @@ function Get-Vlan {
|
||||
return $null
|
||||
}
|
||||
}
|
||||
"DomainObject" {
|
||||
Get-Vlan -L2DomainId $DomainObject.Id
|
||||
}
|
||||
}
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
function Get-Vrf {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
[OutputType([PS.IPAM.Vrf])]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id
|
||||
)
|
||||
process {
|
||||
[string[]]$visiblePropertiesList = @('Id','Name','Description')
|
||||
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
|
||||
|
||||
$_params = @{
|
||||
Controller = "vrf"
|
||||
Controller = [PS.IPAM.controllers]::vrf
|
||||
Method = "GET"
|
||||
Type = [PS.IPAM.types]::vrf
|
||||
}
|
||||
if ($Id) { $_identifiers = @($Id) }
|
||||
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
Invoke-Request @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | `
|
||||
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
|
||||
Invoke-Request @_params
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function Get-Vrf
|
||||
@@ -7,9 +7,8 @@ function New-Address {
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of subnet address belongs to",
|
||||
Position=0)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$SubnetId,
|
||||
[parameter(
|
||||
Mandatory=$true,
|
||||
@@ -72,9 +71,8 @@ function New-Address {
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of subnet address belongs to",
|
||||
Position=7)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$TagId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
@@ -90,9 +88,8 @@ function New-Address {
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of PowerDNS PTR record",
|
||||
Position=7)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$PTRId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
@@ -117,9 +114,8 @@ function New-Address {
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of device address belongs to",
|
||||
Position=12)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$DeviceId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
@@ -137,7 +133,7 @@ function New-Address {
|
||||
)
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = "addresses"
|
||||
Controller = [PS.IPAM.controllers]::addresses
|
||||
Method = "POST"
|
||||
}
|
||||
|
||||
|
||||
@@ -29,25 +29,30 @@ function New-Session {
|
||||
"Authorization" = "Basic $_auth"
|
||||
}
|
||||
|
||||
$_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue
|
||||
$_response = Invoke-RestMethod -Method POST -Uri $_uri -Headers $_headers
|
||||
|
||||
if ($_response.success -ne $true) { return $_response.error }
|
||||
|
||||
$script:ipamAuthType = "Credentials"
|
||||
$script:ipamAuth = $true
|
||||
$script:ipamToken = $_response.data.token
|
||||
$script:ipamAppID = $AppID
|
||||
$script:ipamURL = $URL
|
||||
$script:ipamCredentials = $Credentials
|
||||
$script:ipamExpires = Get-Date $_response.data.expires
|
||||
$script:psipamSession = [PS.IPAM.Session]::new(
|
||||
[ps.ipam.authType]::credentials,
|
||||
$_response.data.token,
|
||||
$AppID,
|
||||
$URL,
|
||||
(Get-Date $_response.data.expires),
|
||||
$Credentials
|
||||
)
|
||||
break
|
||||
}
|
||||
"Token" {
|
||||
$script:ipamAuthType = "Token"
|
||||
$script:ipamAuth = $true
|
||||
$script:ipamToken = $Token
|
||||
$script:ipamAppID = $AppID
|
||||
$script:ipamURL = $URL
|
||||
$script:ipamExpires = "Never"
|
||||
$script:psipamSession = [PS.IPAM.Session]::new(
|
||||
[ps.ipam.authType]::token,
|
||||
$Token,
|
||||
$AppID,
|
||||
$URL,
|
||||
$null,
|
||||
$null
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,30 +2,23 @@ function Remove-Address {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
param (
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByIP")]
|
||||
[ValidateScript({[ipaddress] $_ })]
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$IP,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=1,ParameterSetName="ByIP")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$SubnetId
|
||||
[PS.IPAM.Address]
|
||||
$AddressObject
|
||||
)
|
||||
process {
|
||||
$_params = @{
|
||||
Controller = "addresses"
|
||||
Controller = [PS.IPAM.controllers]::addresses
|
||||
Method = "DELETE"
|
||||
}
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"ByID" { $_identifiers = @($Id) }
|
||||
"ByIP" { $_identifiers = @($IP,$SubnetId) }
|
||||
"ByID" { $_identifiers = @($Id);break }
|
||||
"ByAddressObject" { $_identifiers = @($AddressObject.Id);break }
|
||||
}
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
|
||||
@@ -1,127 +1,61 @@
|
||||
function Set-Address {
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(DefaultParameterSetName="ById")]
|
||||
param (
|
||||
[parameter(
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of subnet address belongs to",
|
||||
Position=0)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Id of subnet address belongs to",Position=0,ParameterSetName="ById")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Defines if address is presented as gateway",
|
||||
Position=1)]
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PS.IPAM.Address]
|
||||
$AddressObject,
|
||||
[parameter(Mandatory=$false,HelpMessage="Defines if address is presented as gateway",Position=1)]
|
||||
[bool]
|
||||
$Gateway,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Address description",
|
||||
Position=2)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Address description",Position=2)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Description,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Address hostname",
|
||||
Position=3)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Address hostname",Position=3)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Hostname,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Mac address",
|
||||
Position=4)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Mac address",Position=4)]
|
||||
[ValidateScript({ $_.Replace(":","") -match "^$('([A-F0-9]{2})' * 6)$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$MAC,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Address owner",
|
||||
Position=5)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Address owner",Position=5)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Owner,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of subnet address belongs to",
|
||||
Position=6)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[parameter(Mandatory=$false,HelpMessage="Id of subnet address belongs to",Position=6)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$TagId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Controls if PTR should not be created",
|
||||
Position=7)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Controls if PTR should not be created",Position=7)]
|
||||
[bool]
|
||||
$PTRIgnore,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of PowerDNS PTR record",
|
||||
Position=8)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[parameter(Mandatory=$false,HelpMessage="Id of PowerDNS PTR record",Position=8)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$PTRId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Note",
|
||||
Position=9)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Note",Position=9)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Note,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Exclude this address from status update scans (ping)",
|
||||
Position=10)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Exclude this address from status update scans (ping)",Position=10)]
|
||||
[bool]
|
||||
$ExcludePing,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of device address belongs to",
|
||||
Position=11)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[parameter(Mandatory=$false,HelpMessage="Id of device address belongs to",Position=11)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$DeviceId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Port",
|
||||
Position=12)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Port",Position=12)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Port,
|
||||
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
|
||||
[parameter(Mandatory=$false)]
|
||||
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
|
||||
$CustomFields
|
||||
)
|
||||
@@ -130,21 +64,25 @@ function Set-Address {
|
||||
Controller = "addresses"
|
||||
Method = "PATCH"
|
||||
}
|
||||
$_identifiers = @($Id)
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"ByID" { $_id = $Id;break }
|
||||
"ByAddressObject" { $_id = $AddressObject.id;break }
|
||||
}
|
||||
$_identifiers = @($_id)
|
||||
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
$_body = @{ }
|
||||
if ($Gateway) { $_body.Add("is_gateway", [int]$Gateway) }
|
||||
if ($Gateway) { $_body.Add("is_gateway", $Gateway) }
|
||||
if ($Description) { $_body.Add("description", $Description) }
|
||||
if ($Hostname) { $_body.Add("hostname", $Hostname) }
|
||||
if ($MAC) { $_body.Add("mac", $MAC) }
|
||||
if ($Owner) { $_body.Add("owner", $Owner) }
|
||||
if ($TagId) { $_body.Add("tag", $TagId) }
|
||||
if ($PTRIgnore) { $_body.Add("PTRignore", [int]$PTRIgnore) }
|
||||
if ($PTRIgnore) { $_body.Add("PTRignore", $PTRIgnore) }
|
||||
if ($PTRId) { $_body.add("PTR", $PTRId)}
|
||||
if ($Note) { $_body.Add("note", $Note) }
|
||||
if ($ExcludePing) { $_body.Add("excludePing", [int]$ExcludePing) }
|
||||
if ($ExcludePing) { $_body.Add("excludePing", $ExcludePing) }
|
||||
if ($DeviceId) { $_body.Add("deviceId", $DeviceId) }
|
||||
if ($Port) { $_body.Add("port", $Port) }
|
||||
|
||||
@@ -165,7 +103,7 @@ function Set-Address {
|
||||
Invoke-Request @_params
|
||||
}
|
||||
finally {
|
||||
Get-Address -Id $Id
|
||||
Get-Address -Id $_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user