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