mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-15 18:55:46 +00:00
(WIP) Enhance IPAM Address (#4)
* Address(IPAM): Fix trailing whitespace (with Visual Code Formater) * Address(IPAM): Fix PSSA about Command accepts pipeline input but not defined a process block * Address(IPAM): Add dns_name parameter to Add and Set * Address(IPAM): all integer are [int] (not uint16)
This commit is contained in:
parent
cfb53cf933
commit
2595c58eaa
5 changed files with 164 additions and 152 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
[Parameter(ParameterSetName = 'Query',
|
[Parameter(ParameterSetName = 'Query',
|
||||||
Position = 0)]
|
Position = 0)]
|
||||||
[string]$Address,
|
[string]$Address,
|
||||||
|
|
||||||
[Parameter(ParameterSetName = 'ByID')]
|
[Parameter(ParameterSetName = 'ByID')]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
|
|
||||||
function Get-NetboxIPAMAvailableIP {
|
function Get-NetboxIPAMAvailableIP {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
A convenience method for returning available IP addresses within a prefix
|
A convenience method for returning available IP addresses within a prefix
|
||||||
|
|
||||||
|
|
@ -44,21 +44,23 @@ function Get-NetboxIPAMAvailableIP {
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $true,
|
[Parameter(Mandatory = $true,
|
||||||
ValueFromPipelineByPropertyName = $true)]
|
ValueFromPipelineByPropertyName = $true)]
|
||||||
[Alias('Id')]
|
[Alias('Id')]
|
||||||
[uint16]$Prefix_ID,
|
[int]$Prefix_ID,
|
||||||
|
|
||||||
[Alias('NumberOfIPs')]
|
[Alias('NumberOfIPs')]
|
||||||
[uint16]$Limit,
|
[int]$Limit,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
)
|
)
|
||||||
|
|
||||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID, 'available-ips'))
|
process {
|
||||||
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID, 'available-ips'))
|
||||||
|
|
||||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'prefix_id'
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'prefix_id'
|
||||||
|
|
||||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||||
|
|
||||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
|
|
||||||
function New-NetboxIPAMAddress {
|
function New-NetboxIPAMAddress {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Create a new IP address to Netbox
|
Create a new IP address to Netbox
|
||||||
|
|
||||||
|
|
@ -47,6 +47,9 @@ function New-NetboxIPAMAddress {
|
||||||
.PARAMETER Description
|
.PARAMETER Description
|
||||||
Description of IP address
|
Description of IP address
|
||||||
|
|
||||||
|
.PARAMETER Dns_name
|
||||||
|
DNS Name of IP address (example : netbox.example.com)
|
||||||
|
|
||||||
.PARAMETER Force
|
.PARAMETER Force
|
||||||
Do not prompt for confirmation to create IP.
|
Do not prompt for confirmation to create IP.
|
||||||
|
|
||||||
|
|
@ -61,55 +64,59 @@ function New-NetboxIPAMAddress {
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(ConfirmImpact = 'Low',
|
[CmdletBinding(ConfirmImpact = 'Low',
|
||||||
SupportsShouldProcess = $true)]
|
SupportsShouldProcess = $true)]
|
||||||
[OutputType([pscustomobject])]
|
[OutputType([pscustomobject])]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $true,
|
[Parameter(Mandatory = $true,
|
||||||
ValueFromPipelineByPropertyName = $true)]
|
ValueFromPipelineByPropertyName = $true)]
|
||||||
[string]$Address,
|
[string]$Address,
|
||||||
|
|
||||||
[object]$Status = 'Active',
|
[object]$Status = 'Active',
|
||||||
|
|
||||||
[uint16]$Tenant,
|
[int]$Tenant,
|
||||||
|
|
||||||
[uint16]$VRF,
|
[int]$VRF,
|
||||||
|
|
||||||
[object]$Role,
|
[object]$Role,
|
||||||
|
|
||||||
[uint16]$NAT_Inside,
|
[int]$NAT_Inside,
|
||||||
|
|
||||||
[hashtable]$Custom_Fields,
|
[hashtable]$Custom_Fields,
|
||||||
|
|
||||||
[uint16]$Interface,
|
[int]$Interface,
|
||||||
|
|
||||||
[string]$Description,
|
[string]$Description,
|
||||||
|
|
||||||
|
[string]$Dns_name,
|
||||||
|
|
||||||
[switch]$Force,
|
[switch]$Force,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
)
|
)
|
||||||
|
|
||||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
|
process {
|
||||||
$Method = 'POST'
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
|
||||||
|
$Method = 'POST'
|
||||||
|
|
||||||
# # Value validation
|
# # Value validation
|
||||||
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
|
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
|
||||||
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
|
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
|
||||||
#
|
#
|
||||||
# foreach ($Property in $EnumProperties.Keys) {
|
# foreach ($Property in $EnumProperties.Keys) {
|
||||||
# if ($PSBoundParameters.ContainsKey($Property)) {
|
# if ($PSBoundParameters.ContainsKey($Property)) {
|
||||||
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
|
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
|
||||||
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
|
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
|
||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||||
|
|
||||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||||
|
|
||||||
if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
|
if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
|
||||||
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
|
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function Remove-NetboxIPAMAddress {
|
function Remove-NetboxIPAMAddress {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Remove an IP address from Netbox
|
Remove an IP address from Netbox
|
||||||
|
|
||||||
|
|
@ -33,12 +33,12 @@ function Remove-NetboxIPAMAddress {
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(ConfirmImpact = 'High',
|
[CmdletBinding(ConfirmImpact = 'High',
|
||||||
SupportsShouldProcess = $true)]
|
SupportsShouldProcess = $true)]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $true,
|
[Parameter(Mandatory = $true,
|
||||||
ValueFromPipelineByPropertyName = $true)]
|
ValueFromPipelineByPropertyName = $true)]
|
||||||
[uint16[]]$Id,
|
[int[]]$Id,
|
||||||
|
|
||||||
[switch]$Force
|
[switch]$Force
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -14,24 +14,24 @@
|
||||||
|
|
||||||
function Set-NetboxIPAMAddress {
|
function Set-NetboxIPAMAddress {
|
||||||
[CmdletBinding(ConfirmImpact = 'Medium',
|
[CmdletBinding(ConfirmImpact = 'Medium',
|
||||||
SupportsShouldProcess = $true)]
|
SupportsShouldProcess = $true)]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $true,
|
[Parameter(Mandatory = $true,
|
||||||
ValueFromPipelineByPropertyName = $true)]
|
ValueFromPipelineByPropertyName = $true)]
|
||||||
[uint16[]]$Id,
|
[int[]]$Id,
|
||||||
|
|
||||||
[string]$Address,
|
[string]$Address,
|
||||||
|
|
||||||
[string]$Status,
|
[string]$Status,
|
||||||
|
|
||||||
[uint16]$Tenant,
|
[int]$Tenant,
|
||||||
|
|
||||||
[uint16]$VRF,
|
[int]$VRF,
|
||||||
|
|
||||||
[object]$Role,
|
[object]$Role,
|
||||||
|
|
||||||
[uint16]$NAT_Inside,
|
[int]$NAT_Inside,
|
||||||
|
|
||||||
[hashtable]$Custom_Fields,
|
[hashtable]$Custom_Fields,
|
||||||
|
|
||||||
|
|
@ -42,6 +42,8 @@ function Set-NetboxIPAMAddress {
|
||||||
|
|
||||||
[string]$Description,
|
[string]$Description,
|
||||||
|
|
||||||
|
[string]$Dns_name,
|
||||||
|
|
||||||
[switch]$Force
|
[switch]$Force
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -71,7 +73,8 @@ function Set-NetboxIPAMAddress {
|
||||||
if ($PSBoundParameters.ContainsKey('Assigned_Object_Type') -or $PSBoundParameters.ContainsKey('Assigned_Object_Id')) {
|
if ($PSBoundParameters.ContainsKey('Assigned_Object_Type') -or $PSBoundParameters.ContainsKey('Assigned_Object_Id')) {
|
||||||
if ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) {
|
if ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) {
|
||||||
throw "Assigned_Object_Type is required when specifying Assigned_Object_Id"
|
throw "Assigned_Object_Type is required when specifying Assigned_Object_Id"
|
||||||
} elseif ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) {
|
}
|
||||||
|
elseif ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) {
|
||||||
throw "Assigned_Object_Id is required when specifying Assigned_Object_Type"
|
throw "Assigned_Object_Id is required when specifying Assigned_Object_Type"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue