mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-13 18:02:29 +00:00
Updates
This commit is contained in:
parent
4e0b18d601
commit
34849685c1
6 changed files with 763 additions and 45 deletions
|
|
@ -113,6 +113,10 @@ function VerifyIPAMChoices {
|
||||||
|
|
||||||
$ValidValues = New-Object System.Collections.ArrayList
|
$ValidValues = New-Object System.Collections.ArrayList
|
||||||
|
|
||||||
|
if (-not $script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName)) {
|
||||||
|
throw "Missing choices for $($PSCmdlet.ParameterSetName)"
|
||||||
|
}
|
||||||
|
|
||||||
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).value)
|
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).value)
|
||||||
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).label)
|
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).label)
|
||||||
|
|
||||||
|
|
@ -274,7 +278,7 @@ function Get-NetboxIPAMAddress {
|
||||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-NetboxIPAMAvaiableIP {
|
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
|
||||||
|
|
@ -289,6 +293,9 @@ function Get-NetboxIPAMAvaiableIP {
|
||||||
.PARAMETER NumberOfIPs
|
.PARAMETER NumberOfIPs
|
||||||
A description of the NumberOfIPs parameter.
|
A description of the NumberOfIPs parameter.
|
||||||
|
|
||||||
|
.PARAMETER Raw
|
||||||
|
A description of the Raw parameter.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
|
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
|
||||||
|
|
||||||
|
|
@ -302,6 +309,7 @@ function Get-NetboxIPAMAvaiableIP {
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[uint16]$Prefix_ID,
|
[uint16]$Prefix_ID,
|
||||||
|
|
||||||
|
[Alias('Limit')]
|
||||||
[uint16]$NumberOfIPs,
|
[uint16]$NumberOfIPs,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
|
|
@ -321,6 +329,86 @@ function Get-NetboxIPAMAvaiableIP {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-NetboxIPAMPrefix {
|
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()]
|
[CmdletBinding()]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
|
|
@ -330,16 +418,19 @@ function Get-NetboxIPAMPrefix {
|
||||||
|
|
||||||
[object]$Family,
|
[object]$Family,
|
||||||
|
|
||||||
|
[boolean]$Is_Pool,
|
||||||
|
|
||||||
[uint16[]]$Id,
|
[uint16[]]$Id,
|
||||||
|
|
||||||
[string]$Query,
|
[string]$Query,
|
||||||
|
|
||||||
#[string]$Within,
|
[string]$Within,
|
||||||
|
|
||||||
#[string]$Within_Include,
|
[string]$Within_Include,
|
||||||
|
|
||||||
[string]$Contains,
|
[string]$Contains,
|
||||||
|
|
||||||
|
[ValidateRange(0, 127)]
|
||||||
[byte]$Mask_Length,
|
[byte]$Mask_Length,
|
||||||
|
|
||||||
[string]$VRF,
|
[string]$VRF,
|
||||||
|
|
@ -377,7 +468,8 @@ function Get-NetboxIPAMPrefix {
|
||||||
|
|
||||||
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
||||||
|
|
||||||
$URIParameters = @{}
|
$URIParameters = @{
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
||||||
if ($CmdletParameterName -in $CommonParameterNames) {
|
if ($CmdletParameterName -in $CommonParameterNames) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
.NOTES
|
.NOTES
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
|
Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
|
||||||
Generated on: 5/11/2018 3:48 PM
|
Generated on: 5/11/2018 4:30 PM
|
||||||
Generated by: Ben Claussen
|
Generated by: Ben Claussen
|
||||||
Organization: NEOnet
|
Organization: NEOnet
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -13,16 +13,16 @@
|
||||||
|
|
||||||
#region Invoke-Helpers_ps1
|
#region Invoke-Helpers_ps1
|
||||||
<#
|
<#
|
||||||
.NOTES
|
.NOTES
|
||||||
===========================================================================
|
===========================================================================
|
||||||
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
|
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
|
||||||
Created on: 2/28/2018 3:33 PM
|
Created on: 2/28/2018 3:33 PM
|
||||||
Created by: Ben Claussen
|
Created by: Ben Claussen
|
||||||
Organization: NEOnet
|
Organization: NEOnet
|
||||||
Filename: Helpers.ps1
|
Filename: Helpers.ps1
|
||||||
===========================================================================
|
===========================================================================
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
These function are internal functions and generally are not
|
These function are internal functions and generally are not
|
||||||
exposed to the end user
|
exposed to the end user
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
|
@ -885,8 +885,7 @@
|
||||||
|
|
||||||
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
|
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
|
||||||
|
|
||||||
$URIParameters = @{
|
$URIParameters = @{}
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
||||||
if ($CmdletParameterName -in $CommonParameterNames) {
|
if ($CmdletParameterName -in $CommonParameterNames) {
|
||||||
|
|
@ -1284,6 +1283,10 @@
|
||||||
|
|
||||||
$ValidValues = New-Object System.Collections.ArrayList
|
$ValidValues = New-Object System.Collections.ArrayList
|
||||||
|
|
||||||
|
if (-not $script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName)) {
|
||||||
|
throw "Missing choices for $($PSCmdlet.ParameterSetName)"
|
||||||
|
}
|
||||||
|
|
||||||
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).value)
|
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).value)
|
||||||
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).label)
|
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).label)
|
||||||
|
|
||||||
|
|
@ -1445,7 +1448,7 @@
|
||||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-NetboxIPAMAvaiableIP {
|
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
|
||||||
|
|
@ -1460,6 +1463,9 @@
|
||||||
.PARAMETER NumberOfIPs
|
.PARAMETER NumberOfIPs
|
||||||
A description of the NumberOfIPs parameter.
|
A description of the NumberOfIPs parameter.
|
||||||
|
|
||||||
|
.PARAMETER Raw
|
||||||
|
A description of the Raw parameter.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
|
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
|
||||||
|
|
||||||
|
|
@ -1473,6 +1479,7 @@
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[uint16]$Prefix_ID,
|
[uint16]$Prefix_ID,
|
||||||
|
|
||||||
|
[Alias('Limit')]
|
||||||
[uint16]$NumberOfIPs,
|
[uint16]$NumberOfIPs,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
|
|
@ -1492,6 +1499,86 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-NetboxIPAMPrefix {
|
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()]
|
[CmdletBinding()]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
|
|
@ -1501,16 +1588,19 @@
|
||||||
|
|
||||||
[object]$Family,
|
[object]$Family,
|
||||||
|
|
||||||
|
[boolean]$Is_Pool,
|
||||||
|
|
||||||
[uint16[]]$Id,
|
[uint16[]]$Id,
|
||||||
|
|
||||||
[string]$Query,
|
[string]$Query,
|
||||||
|
|
||||||
#[string]$Within,
|
[string]$Within,
|
||||||
|
|
||||||
#[string]$Within_Include,
|
[string]$Within_Include,
|
||||||
|
|
||||||
[string]$Contains,
|
[string]$Contains,
|
||||||
|
|
||||||
|
[ValidateRange(0, 127)]
|
||||||
[byte]$Mask_Length,
|
[byte]$Mask_Length,
|
||||||
|
|
||||||
[string]$VRF,
|
[string]$VRF,
|
||||||
|
|
@ -1548,7 +1638,8 @@
|
||||||
|
|
||||||
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
||||||
|
|
||||||
$URIParameters = @{}
|
$URIParameters = @{
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
||||||
if ($CmdletParameterName -in $CommonParameterNames) {
|
if ($CmdletParameterName -in $CommonParameterNames) {
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with limit and offset" {
|
It "Should request with limit and offset" {
|
||||||
|
|
@ -66,6 +67,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?offset=12&limit=10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?offset=12&limit=10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a query" {
|
It "Should request with a query" {
|
||||||
|
|
@ -76,6 +78,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=10.10.0.0'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=10.10.0.0'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with an escaped query" {
|
It "Should request with an escaped query" {
|
||||||
|
|
@ -86,6 +89,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=my+aggregate'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=my+aggregate'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a single ID" {
|
It "Should request with a single ID" {
|
||||||
|
|
@ -96,6 +100,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/10/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/10/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with multiple IDs" {
|
It "Should request with multiple IDs" {
|
||||||
|
|
@ -106,6 +111,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?id__in=10,12,15'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?id__in=10,12,15'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +124,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with limit and offset" {
|
It "Should request with limit and offset" {
|
||||||
|
|
@ -128,6 +135,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?offset=12&limit=10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?offset=12&limit=10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a query" {
|
It "Should request with a query" {
|
||||||
|
|
@ -138,6 +146,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=10.10.10.10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=10.10.10.10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with an escaped query" {
|
It "Should request with an escaped query" {
|
||||||
|
|
@ -148,6 +157,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=my+ip+address'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=my+ip+address'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a single ID" {
|
It "Should request with a single ID" {
|
||||||
|
|
@ -158,6 +168,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/10/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/10/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with multiple IDs" {
|
It "Should request with multiple IDs" {
|
||||||
|
|
@ -168,6 +179,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?id__in=10,12,15'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?id__in=10,12,15'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
#region TODO: Figure out how to mock/test Verification appropriately...
|
#region TODO: Figure out how to mock/test Verification appropriately...
|
||||||
|
|
@ -197,8 +209,140 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
Context -Name "Get-NetboxIPAMPrefix" {
|
Context -Name "Get-NetboxIPAMAvailableIP" -Fixture {
|
||||||
|
It "Should request the default number of available IPs" {
|
||||||
|
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/available-ips/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request 10 available IPs" {
|
||||||
|
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 1504 -NumberOfIPs 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/1504/available-ips/?limit=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context -Name "Get-NetboxIPAMPrefix" {
|
||||||
|
It "Should request the default number of prefixes" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with limit and offset" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Limit 10 -Offset 12
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?offset=12&limit=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with a query" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Query '10.10.10.10'
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=10.10.10.10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with an escaped query" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Query 'my ip address'
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=my+ip+address'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with a single ID" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Id 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with multiple IDs" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Id 10, 12, 15
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?id__in=10,12,15'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with VLAN vID" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -VLAN_VID 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?vlan_vid=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
It "Should request with family of 4" {
|
||||||
|
Mock -CommandName "VerifyIPAMChoices" -ModuleName 'NetboxPS' -MockWith {
|
||||||
|
return 4
|
||||||
|
} -Verifiable
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Family 4
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?family=4'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
|
||||||
|
It "Should request with mask length 24" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Mask_length 24
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?mask_length=24'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should throw because the mask length is too large" {
|
||||||
|
{
|
||||||
|
Get-NetboxIPAMPrefix -Mask_length 128
|
||||||
|
} | Should -Throw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with limit and offset" {
|
It "Should request with limit and offset" {
|
||||||
|
|
@ -66,6 +67,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?offset=12&limit=10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?offset=12&limit=10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a query" {
|
It "Should request with a query" {
|
||||||
|
|
@ -76,6 +78,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=10.10.0.0'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=10.10.0.0'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with an escaped query" {
|
It "Should request with an escaped query" {
|
||||||
|
|
@ -86,6 +89,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=my+aggregate'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=my+aggregate'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a single ID" {
|
It "Should request with a single ID" {
|
||||||
|
|
@ -96,6 +100,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/10/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/10/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with multiple IDs" {
|
It "Should request with multiple IDs" {
|
||||||
|
|
@ -106,6 +111,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?id__in=10,12,15'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?id__in=10,12,15'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +124,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with limit and offset" {
|
It "Should request with limit and offset" {
|
||||||
|
|
@ -128,6 +135,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?offset=12&limit=10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?offset=12&limit=10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a query" {
|
It "Should request with a query" {
|
||||||
|
|
@ -138,6 +146,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=10.10.10.10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=10.10.10.10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with an escaped query" {
|
It "Should request with an escaped query" {
|
||||||
|
|
@ -148,6 +157,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=my+ip+address'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=my+ip+address'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a single ID" {
|
It "Should request with a single ID" {
|
||||||
|
|
@ -158,6 +168,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/10/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/10/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with multiple IDs" {
|
It "Should request with multiple IDs" {
|
||||||
|
|
@ -168,6 +179,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?id__in=10,12,15'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?id__in=10,12,15'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
#region TODO: Figure out how to mock/test Verification appropriately...
|
#region TODO: Figure out how to mock/test Verification appropriately...
|
||||||
|
|
@ -197,8 +209,152 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
Context -Name "Get-NetboxIPAMPrefix" {
|
Context -Name "Get-NetboxIPAMAvailableIP" -Fixture {
|
||||||
|
It "Should request the default number of available IPs" {
|
||||||
|
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/available-ips/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request 10 available IPs" {
|
||||||
|
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 1504 -NumberOfIPs 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/1504/available-ips/?limit=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context -Name "Get-NetboxIPAMPrefix" {
|
||||||
|
It "Should request the default number of prefixes" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with limit and offset" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Limit 10 -Offset 12
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?offset=12&limit=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with a query" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Query '10.10.10.10'
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=10.10.10.10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with an escaped query" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Query 'my ip address'
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=my+ip+address'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with a single ID" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Id 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with multiple IDs" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Id 10, 12, 15
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?id__in=10,12,15'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with VLAN vID" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -VLAN_VID 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?vlan_vid=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
It "Should request with family of 4" {
|
||||||
|
Mock -CommandName "VerifyIPAMChoices" -ModuleName 'NetboxPS' -MockWith {
|
||||||
|
return 4
|
||||||
|
} -Verifiable
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Family 4
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?family=4'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
|
||||||
|
It "Should throw because the mask length is too large" {
|
||||||
|
{
|
||||||
|
Get-NetboxIPAMPrefix -Mask_length 128
|
||||||
|
} | Should -Throw
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should throw because the mask length is too small" {
|
||||||
|
{
|
||||||
|
Get-NetboxIPAMPrefix -Mask_length -1
|
||||||
|
} | Should -Throw
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should not throw because the mask length is just right" {
|
||||||
|
{
|
||||||
|
Get-NetboxIPAMPrefix -Mask_length 24
|
||||||
|
} | Should -Not -Throw
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with mask length 24" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Mask_length 24
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?mask_length=24'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
127
dist/NetboxPS.psm1
vendored
127
dist/NetboxPS.psm1
vendored
|
|
@ -2,7 +2,7 @@
|
||||||
.NOTES
|
.NOTES
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
|
Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
|
||||||
Generated on: 5/11/2018 3:48 PM
|
Generated on: 5/11/2018 4:30 PM
|
||||||
Generated by: Ben Claussen
|
Generated by: Ben Claussen
|
||||||
Organization: NEOnet
|
Organization: NEOnet
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -13,16 +13,16 @@
|
||||||
|
|
||||||
#region Invoke-Helpers_ps1
|
#region Invoke-Helpers_ps1
|
||||||
<#
|
<#
|
||||||
.NOTES
|
.NOTES
|
||||||
===========================================================================
|
===========================================================================
|
||||||
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
|
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
|
||||||
Created on: 2/28/2018 3:33 PM
|
Created on: 2/28/2018 3:33 PM
|
||||||
Created by: Ben Claussen
|
Created by: Ben Claussen
|
||||||
Organization: NEOnet
|
Organization: NEOnet
|
||||||
Filename: Helpers.ps1
|
Filename: Helpers.ps1
|
||||||
===========================================================================
|
===========================================================================
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
These function are internal functions and generally are not
|
These function are internal functions and generally are not
|
||||||
exposed to the end user
|
exposed to the end user
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
|
@ -885,8 +885,7 @@
|
||||||
|
|
||||||
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
|
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
|
||||||
|
|
||||||
$URIParameters = @{
|
$URIParameters = @{}
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
||||||
if ($CmdletParameterName -in $CommonParameterNames) {
|
if ($CmdletParameterName -in $CommonParameterNames) {
|
||||||
|
|
@ -1284,6 +1283,10 @@
|
||||||
|
|
||||||
$ValidValues = New-Object System.Collections.ArrayList
|
$ValidValues = New-Object System.Collections.ArrayList
|
||||||
|
|
||||||
|
if (-not $script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName)) {
|
||||||
|
throw "Missing choices for $($PSCmdlet.ParameterSetName)"
|
||||||
|
}
|
||||||
|
|
||||||
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).value)
|
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).value)
|
||||||
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).label)
|
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.IPAM.$($PSCmdlet.ParameterSetName).label)
|
||||||
|
|
||||||
|
|
@ -1445,7 +1448,7 @@
|
||||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-NetboxIPAMAvaiableIP {
|
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
|
||||||
|
|
@ -1460,6 +1463,9 @@
|
||||||
.PARAMETER NumberOfIPs
|
.PARAMETER NumberOfIPs
|
||||||
A description of the NumberOfIPs parameter.
|
A description of the NumberOfIPs parameter.
|
||||||
|
|
||||||
|
.PARAMETER Raw
|
||||||
|
A description of the Raw parameter.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
|
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
|
||||||
|
|
||||||
|
|
@ -1473,6 +1479,7 @@
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[uint16]$Prefix_ID,
|
[uint16]$Prefix_ID,
|
||||||
|
|
||||||
|
[Alias('Limit')]
|
||||||
[uint16]$NumberOfIPs,
|
[uint16]$NumberOfIPs,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
|
|
@ -1492,6 +1499,86 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-NetboxIPAMPrefix {
|
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()]
|
[CmdletBinding()]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
|
|
@ -1501,16 +1588,19 @@
|
||||||
|
|
||||||
[object]$Family,
|
[object]$Family,
|
||||||
|
|
||||||
|
[boolean]$Is_Pool,
|
||||||
|
|
||||||
[uint16[]]$Id,
|
[uint16[]]$Id,
|
||||||
|
|
||||||
[string]$Query,
|
[string]$Query,
|
||||||
|
|
||||||
#[string]$Within,
|
[string]$Within,
|
||||||
|
|
||||||
#[string]$Within_Include,
|
[string]$Within_Include,
|
||||||
|
|
||||||
[string]$Contains,
|
[string]$Contains,
|
||||||
|
|
||||||
|
[ValidateRange(0, 127)]
|
||||||
[byte]$Mask_Length,
|
[byte]$Mask_Length,
|
||||||
|
|
||||||
[string]$VRF,
|
[string]$VRF,
|
||||||
|
|
@ -1548,7 +1638,8 @@
|
||||||
|
|
||||||
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
||||||
|
|
||||||
$URIParameters = @{}
|
$URIParameters = @{
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
|
||||||
if ($CmdletParameterName -in $CommonParameterNames) {
|
if ($CmdletParameterName -in $CommonParameterNames) {
|
||||||
|
|
|
||||||
146
dist/Tests/IPAM.Tests.ps1
vendored
146
dist/Tests/IPAM.Tests.ps1
vendored
|
|
@ -56,6 +56,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with limit and offset" {
|
It "Should request with limit and offset" {
|
||||||
|
|
@ -66,6 +67,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?offset=12&limit=10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?offset=12&limit=10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a query" {
|
It "Should request with a query" {
|
||||||
|
|
@ -76,6 +78,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=10.10.0.0'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=10.10.0.0'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with an escaped query" {
|
It "Should request with an escaped query" {
|
||||||
|
|
@ -86,6 +89,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=my+aggregate'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?q=my+aggregate'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a single ID" {
|
It "Should request with a single ID" {
|
||||||
|
|
@ -96,6 +100,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/10/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/10/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with multiple IDs" {
|
It "Should request with multiple IDs" {
|
||||||
|
|
@ -106,6 +111,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?id__in=10,12,15'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/aggregates/?id__in=10,12,15'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +124,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with limit and offset" {
|
It "Should request with limit and offset" {
|
||||||
|
|
@ -128,6 +135,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?offset=12&limit=10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?offset=12&limit=10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a query" {
|
It "Should request with a query" {
|
||||||
|
|
@ -138,6 +146,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=10.10.10.10'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=10.10.10.10'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with an escaped query" {
|
It "Should request with an escaped query" {
|
||||||
|
|
@ -148,6 +157,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=my+ip+address'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?q=my+ip+address'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with a single ID" {
|
It "Should request with a single ID" {
|
||||||
|
|
@ -158,6 +168,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/10/'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/10/'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should request with multiple IDs" {
|
It "Should request with multiple IDs" {
|
||||||
|
|
@ -168,6 +179,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
$Result.Method | Should -Be 'GET'
|
$Result.Method | Should -Be 'GET'
|
||||||
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?id__in=10,12,15'
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?id__in=10,12,15'
|
||||||
$Result.Headers.Keys.Count | Should -BeExactly 1
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
}
|
}
|
||||||
|
|
||||||
#region TODO: Figure out how to mock/test Verification appropriately...
|
#region TODO: Figure out how to mock/test Verification appropriately...
|
||||||
|
|
@ -197,8 +209,140 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
Context -Name "Get-NetboxIPAMPrefix" {
|
Context -Name "Get-NetboxIPAMAvailableIP" -Fixture {
|
||||||
|
It "Should request the default number of available IPs" {
|
||||||
|
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/available-ips/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request 10 available IPs" {
|
||||||
|
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 1504 -NumberOfIPs 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/1504/available-ips/?limit=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context -Name "Get-NetboxIPAMPrefix" {
|
||||||
|
It "Should request the default number of prefixes" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with limit and offset" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Limit 10 -Offset 12
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?offset=12&limit=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with a query" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Query '10.10.10.10'
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=10.10.10.10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with an escaped query" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Query 'my ip address'
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=my+ip+address'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with a single ID" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Id 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with multiple IDs" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Id 10, 12, 15
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?id__in=10,12,15'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should request with VLAN vID" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -VLAN_VID 10
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?vlan_vid=10'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
It "Should request with family of 4" {
|
||||||
|
Mock -CommandName "VerifyIPAMChoices" -ModuleName 'NetboxPS' -MockWith {
|
||||||
|
return 4
|
||||||
|
} -Verifiable
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Family 4
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?family=4'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
|
||||||
|
It "Should request with mask length 24" {
|
||||||
|
$Result = Get-NetboxIPAMPrefix -Mask_length 24
|
||||||
|
|
||||||
|
Assert-VerifiableMock
|
||||||
|
|
||||||
|
$Result.Method | Should -Be 'GET'
|
||||||
|
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?mask_length=24'
|
||||||
|
$Result.Headers.Keys.Count | Should -BeExactly 1
|
||||||
|
$Result.Headers.Authorization | Should -Be "Token faketoken"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should throw because the mask length is too large" {
|
||||||
|
{
|
||||||
|
Get-NetboxIPAMPrefix -Mask_length 128
|
||||||
|
} | Should -Throw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue