NetboxPS/Functions/IPAM/Range/New-NetboxIPAMAddressRange.ps1

107 lines
2.5 KiB
PowerShell
Raw Normal View History

2023-11-07 09:57:42 -05:00

2023-11-07 09:37:47 -05:00
function New-NetboxIPAMAddressRange {
<#
.SYNOPSIS
Create a new IP address range to Netbox
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.DESCRIPTION
2023-11-07 09:57:42 -05:00
Create a new IP address range to Netbox with a status of Active by default. The maximum supported
2023-11-07 09:37:47 -05:00
size of an IP range is 2^32 - 1.
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Start_Address
Starting IPv4 or IPv6 address (with mask). The maximum supported size of an IP range is 2^32 - 1.
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER End_Address
Ending IPv4 or IPv6 address (with mask). The maximum supported size of an IP range is 2^32 - 1.
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Status
Operational status of this range. Defaults to Active
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Tenant
Tenant ID
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER VRF
VRF ID
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Role
Role such as backup, customer, development, etc... Defaults to nothing
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Description
Description of IP address range
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Comments
Extra comments (markdown supported).
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Tags
One or more tags.
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Mark_Utilized
Treat as 100% utilized
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.PARAMETER Raw
Return raw results from API service
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.EXAMPLE
New-NetboxIPAMAddressRange -Start_Address 192.0.2.20/24 -End_Address 192.0.2.20/24
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
Add new IP Address range from 192.0.2.20/24 to 192.0.2.20/24 with status active
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
.NOTES
https://netbox.neonet.org/static/docs/models/ipam/iprange/
#>
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Start_Address,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[Parameter(Mandatory = $true)]
[string]$End_Address,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[object]$Status = 'Active',
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[uint64]$Tenant,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[uint64]$VRF,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[object]$Role,
2023-11-07 10:19:03 -05:00
2023-11-07 09:37:47 -05:00
[hashtable]$Custom_Fields,
2023-11-07 10:19:03 -05:00
2023-11-07 09:37:47 -05:00
[string]$Description,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[string]$Comments,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[object[]]$Tags,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[switch]$Mark_Utilized,
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
[switch]$Raw
)
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
process {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-ranges'))
$Method = 'POST'
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2023-11-07 09:57:42 -05:00
2023-11-07 09:37:47 -05:00
if ($PSCmdlet.ShouldProcess($Start_Address, 'Create new IP address range')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}