mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-13 18:02:29 +00:00
468 lines
12 KiB
PowerShell
468 lines
12 KiB
PowerShell
<#
|
|
.NOTES
|
|
===========================================================================
|
|
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
|
|
Created on: 5/10/2018 3:41 PM
|
|
Created by: Ben Claussen
|
|
Organization: NEOnet
|
|
Filename: IPAM.ps1
|
|
===========================================================================
|
|
.DESCRIPTION
|
|
IPAM Object functions
|
|
#>
|
|
|
|
function Get-NetboxIPAMChoices {
|
|
[CmdletBinding()]
|
|
param ()
|
|
|
|
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', '_choices'))
|
|
|
|
$uri = BuildNewURI -Segments $uriSegments -Parameters $Parameters
|
|
|
|
InvokeNetboxRequest -URI $uri
|
|
}
|
|
|
|
function VerifyIPAMChoices {
|
|
<#
|
|
.SYNOPSIS
|
|
Internal function to verify provided values for static choices
|
|
|
|
.DESCRIPTION
|
|
When users connect to the API, choices for each major object are cached to the config variable.
|
|
These values are then utilized to verify if the provided value from a user is valid.
|
|
|
|
.PARAMETER ProvidedValue
|
|
The value to validate against static choices
|
|
|
|
.PARAMETER AggregateFamily
|
|
Verify against aggregate family values
|
|
|
|
.PARAMETER PrefixFamily
|
|
Verify against prefix family values
|
|
|
|
.PARAMETER PrefixStatus
|
|
Verify against prefix status values
|
|
|
|
.PARAMETER IPAddressFamily
|
|
Verify against ip-address family values
|
|
|
|
.PARAMETER IPAddressStatus
|
|
Verify against ip-address status values
|
|
|
|
.PARAMETER IPAddressRole
|
|
Verify against ip-address role values
|
|
|
|
.PARAMETER VLANStatus
|
|
Verify against VLAN status values
|
|
|
|
.PARAMETER ServiceProtocol
|
|
Verify against service protocol values
|
|
|
|
.EXAMPLE
|
|
PS C:\> VerifyIPAMChoices -ProvidedValue 'loopback' -IPAddressRole
|
|
|
|
.EXAMPLE
|
|
PS C:\> VerifyIPAMChoices -ProvidedValue 'Loopback' -IPAddressFamily
|
|
>> Invalid value Loopback for ip-address:family. Must be one of: 4, 6, IPv4, IPv6
|
|
|
|
.OUTPUTS
|
|
This function returns the integer value if valid. Otherwise, it will throw an error.
|
|
|
|
.NOTES
|
|
Additional information about the function.
|
|
|
|
.FUNCTIONALITY
|
|
This cmdlet is intended to be used internally and not exposed to the user
|
|
#>
|
|
|
|
[CmdletBinding(DefaultParameterSetName = 'service:protocol')]
|
|
[OutputType([uint16])]
|
|
param
|
|
(
|
|
[Parameter(Mandatory = $true)]
|
|
[object]$ProvidedValue,
|
|
|
|
[Parameter(ParameterSetName = 'aggregate:family',
|
|
Mandatory = $true)]
|
|
[switch]$AggregateFamily,
|
|
|
|
[Parameter(ParameterSetName = 'prefix:family',
|
|
Mandatory = $true)]
|
|
[switch]$PrefixFamily,
|
|
|
|
[Parameter(ParameterSetName = 'prefix:status',
|
|
Mandatory = $true)]
|
|
[switch]$PrefixStatus,
|
|
|
|
[Parameter(ParameterSetName = 'ip-address:family',
|
|
Mandatory = $true)]
|
|
[switch]$IPAddressFamily,
|
|
|
|
[Parameter(ParameterSetName = 'ip-address:status',
|
|
Mandatory = $true)]
|
|
[switch]$IPAddressStatus,
|
|
|
|
[Parameter(ParameterSetName = 'ip-address:role',
|
|
Mandatory = $true)]
|
|
[switch]$IPAddressRole,
|
|
|
|
[Parameter(ParameterSetName = 'vlan:status',
|
|
Mandatory = $true)]
|
|
[switch]$VLANStatus,
|
|
|
|
[Parameter(ParameterSetName = 'service:protocol',
|
|
Mandatory = $true)]
|
|
[switch]$ServiceProtocol
|
|
)
|
|
|
|
ValidateChoice -MajorObject 'IPAM' -ChoiceName $PSCmdlet.ParameterSetName
|
|
}
|
|
|
|
|
|
function Get-NetboxIPAMAggregate {
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[uint16]$Limit,
|
|
|
|
[uint16]$Offset,
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
[object]$Family,
|
|
|
|
[datetime]$Date_Added,
|
|
|
|
[uint16[]]$Id,
|
|
|
|
[string]$Query,
|
|
|
|
[uint16]$RIR_Id,
|
|
|
|
[string]$RIR,
|
|
|
|
[switch]$Raw
|
|
)
|
|
|
|
if ($Family -ne $null) {
|
|
$PSBoundParameters.Family = VerifyIPAMChoices -ProvidedValue $Family -AggregateFamily
|
|
}
|
|
|
|
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
|
|
|
|
$URIComponents = BuildURIComponents -URISegments $uriSegments -ParametersDictionary $PSBoundParameters
|
|
|
|
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
|
|
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
|
}
|
|
|
|
function Get-NetboxIPAMAddress {
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[uint16]$Limit,
|
|
|
|
[uint16]$Offset,
|
|
|
|
[object]$Family,
|
|
|
|
[uint16[]]$Id,
|
|
|
|
[string]$Query,
|
|
|
|
[uint16]$Parent,
|
|
|
|
[byte]$Mask_Length,
|
|
|
|
[string]$VRF,
|
|
|
|
[uint16]$VRF_Id,
|
|
|
|
[string]$Tenant,
|
|
|
|
[uint16]$Tenant_Id,
|
|
|
|
[string]$Device,
|
|
|
|
[uint16]$Device_ID,
|
|
|
|
[string]$Virtual_Machine,
|
|
|
|
[uint16]$Virtual_Machine_Id,
|
|
|
|
[uint16]$Interface_Id,
|
|
|
|
[object]$Status,
|
|
|
|
[object]$Role,
|
|
|
|
[switch]$Raw
|
|
)
|
|
|
|
if ($Family -ne $null) {
|
|
$PSBoundParameters.Family = VerifyIPAMChoices -ProvidedValue $Family -IPAddressFamily
|
|
}
|
|
|
|
if ($Status -ne $null) {
|
|
$PSBoundParameters.Status = VerifyIPAMChoices -ProvidedValue $Status -IPAddressStatus
|
|
}
|
|
|
|
if ($Role -ne $null) {
|
|
$PSBoundParameters.Role = VerifyIPAMChoices -ProvidedValue $Role -IPAddressRole
|
|
}
|
|
|
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
|
|
|
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
|
|
|
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
|
|
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
|
}
|
|
|
|
function Get-NetboxIPAMAvailableIP {
|
|
<#
|
|
.SYNOPSIS
|
|
A convenience method for returning available IP addresses within a prefix
|
|
|
|
.DESCRIPTION
|
|
By default, the number of IPs returned will be equivalent to PAGINATE_COUNT. An arbitrary limit
|
|
(up to MAX_PAGE_SIZE, if set) may be passed, however results will not be paginated
|
|
|
|
.PARAMETER Prefix_ID
|
|
A description of the Prefix_ID parameter.
|
|
|
|
.PARAMETER NumberOfIPs
|
|
A description of the NumberOfIPs parameter.
|
|
|
|
.PARAMETER Raw
|
|
A description of the Raw parameter.
|
|
|
|
.EXAMPLE
|
|
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
|
|
|
|
.NOTES
|
|
Additional information about the function.
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[Parameter(Mandatory = $true)]
|
|
[uint16]$Prefix_ID,
|
|
|
|
[Alias('NumberOfIPs')]
|
|
[uint16]$Limit,
|
|
|
|
[switch]$Raw
|
|
)
|
|
|
|
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID, 'available-ips'))
|
|
|
|
$URIComponents = BuildURIComponents -URISegments $uriSegments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'prefix_id'
|
|
|
|
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
|
|
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
|
}
|
|
|
|
function Get-NetboxIPAMPrefix {
|
|
<#
|
|
.SYNOPSIS
|
|
A brief description of the Get-NetboxIPAMPrefix function.
|
|
|
|
.DESCRIPTION
|
|
A detailed description of the Get-NetboxIPAMPrefix function.
|
|
|
|
.PARAMETER Limit
|
|
A description of the Limit parameter.
|
|
|
|
.PARAMETER Offset
|
|
A description of the Offset parameter.
|
|
|
|
.PARAMETER Family
|
|
A description of the Family parameter.
|
|
|
|
.PARAMETER Is_Pool
|
|
A description of the Is_Pool parameter.
|
|
|
|
.PARAMETER Id
|
|
A description of the Id parameter.
|
|
|
|
.PARAMETER Query
|
|
A description of the Query parameter.
|
|
|
|
.PARAMETER Within
|
|
Should be a CIDR notation prefix such as '10.0.0.0/16'
|
|
|
|
.PARAMETER Within_Include
|
|
Should be a CIDR notation prefix such as '10.0.0.0/16'
|
|
|
|
.PARAMETER Contains
|
|
A description of the Contains parameter.
|
|
|
|
.PARAMETER Mask_Length
|
|
CIDR mask length value
|
|
|
|
.PARAMETER VRF
|
|
A description of the VRF parameter.
|
|
|
|
.PARAMETER VRF_Id
|
|
A description of the VRF_Id parameter.
|
|
|
|
.PARAMETER Tenant
|
|
A description of the Tenant parameter.
|
|
|
|
.PARAMETER Tenant_Id
|
|
A description of the Tenant_Id parameter.
|
|
|
|
.PARAMETER Site
|
|
A description of the Site parameter.
|
|
|
|
.PARAMETER Site_Id
|
|
A description of the Site_Id parameter.
|
|
|
|
.PARAMETER Vlan_VId
|
|
A description of the Vlan_VId parameter.
|
|
|
|
.PARAMETER Vlan_Id
|
|
A description of the Vlan_Id parameter.
|
|
|
|
.PARAMETER Status
|
|
A description of the Status parameter.
|
|
|
|
.PARAMETER Role
|
|
A description of the Role parameter.
|
|
|
|
.PARAMETER Role_Id
|
|
A description of the Role_Id parameter.
|
|
|
|
.PARAMETER Raw
|
|
A description of the Raw parameter.
|
|
|
|
.EXAMPLE
|
|
PS C:\> Get-NetboxIPAMPrefix
|
|
|
|
.NOTES
|
|
Additional information about the function.
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[uint16]$Limit,
|
|
|
|
[uint16]$Offset,
|
|
|
|
[object]$Family,
|
|
|
|
[boolean]$Is_Pool,
|
|
|
|
[uint16[]]$Id,
|
|
|
|
[string]$Query,
|
|
|
|
[string]$Within,
|
|
|
|
[string]$Within_Include,
|
|
|
|
[string]$Contains,
|
|
|
|
[ValidateRange(0, 127)]
|
|
[byte]$Mask_Length,
|
|
|
|
[string]$VRF,
|
|
|
|
[uint16]$VRF_Id,
|
|
|
|
[string]$Tenant,
|
|
|
|
[uint16]$Tenant_Id,
|
|
|
|
[string]$Site,
|
|
|
|
[uint16]$Site_Id,
|
|
|
|
[string]$Vlan_VId,
|
|
|
|
[uint16]$Vlan_Id,
|
|
|
|
[object]$Status,
|
|
|
|
[string]$Role,
|
|
|
|
[uint16]$Role_Id,
|
|
|
|
[switch]$Raw
|
|
)
|
|
|
|
if ($Family -ne $null) {
|
|
$PSBoundParameters.Family = VerifyIPAMChoices -ProvidedValue $Family -PrefixFamily
|
|
}
|
|
|
|
if ($Status -ne $null) {
|
|
$PSBoundParameters.Status = VerifyIPAMChoices -ProvidedValue $Status -PrefixStatus
|
|
}
|
|
|
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
|
|
|
$URIComponents = BuildURIComponents -ParametersDictionary $PSBoundParameters -URISegments $Segments
|
|
|
|
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
|
|
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
|
}
|
|
|
|
function Add-NetboxIPAMAddress {
|
|
[CmdletBinding(DefaultParameterSetName = 'CIDR')]
|
|
[OutputType([pscustomobject])]
|
|
param
|
|
(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Address,
|
|
|
|
[object]$Status = 'Active',
|
|
|
|
[uint16]$Tenant,
|
|
|
|
[uint16]$VRF,
|
|
|
|
[object]$Role,
|
|
|
|
[uint16]$NAT_Inside,
|
|
|
|
[hashtable]$Custom_Fields,
|
|
|
|
[uint16]$Interface,
|
|
|
|
[string]$Description,
|
|
|
|
[switch]$Raw
|
|
)
|
|
|
|
$segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
|
|
|
|
$PSBoundParameters.Status = VerifyIPAMChoices -ProvidedValue $Status -IPAddressStatus
|
|
|
|
if ($Role) {
|
|
$PSBoundParameters.Role = VerifyIPAMChoices -ProvidedValue $Role -IPAddressRole
|
|
}
|
|
|
|
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
|
|
|
|
$URI = BuildNewURI -Segments $URIComponents.Segments
|
|
|
|
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|