* Connect(Setup): Fix indent (using Visual code Formatter)

* Setup(Functions): Fix indent (using Visual Code Formatter)

* Support(Setup): Fix indent (using Visual Code Formatter)

* InvokeNetboxRequest(Helpers): Fix indent (using Visual Code Formatter)

* Add Set-netboxCipherSSL for enable TLS1.1 and TLS1.2 (for PS 5.0)

From PowerAruba/FortiPower Module :)

* Add Set-NetboxUnstrustedSSL for disable SSL chain test (for PS 5.0

From PowerAruba/FortiPwoer Module :)

* Add Get/Set netboxInvokeParms for Get and Set Invoke Params (array)

Like -SkipCertificate, Timeout...

* InvokeNetboxRequest: Add to Splat NetboxInvokeParams

* Connect: Add SkipCertificateCheck parameter (for PS5 and Core)

Also enable TLS 1.1 and 1.2 for PS5

* PSSA: Add Github Actions for launch PSSA (PowerShell Script Analyzer) when launch PR (#11)

Add also vscode/PSScriptAnalyzerSettings.psd1 for Settings for PSSA (can be reuse also for vscode...)

* Update psproj

* Correct typo

* Correct brace formatting

* Add Get/Set timeout functions

* Add Get/Set timeout functions

* Add TimeoutSeconds parameter and logic to Connect-NetboxAPI
- Updated `InvokeNetboxRequest` to use `NetboxConfig.Timeout`
- Updated `Get-NetboxAPIDefinition` to use `NetboxConfig.Timeout`

* Trim whitespaces

* Add Get-NetboxVersion function

* Remove API Definition caching and replace with Netbox version check

* Increment version to 1.4

* Fix Typo and Enhance AvailableIP Example (#18)

* AvailableIP(IPAM/Address): Fix typo

* AvailableIP(IAPM/Address): Enhance Example

* NetboxPS(.psm1): Fix typo (paramters => parameters

* Update deployment files

* Add Assigned Object (Type and ID) to New IPAM Address (#19)

* IPAMAddress(New): Remove tab (use 4 spaces)

* IPAMAddress(New): Remove not longer needed code about value validation

* IPAMAddress(New): Add Assigned Object Type and ID

Fix #17

* IPAMAddress(New): add Parameter example

* IPAMAddress(New): Add Validate for Assigned Object Type

Can be only dcim.interface or virtualization.vminterface

* IPAMAddress(New): Fix Example (it is New and not Create Verb !)

* IPAMAddress(New): Remove -Force parameter, use -Confirm if you want a confirmation

it is the standard with ShouldProcess

* Fix PSSA Warning (#20)

* Fix trailing white space

using Invoke-ScriptAnalyzer -Fix -Path . -Recurse

* add settings.json for configure Visual Code (Formatter)

* PSSA: Fix Command accepts pipeline input but has not defined a process block

* PSSA: Fix PSUseDeclaredVarsMoreThanAssignments

The variable 'I_B' is assigned but never used
The variable 'I_A' is assigned but never used

* PSSA: Fix PSUseShouldProcessForStateChangingFunctions

Function New-/Set-... has verb that could change system state. Therefore, the function has to support 'ShouldProcess'

* Add release.(yml) Github Actions (#21)

It will push on PSGallery module when release a new version !

* Update deploy.ps1 docs

* Update readme

* Remove unused files

* Increment version to 1.5.0

Co-authored-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Co-authored-by: Ben Claussen <claussen@neonet.org>
This commit is contained in:
Ben Claussen 2021-07-23 16:24:34 -04:00 committed by GitHub
parent 739f5e98e2
commit 26c7ccfdd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 3017 additions and 2997 deletions

16
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,16 @@
name: Release
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Publish
run: |
pwsh -Command "Publish-Module -Path ./NetboxPS -NuGetApiKey ${{ secrets.PSGALLERY_API_KEY }}"

10
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,10 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"powershell.scriptAnalysis.settingsPath": ".vscode/PSScriptAnalyzerSettings.psd1",
"powershell.codeFormatting.newLineAfterCloseBrace": false,
"[markdown]": {
"files.trimTrailingWhitespace": false,
}
}

View file

@ -1,14 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
Created on: 2/28/2018 4:06 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: Circuits.ps1
===========================================================================
.DESCRIPTION
Circuit object functions
#>

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,119 +13,121 @@
function Get-NetboxCircuit { function Get-NetboxCircuit {
<# <#
.SYNOPSIS .SYNOPSIS
Gets one or more circuits Gets one or more circuits
.DESCRIPTION .DESCRIPTION
A detailed description of the Get-NetboxCircuit function. A detailed description of the Get-NetboxCircuit function.
.PARAMETER Id .PARAMETER Id
Database ID of circuit. This will query for exactly the IDs provided Database ID of circuit. This will query for exactly the IDs provided
.PARAMETER CID .PARAMETER CID
Circuit ID Circuit ID
.PARAMETER InstallDate .PARAMETER InstallDate
Date of installation Date of installation
.PARAMETER CommitRate .PARAMETER CommitRate
Committed rate in Kbps Committed rate in Kbps
.PARAMETER Query .PARAMETER Query
A raw search query... As if you were searching the web site A raw search query... As if you were searching the web site
.PARAMETER Provider .PARAMETER Provider
The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs
.PARAMETER Type .PARAMETER Type
Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs
.PARAMETER Site .PARAMETER Site
Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs
.PARAMETER Tenant .PARAMETER Tenant
Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs
.PARAMETER Limit .PARAMETER Limit
A description of the Limit parameter. A description of the Limit parameter.
.PARAMETER Offset .PARAMETER Offset
A description of the Offset parameter. A description of the Offset parameter.
.PARAMETER Raw .PARAMETER Raw
A description of the Raw parameter. A description of the Raw parameter.
.PARAMETER ID__IN .PARAMETER ID__IN
Multiple unique DB IDs to retrieve Multiple unique DB IDs to retrieve
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxCircuit PS C:\> Get-NetboxCircuit
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding(DefaultParameterSetName = 'Query')] [CmdletBinding(DefaultParameterSetName = 'Query')]
param param
( (
[Parameter(ParameterSetName = 'ById')] [Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id, [uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$CID, [string]$CID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[datetime]$InstallDate, [datetime]$InstallDate,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$CommitRate, [uint32]$CommitRate,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[object]$Provider, [object]$Provider,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[object]$Type, [object]$Type,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Site, [string]$Site,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Tenant, [string]$Tenant,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { process {
'ById' { switch ($PSCmdlet.ParameterSetName) {
foreach ($i in $ID) { 'ById' {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i)) foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$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
} }
} }
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
@ -15,53 +15,55 @@
function New-NetboxCircuit { function New-NetboxCircuit {
[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]$CID, [string]$CID,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint32]$Provider, [uint32]$Provider,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint32]$Type, [uint32]$Type,
#[ValidateSet('Active', 'Planned', 'Provisioning', 'Offline', 'Deprovisioning', 'Decommissioned ')] #[ValidateSet('Active', 'Planned', 'Provisioning', 'Offline', 'Deprovisioning', 'Decommissioned ')]
[uint16]$Status = 'Active', [uint16]$Status = 'Active',
[string]$Description, [string]$Description,
[uint32]$Tenant, [uint32]$Tenant,
[string]$Termination_A, [string]$Termination_A,
[datetime]$Install_Date, [datetime]$Install_Date,
[string]$Termination_Z, [string]$Termination_Z,
[ValidateRange(0, 2147483647)] [ValidateRange(0, 2147483647)]
[uint32]$Commit_Rate, [uint32]$Commit_Rate,
[string]$Comments, [string]$Comments,
[hashtable]$Custom_Fields, [hashtable]$Custom_Fields,
[switch]$Force, [switch]$Force,
[switch]$Raw [switch]$Raw
) )
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) process {
$Method = 'POST' $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$Method = 'POST'
$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($CID, 'Create new circuit')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
@ -20,52 +20,52 @@ function Get-NetboxCircuitProvider {
[Parameter(ParameterSetName = 'ById', [Parameter(ParameterSetName = 'ById',
Mandatory = $true)] Mandatory = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[Parameter(ParameterSetName = 'Query', [Parameter(ParameterSetName = 'Query',
Mandatory = $false)] Mandatory = $false)]
[string]$Name, [string]$Name,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Slug, [string]$Slug,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$ASN, [string]$ASN,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Account, [string]$Account,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($i in $ID) { foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers', $i)) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "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
} }
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers')) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$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
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
@ -20,58 +20,58 @@ function Get-NetboxCircuitTermination {
[Parameter(ParameterSetName = 'ById', [Parameter(ParameterSetName = 'ById',
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint32[]]$Id, [uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Circuit_ID, [string]$Circuit_ID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Term_Side, [string]$Term_Side,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Port_Speed, [uint32]$Port_Speed,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Site_ID, [string]$Site_ID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Site, [string]$Site,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$XConnect_ID, [string]$XConnect_ID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
process { process {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($i in $ID) { foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations', $i)) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "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
} }
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations')) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$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
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
@ -19,45 +19,45 @@ function Get-NetboxCircuitType {
( (
[Parameter(ParameterSetName = 'ById')] [Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id, [uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Name, [string]$Name,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Slug, [string]$Slug,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($i in $ID) { foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit_types', $i)) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit_types', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id" $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "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
} }
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-types')) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-types'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$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
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,82 +18,84 @@ function Get-NetboxDCIMDevice {
param param
( (
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)] [Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[string]$Query, [string]$Query,
[string]$Name, [string]$Name,
[uint16]$Manufacturer_Id, [uint16]$Manufacturer_Id,
[string]$Manufacturer, [string]$Manufacturer,
[uint16]$Device_Type_Id, [uint16]$Device_Type_Id,
[uint16]$Role_Id, [uint16]$Role_Id,
[string]$Role, [string]$Role,
[uint16]$Tenant_Id, [uint16]$Tenant_Id,
[string]$Tenant, [string]$Tenant,
[uint16]$Platform_Id, [uint16]$Platform_Id,
[string]$Platform, [string]$Platform,
[string]$Asset_Tag, [string]$Asset_Tag,
[uint16]$Site_Id, [uint16]$Site_Id,
[string]$Site, [string]$Site,
[uint16]$Rack_Group_Id, [uint16]$Rack_Group_Id,
[uint16]$Rack_Id, [uint16]$Rack_Id,
[uint16]$Cluster_Id, [uint16]$Cluster_Id,
[uint16]$Model, [uint16]$Model,
[object]$Status, [object]$Status,
[bool]$Is_Full_Depth, [bool]$Is_Full_Depth,
[bool]$Is_Console_Server, [bool]$Is_Console_Server,
[bool]$Is_PDU, [bool]$Is_PDU,
[bool]$Is_Network_Device, [bool]$Is_Network_Device,
[string]$MAC_Address, [string]$MAC_Address,
[bool]$Has_Primary_IP, [bool]$Has_Primary_IP,
[uint16]$Virtual_Chassis_Id, [uint16]$Virtual_Chassis_Id,
[uint16]$Position, [uint16]$Position,
[string]$Serial, [string]$Serial,
[switch]$Raw [switch]$Raw
) )
#endregion Parameters #endregion Parameters
if ($null -ne $Status) { process {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -17,45 +17,45 @@ function Get-NetboxDCIMDeviceRole {
param param
( (
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[Parameter(ParameterSetName = 'ById')] [Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id, [uint16[]]$Id,
[string]$Name, [string]$Name,
[string]$Slug, [string]$Slug,
[string]$Color, [string]$Color,
[bool]$VM_Role, [bool]$VM_Role,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($DRId in $Id) { foreach ($DRId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles', $DRId)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles', $DRId))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw'
$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
} }
break break
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$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
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,44 +18,44 @@ function Get-NetboxDCIMDeviceType {
param param
( (
[uint16]$Offset, [uint16]$Offset,
[uint16]$Limit, [uint16]$Limit,
[uint16[]]$Id, [uint16[]]$Id,
[string]$Query, [string]$Query,
[string]$Slug, [string]$Slug,
[string]$Manufacturer, [string]$Manufacturer,
[uint16]$Manufacturer_Id, [uint16]$Manufacturer_Id,
[string]$Model, [string]$Model,
[string]$Part_Number, [string]$Part_Number,
[uint16]$U_Height, [uint16]$U_Height,
[bool]$Is_Full_Depth, [bool]$Is_Full_Depth,
[bool]$Is_Console_Server, [bool]$Is_Console_Server,
[bool]$Is_PDU, [bool]$Is_PDU,
[bool]$Is_Network_Device, [bool]$Is_Network_Device,
[uint16]$Subdevice_Role, [uint16]$Subdevice_Role,
[switch]$Raw [switch]$Raw
) )
#endregion Parameters #endregion Parameters
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$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
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,78 +13,81 @@
function New-NetboxDCIMDevice { function New-NetboxDCIMDevice {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
#region Parameters #region Parameters
param param
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$Name, [string]$Name,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[object]$Device_Role, [object]$Device_Role,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[object]$Device_Type, [object]$Device_Type,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$Site, [uint16]$Site,
[object]$Status = 'Active', [object]$Status = 'Active',
[uint16]$Platform, [uint16]$Platform,
[uint16]$Tenant, [uint16]$Tenant,
[uint16]$Cluster, [uint16]$Cluster,
[uint16]$Rack, [uint16]$Rack,
[uint16]$Position, [uint16]$Position,
[object]$Face, [object]$Face,
[string]$Serial, [string]$Serial,
[string]$Asset_Tag, [string]$Asset_Tag,
[uint16]$Virtual_Chassis, [uint16]$Virtual_Chassis,
[uint16]$VC_Priority, [uint16]$VC_Priority,
[uint16]$VC_Position, [uint16]$VC_Position,
[uint16]$Primary_IP4, [uint16]$Primary_IP4,
[uint16]$Primary_IP6, [uint16]$Primary_IP6,
[string]$Comments, [string]$Comments,
[hashtable]$Custom_Fields [hashtable]$Custom_Fields
) )
#endregion Parameters #endregion Parameters
# if ($null -ne $Device_Role) { # if ($null -ne $Device_Role) {
# # Validate device role? # # Validate device role?
# } # }
#
# if ($null -ne $Device_Type) { # if ($null -ne $Device_Type) {
# # Validate device type? # # Validate device type?
# } # }
#
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,23 +16,23 @@ function Remove-NetboxDCIMDevice {
<# <#
.SYNOPSIS .SYNOPSIS
Delete a device Delete a device
.DESCRIPTION .DESCRIPTION
Deletes a device from Netbox by ID Deletes a device from Netbox by ID
.PARAMETER Id .PARAMETER Id
Database ID of the device Database ID of the device
.PARAMETER Force .PARAMETER Force
Force deletion without any prompts Force deletion without any prompts
.EXAMPLE .EXAMPLE
PS C:\> Remove-NetboxDCIMDevice -Id $value1 PS C:\> Remove-NetboxDCIMDevice -Id $value1
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding(ConfirmImpact = 'High', [CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
param param
@ -40,29 +40,29 @@ function Remove-NetboxDCIMDevice {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[switch]$Force [switch]$Force
) )
begin { begin {
} }
process { process {
foreach ($DeviceID in $Id) { foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop $CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentDevice.Name) | ID: $($CurrentDevice.Id)", "Remove")) { if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentDevice.Name) | ID: $($CurrentDevice.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE InvokeNetboxRequest -URI $URI -Method DELETE
} }
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -19,77 +19,77 @@ function Set-NetboxDCIMDevice {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[string]$Name, [string]$Name,
[object]$Device_Role, [object]$Device_Role,
[object]$Device_Type, [object]$Device_Type,
[uint16]$Site, [uint16]$Site,
[object]$Status, [object]$Status,
[uint16]$Platform, [uint16]$Platform,
[uint16]$Tenant, [uint16]$Tenant,
[uint16]$Cluster, [uint16]$Cluster,
[uint16]$Rack, [uint16]$Rack,
[uint16]$Position, [uint16]$Position,
[object]$Face, [object]$Face,
[string]$Serial, [string]$Serial,
[string]$Asset_Tag, [string]$Asset_Tag,
[uint16]$Virtual_Chassis, [uint16]$Virtual_Chassis,
[uint16]$VC_Priority, [uint16]$VC_Priority,
[uint16]$VC_Position, [uint16]$VC_Position,
[uint16]$Primary_IP4, [uint16]$Primary_IP4,
[uint16]$Primary_IP6, [uint16]$Primary_IP6,
[string]$Comments, [string]$Comments,
[hashtable]$Custom_Fields, [hashtable]$Custom_Fields,
[switch]$Force [switch]$Force
) )
begin { begin {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
} }
process { process {
foreach ($DeviceID in $Id) { foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop $CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) { if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,45 +18,45 @@ function Get-NetboxDCIMPlatform {
param param
( (
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[Parameter(ParameterSetName = 'ById')] [Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id, [uint16[]]$Id,
[string]$Name, [string]$Name,
[string]$Slug, [string]$Slug,
[uint16]$Manufacturer_Id, [uint16]$Manufacturer_Id,
[string]$Manufacturer, [string]$Manufacturer,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($PlatformID in $Id) { foreach ($PlatformID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $PlatformID)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $PlatformID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw'
$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
} }
break break
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$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
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -19,66 +19,66 @@ function Add-NetboxDCIMInterface {
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$Device, [uint16]$Device,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$Name, [string]$Name,
[bool]$Enabled, [bool]$Enabled,
[object]$Form_Factor, [object]$Form_Factor,
[uint16]$MTU, [uint16]$MTU,
[string]$MAC_Address, [string]$MAC_Address,
[bool]$MGMT_Only, [bool]$MGMT_Only,
[uint16]$LAG, [uint16]$LAG,
[string]$Description, [string]$Description,
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)] [ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode, [string]$Mode,
[ValidateRange(1, 4094)] [ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN, [uint16]$Untagged_VLAN,
[ValidateRange(1, 4094)] [ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs [uint16[]]$Tagged_VLANs
) )
# if ($null -ne $Form_Factor) { # if ($null -ne $Form_Factor) {
# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor # $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
# } # }
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) { $PSBoundParameters.Mode = switch ($Mode) {
'Access' { 'Access' {
100 100
break break
} }
'Tagged' { 'Tagged' {
200 200
break break
} }
'Tagged All' { 'Tagged All' {
300 300
break break
} }
default { default {
$_ $_
} }
} }
} }
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,55 +13,55 @@
function Add-NetboxDCIMInterfaceConnection { function Add-NetboxDCIMInterfaceConnection {
<# <#
.SYNOPSIS .SYNOPSIS
Create a new connection between two interfaces Create a new connection between two interfaces
.DESCRIPTION .DESCRIPTION
Create a new connection between two interfaces Create a new connection between two interfaces
.PARAMETER Connection_Status .PARAMETER Connection_Status
Is it connected or planned? Is it connected or planned?
.PARAMETER Interface_A .PARAMETER Interface_A
Database ID of interface A Database ID of interface A
.PARAMETER Interface_B .PARAMETER Interface_B
Database ID of interface B Database ID of interface B
.EXAMPLE .EXAMPLE
PS C:\> Add-NetboxDCIMInterfaceConnection -Interface_A $value1 -Interface_B $value2 PS C:\> Add-NetboxDCIMInterfaceConnection -Interface_A $value1 -Interface_B $value2
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
[object]$Connection_Status, [object]$Connection_Status,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$Interface_A, [uint16]$Interface_A,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$Interface_B [uint16]$Interface_B
) )
if ($null -ne $Connection_Status) { if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
} }
# Verify if both Interfaces exist # Verify if both Interfaces exist
$I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null
$I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,44 +18,46 @@ function Get-NetboxDCIMInterface {
param param
( (
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)] [Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16]$Id, [uint16]$Id,
[uint16]$Name, [uint16]$Name,
[object]$Form_Factor, [object]$Form_Factor,
[bool]$Enabled, [bool]$Enabled,
[uint16]$MTU, [uint16]$MTU,
[bool]$MGMT_Only, [bool]$MGMT_Only,
[string]$Device, [string]$Device,
[uint16]$Device_Id, [uint16]$Device_Id,
[uint16]$Type, [uint16]$Type,
[uint16]$LAG_Id, [uint16]$LAG_Id,
[string]$MAC_Address, [string]$MAC_Address,
[switch]$Raw [switch]$Raw
) )
if ($null -ne $Form_Factor) { process {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,29 +18,29 @@ function Get-NetboxDCIMInterfaceConnection {
param param
( (
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[uint16]$Id, [uint16]$Id,
[object]$Connection_Status, [object]$Connection_Status,
[uint16]$Site, [uint16]$Site,
[uint16]$Device, [uint16]$Device,
[switch]$Raw [switch]$Raw
) )
if ($null -ne $Connection_Status) { if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
} }
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$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
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,23 +16,23 @@ function Remove-NetboxDCIMInterface {
<# <#
.SYNOPSIS .SYNOPSIS
Removes an interface Removes an interface
.DESCRIPTION .DESCRIPTION
Removes an interface by ID from a device Removes an interface by ID from a device
.PARAMETER Id .PARAMETER Id
A description of the Id parameter. A description of the Id parameter.
.PARAMETER Force .PARAMETER Force
A description of the Force parameter. A description of the Force parameter.
.EXAMPLE .EXAMPLE
PS C:\> Remove-NetboxDCIMInterface -Id $value1 PS C:\> Remove-NetboxDCIMInterface -Id $value1
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding(ConfirmImpact = 'High', [CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
param param
@ -40,29 +40,29 @@ function Remove-NetboxDCIMInterface {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[switch]$Force [switch]$Force
) )
begin { begin {
} }
process { process {
foreach ($InterfaceId in $Id) { foreach ($InterfaceId in $Id) {
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentInterface.Name) | ID: $($CurrentInterface.Id)", "Remove")) { if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentInterface.Name) | ID: $($CurrentInterface.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE InvokeNetboxRequest -URI $URI -Method DELETE
} }
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -21,31 +21,31 @@ function Remove-NetboxDCIMInterfaceConnection {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[switch]$Force [switch]$Force
) )
begin { begin {
} }
process { process {
foreach ($ConnectionID in $Id) { foreach ($ConnectionID in $Id) {
$CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop $CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($ConnectionID.Id)", "REMOVE")) { if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($ConnectionID.Id)", "REMOVE")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method DELETE InvokeNetboxRequest -URI $URI -Method DELETE
} }
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,86 +13,89 @@
function Set-NetboxDCIMInterface { function Set-NetboxDCIMInterface {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[uint16]$Device, [uint16]$Device,
[string]$Name, [string]$Name,
[bool]$Enabled, [bool]$Enabled,
[object]$Form_Factor, [object]$Form_Factor,
[uint16]$MTU, [uint16]$MTU,
[string]$MAC_Address, [string]$MAC_Address,
[bool]$MGMT_Only, [bool]$MGMT_Only,
[uint16]$LAG, [uint16]$LAG,
[string]$Description, [string]$Description,
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)] [ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode, [string]$Mode,
[ValidateRange(1, 4094)] [ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN, [uint16]$Untagged_VLAN,
[ValidateRange(1, 4094)] [ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs [uint16[]]$Tagged_VLANs
) )
begin { begin {
# if ($null -ne $Form_Factor) { # if ($null -ne $Form_Factor) {
# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor # $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
# } # }
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) { $PSBoundParameters.Mode = switch ($Mode) {
'Access' { 'Access' {
100 100
break break
} }
'Tagged' { 'Tagged' {
200 200
break break
} }
'Tagged All' { 'Tagged All' {
300 300
break break
} }
default { default {
$_ $_
} }
} }
} }
} }
process { process {
foreach ($InterfaceId in $Id) { foreach ($InterfaceId in $Id) {
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,32 +16,32 @@ function Set-NetboxDCIMInterfaceConnection {
<# <#
.SYNOPSIS .SYNOPSIS
Update an interface connection Update an interface connection
.DESCRIPTION .DESCRIPTION
Update an interface connection Update an interface connection
.PARAMETER Id .PARAMETER Id
A description of the Id parameter. A description of the Id parameter.
.PARAMETER Connection_Status .PARAMETER Connection_Status
A description of the Connection_Status parameter. A description of the Connection_Status parameter.
.PARAMETER Interface_A .PARAMETER Interface_A
A description of the Interface_A parameter. A description of the Interface_A parameter.
.PARAMETER Interface_B .PARAMETER Interface_B
A description of the Interface_B parameter. A description of the Interface_B parameter.
.PARAMETER Force .PARAMETER Force
A description of the Force parameter. A description of the Force parameter.
.EXAMPLE .EXAMPLE
PS C:\> Set-NetboxDCIMInterfaceConnection -Id $value1 PS C:\> Set-NetboxDCIMInterfaceConnection -Id $value1
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding(ConfirmImpact = 'Medium', [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
param param
@ -49,44 +49,44 @@ function Set-NetboxDCIMInterfaceConnection {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[object]$Connection_Status, [object]$Connection_Status,
[uint16]$Interface_A, [uint16]$Interface_A,
[uint16]$Interface_B, [uint16]$Interface_B,
[switch]$Force [switch]$Force
) )
begin { begin {
# if ($null -ne $Connection_Status) { # if ($null -ne $Connection_Status) {
# $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus # $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
# } # }
if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) { if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) {
throw "Cannot set multiple connections to the same interface" throw "Cannot set multiple connections to the same interface"
} }
} }
process { process {
foreach ($ConnectionID in $Id) { foreach ($ConnectionID in $Id) {
$CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop $CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id))
if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($CurrentConnection.Id)", "Set")) { if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($CurrentConnection.Id)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
@ -20,89 +20,91 @@ function Get-NetboxDCIMSite {
( (
[Parameter(ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true)] [Parameter(ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true)]
[uint32]$Id, [uint32]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Name, [string]$Name,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Slug, [string]$Slug,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Facility, [string]$Facility,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$ASN, [uint32]$ASN,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[decimal]$Latitude, [decimal]$Latitude,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[decimal]$Longitude, [decimal]$Longitude,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Contact_Name, [string]$Contact_Name,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Contact_Phone, [string]$Contact_Phone,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Contact_Email, [string]$Contact_Email,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Group_ID, [uint32]$Tenant_Group_ID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Tenant_Group, [string]$Tenant_Group,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_ID, [uint32]$Tenant_ID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Tenant, [string]$Tenant,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Status, [string]$Status,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Region_ID, [uint32]$Region_ID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Region, [string]$Region,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { process {
'ById' { switch ($PSCmdlet.ParameterSetName) {
foreach ($Site_ID in $ID) { 'ById' {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id)) foreach ($Site_ID in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$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
} }
} }
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,77 +16,77 @@ function BuildNewURI {
<# <#
.SYNOPSIS .SYNOPSIS
Create a new URI for Netbox Create a new URI for Netbox
.DESCRIPTION .DESCRIPTION
Internal function used to build a URIBuilder object. Internal function used to build a URIBuilder object.
.PARAMETER Hostname .PARAMETER Hostname
Hostname of the Netbox API Hostname of the Netbox API
.PARAMETER Segments .PARAMETER Segments
Array of strings for each segment in the URL path Array of strings for each segment in the URL path
.PARAMETER Parameters .PARAMETER Parameters
Hashtable of query parameters to include Hashtable of query parameters to include
.PARAMETER HTTPS .PARAMETER HTTPS
Whether to use HTTPS or HTTP Whether to use HTTPS or HTTP
.PARAMETER Port .PARAMETER Port
A description of the Port parameter. A description of the Port parameter.
.PARAMETER APIInfo .PARAMETER APIInfo
A description of the APIInfo parameter. A description of the APIInfo parameter.
.EXAMPLE .EXAMPLE
PS C:\> BuildNewURI PS C:\> BuildNewURI
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding()]
[OutputType([System.UriBuilder])] [OutputType([System.UriBuilder])]
param param
( (
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[string[]]$Segments, [string[]]$Segments,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[hashtable]$Parameters, [hashtable]$Parameters,
[switch]$SkipConnectedCheck [switch]$SkipConnectedCheck
) )
Write-Verbose "Building URI" Write-Verbose "Building URI"
if (-not $SkipConnectedCheck) { if (-not $SkipConnectedCheck) {
# There is no point in continuing if we have not successfully connected to an API # There is no point in continuing if we have not successfully connected to an API
$null = CheckNetboxIsConnected $null = CheckNetboxIsConnected
} }
# Begin a URI builder with HTTP/HTTPS and the provided hostname # Begin a URI builder with HTTP/HTTPS and the provided hostname
$uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort) $uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort)
# Generate the path by trimming excess slashes and whitespace from the $segments[] and joining together # Generate the path by trimming excess slashes and whitespace from the $segments[] and joining together
$uriBuilder.Path = "api/{0}/" -f ($Segments.ForEach({ $uriBuilder.Path = "api/{0}/" -f ($Segments.ForEach({
$_.trim('/').trim() $_.trim('/').trim()
}) -join '/') }) -join '/')
Write-Verbose " URIPath: $($uriBuilder.Path)" Write-Verbose " URIPath: $($uriBuilder.Path)"
if ($parameters) { if ($parameters) {
# Loop through the parameters and use the HttpUtility to create a Query string # Loop through the parameters and use the HttpUtility to create a Query string
[System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) [System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
foreach ($param in $Parameters.GetEnumerator()) { foreach ($param in $Parameters.GetEnumerator()) {
Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)" Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)"
$URIParams[$param.Key] = $param.Value $URIParams[$param.Key] = $param.Value
} }
$uriBuilder.Query = $URIParams.ToString() $uriBuilder.Query = $URIParams.ToString()
} }
Write-Verbose " Completed building URIBuilder" Write-Verbose " Completed building URIBuilder"
# Return the entire UriBuilder object # Return the entire UriBuilder object
$uriBuilder $uriBuilder

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -19,30 +19,30 @@ function BuildURIComponents {
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[System.Collections.ArrayList]$URISegments, [System.Collections.ArrayList]$URISegments,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[object]$ParametersDictionary, [object]$ParametersDictionary,
[string[]]$SkipParameterByName [string[]]$SkipParameterByName
) )
Write-Verbose "Building URI components" Write-Verbose "Building URI components"
$URIParameters = @{ $URIParameters = @{
} }
foreach ($CmdletParameterName in $ParametersDictionary.Keys) { foreach ($CmdletParameterName in $ParametersDictionary.Keys) {
if ($CmdletParameterName -in $script:CommonParameterNames) { if ($CmdletParameterName -in $script:CommonParameterNames) {
# These are common parameters and should not be appended to the URI # These are common parameters and should not be appended to the URI
Write-Debug "Skipping common parameter $CmdletParameterName" Write-Debug "Skipping common parameter $CmdletParameterName"
continue continue
} }
if ($CmdletParameterName -in $SkipParameterByName) { if ($CmdletParameterName -in $SkipParameterByName) {
Write-Debug "Skipping parameter $CmdletParameterName by SkipParameterByName" Write-Debug "Skipping parameter $CmdletParameterName by SkipParameterByName"
continue continue
} }
switch ($CmdletParameterName) { switch ($CmdletParameterName) {
"id" { "id" {
# Check if there is one or more values for Id and build a URI or query as appropriate # Check if there is one or more values for Id and build a URI or query as appropriate
@ -53,26 +53,26 @@ function BuildURIComponents {
Write-Verbose " Adding ID to segments" Write-Verbose " Adding ID to segments"
[void]$uriSegments.Add($ParametersDictionary[$CmdletParameterName]) [void]$uriSegments.Add($ParametersDictionary[$CmdletParameterName])
} }
break break
} }
'Query' { 'Query' {
Write-Verbose " Adding query parameter" Write-Verbose " Adding query parameter"
$URIParameters['q'] = $ParametersDictionary[$CmdletParameterName] $URIParameters['q'] = $ParametersDictionary[$CmdletParameterName]
break break
} }
'CustomFields' { 'CustomFields' {
Write-Verbose " Adding custom field query parameters" Write-Verbose " Adding custom field query parameters"
foreach ($field in $ParametersDictionary[$CmdletParameterName].GetEnumerator()) { foreach ($field in $ParametersDictionary[$CmdletParameterName].GetEnumerator()) {
Write-Verbose " Adding parameter 'cf_$($field.Key) = $($field.Value)" Write-Verbose " Adding parameter 'cf_$($field.Key) = $($field.Value)"
$URIParameters["cf_$($field.Key.ToLower())"] = $field.Value $URIParameters["cf_$($field.Key.ToLower())"] = $field.Value
} }
break break
} }
default { default {
Write-Verbose " Adding $($CmdletParameterName.ToLower()) parameter" Write-Verbose " Adding $($CmdletParameterName.ToLower()) parameter"
$URIParameters[$CmdletParameterName.ToLower()] = $ParametersDictionary[$CmdletParameterName] $URIParameters[$CmdletParameterName.ToLower()] = $ParametersDictionary[$CmdletParameterName]
@ -80,7 +80,7 @@ function BuildURIComponents {
} }
} }
} }
return @{ return @{
'Segments' = [System.Collections.ArrayList]$URISegments 'Segments' = [System.Collections.ArrayList]$URISegments
'Parameters' = $URIParameters 'Parameters' = $URIParameters

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -15,7 +15,7 @@
function CheckNetboxIsConnected { function CheckNetboxIsConnected {
[CmdletBinding()] [CmdletBinding()]
param () param ()
Write-Verbose "Checking connection status" Write-Verbose "Checking connection status"
if (-not $script:NetboxConfig.Connected) { if (-not $script:NetboxConfig.Connected) {
throw "Not connected to a Netbox API! Please run 'Connect-NetboxAPI'" throw "Not connected to a Netbox API! Please run 'Connect-NetboxAPI'"

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,13 +18,13 @@ function CreateEnum {
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$EnumName, [string]$EnumName,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[pscustomobject]$Values, [pscustomobject]$Values,
[switch]$PassThru [switch]$PassThru
) )
$definition = @" $definition = @"
public enum $EnumName public enum $EnumName
{`n$(foreach ($value in $values) { {`n$(foreach ($value in $values) {

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
@ -20,45 +20,45 @@ function Get-ModelDefinition {
[Parameter(ParameterSetName = 'ByName', [Parameter(ParameterSetName = 'ByName',
Mandatory = $true)] Mandatory = $true)]
[string]$ModelName, [string]$ModelName,
[Parameter(ParameterSetName = 'ByPath', [Parameter(ParameterSetName = 'ByPath',
Mandatory = $true)] Mandatory = $true)]
[string]$URIPath, [string]$URIPath,
[Parameter(ParameterSetName = 'ByPath')] [Parameter(ParameterSetName = 'ByPath')]
[string]$Method = "post" [string]$Method = "post"
) )
switch ($PsCmdlet.ParameterSetName) { switch ($PsCmdlet.ParameterSetName) {
'ByName' { 'ByName' {
$script:NetboxConfig.APIDefinition.definitions.$ModelName $script:NetboxConfig.APIDefinition.definitions.$ModelName
break break
} }
'ByPath' { 'ByPath' {
switch ($Method) { switch ($Method) {
"get" { "get" {
break break
} }
"post" { "post" {
if (-not $URIPath.StartsWith('/')) { if (-not $URIPath.StartsWith('/')) {
$URIPath = "/$URIPath" $URIPath = "/$URIPath"
} }
if (-not $URIPath.EndsWith('/')) { if (-not $URIPath.EndsWith('/')) {
$URIPath = "$URIPath/" $URIPath = "$URIPath/"
} }
$ModelName = $script:NetboxConfig.APIDefinition.paths.$URIPath.post.parameters.schema.'$ref'.split('/')[-1] $ModelName = $script:NetboxConfig.APIDefinition.paths.$URIPath.post.parameters.schema.'$ref'.split('/')[-1]
$script:NetboxConfig.APIDefinition.definitions.$ModelName $script:NetboxConfig.APIDefinition.definitions.$ModelName
break break
} }
} }
break break
} }
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,10 +18,10 @@ function GetNetboxAPIErrorBody {
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[System.Net.HttpWebResponse]$Response [System.Net.HttpWebResponse]$Response
) )
# This takes the $Response stream and turns it into a useable object... generally a string. # This takes the $Response stream and turns it into a useable object... generally a string.
# If the body is JSON, you should be able to use ConvertFrom-Json # If the body is JSON, you should be able to use ConvertFrom-Json
$reader = New-Object System.IO.StreamReader($Response.GetResponseStream()) $reader = New-Object System.IO.StreamReader($Response.GetResponseStream())
$reader.BaseStream.Position = 0 $reader.BaseStream.Position = 0
$reader.DiscardBufferedData() $reader.DiscardBufferedData()

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -14,11 +14,11 @@
function ThrowNetboxRESTError { function ThrowNetboxRESTError {
$uriSegments = [System.Collections.ArrayList]::new(@('fake', 'url')) $uriSegments = [System.Collections.ArrayList]::new(@('fake', 'url'))
$URIParameters = @{ $URIParameters = @{
} }
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters $uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
InvokeNetboxRequest -URI $uri -Raw InvokeNetboxRequest -URI $uri -Raw
} }

View file

@ -34,7 +34,14 @@ function Get-NetboxIPAMAvailableIP {
A description of the NumberOfIPs parameter. A description of the NumberOfIPs parameter.
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1 Get-NetboxIPAMAvailableIP -Prefix_ID (Get-NetboxIPAMPrefix -Prefix 192.0.2.0/24).id
Get (Next) Available IP on the Prefix 192.0.2.0/24
.EXAMPLE
Get-NetboxIPAMAvailableIP -Prefix_ID 2 -NumberOfIPs 3
Get 3 (Next) Available IP on the Prefix 192.0.2.0/24
.NOTES .NOTES
Additional information about the function. Additional information about the function.

View file

@ -1,14 +1,14 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:51 Created on: 3/19/2020 11:51
Created by: Claussen Created by: Claussen
Organization: NEOnet Organization: NEOnet
Filename: New-NetboxIPAMAddress.ps1 Filename: New-NetboxIPAMAddress.ps1
=========================================================================== ===========================================================================
.DESCRIPTION .DESCRIPTION
A description of the file. A description of the file.
#> #>
@ -50,14 +50,19 @@ function New-NetboxIPAMAddress {
.PARAMETER Dns_name .PARAMETER Dns_name
DNS Name of IP address (example : netbox.example.com) DNS Name of IP address (example : netbox.example.com)
.PARAMETER Force .PARAMETER Assigned_Object_Type
Do not prompt for confirmation to create IP. Assigned Object Type dcim.interface or virtualization.vminterface
.PARAMETER Assigned_Object_Id
Assigned Object ID
.PARAMETER Raw .PARAMETER Raw
Return raw results from API service Return raw results from API service
.EXAMPLE .EXAMPLE
PS C:\> Create-NetboxIPAMAddress New-NetboxIPAMAddress -Address 192.0.2.1/32
Add new IP Address 192.0.2.1/32 with status active
.NOTES .NOTES
Additional information about the function. Additional information about the function.
@ -90,7 +95,10 @@ function New-NetboxIPAMAddress {
[string]$Dns_name, [string]$Dns_name,
[switch]$Force, [ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
[int]$Assigned_Object_Id,
[switch]$Raw [switch]$Raw
) )
@ -99,22 +107,11 @@ function New-NetboxIPAMAddress {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses')) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST' $Method = 'POST'
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
# foreach ($Property in $EnumProperties.Keys) {
# if ($PSBoundParameters.ContainsKey($Property)) {
# Write-Verbose "Validating property [$Property] with value [$($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 ($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
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,61 +18,61 @@ function Get-NetboxIPAMAggregate {
( (
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'ByID')] [Parameter(ParameterSetName = 'ByID')]
[uint16[]]$Id, [uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Prefix, [string]$Prefix,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[object]$Family, [object]$Family,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$RIR_Id, [uint16]$RIR_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$RIR, [string]$RIR,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[datetime]$Date_Added, [datetime]$Date_Added,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
# if ($null -ne $Family) { # if ($null -ne $Family) {
# $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily # $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily
# } # }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($IP_ID in $Id) { foreach ($IP_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates', $IP_ID)) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates', $IP_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName '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
} }
break break
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates')) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
break break
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,189 +16,189 @@ function Get-NetboxIPAMPrefix {
<# <#
.SYNOPSIS .SYNOPSIS
A brief description of the Get-NetboxIPAMPrefix function. A brief description of the Get-NetboxIPAMPrefix function.
.DESCRIPTION .DESCRIPTION
A detailed description of the Get-NetboxIPAMPrefix function. A detailed description of the Get-NetboxIPAMPrefix function.
.PARAMETER Query .PARAMETER Query
A description of the Query parameter. A description of the Query parameter.
.PARAMETER Id .PARAMETER Id
A description of the Id parameter. A description of the Id parameter.
.PARAMETER Limit .PARAMETER Limit
A description of the Limit parameter. A description of the Limit parameter.
.PARAMETER Offset .PARAMETER Offset
A description of the Offset parameter. A description of the Offset parameter.
.PARAMETER Family .PARAMETER Family
A description of the Family parameter. A description of the Family parameter.
.PARAMETER Is_Pool .PARAMETER Is_Pool
A description of the Is_Pool parameter. A description of the Is_Pool parameter.
.PARAMETER Within .PARAMETER Within
Should be a CIDR notation prefix such as '10.0.0.0/16' Should be a CIDR notation prefix such as '10.0.0.0/16'
.PARAMETER Within_Include .PARAMETER Within_Include
Should be a CIDR notation prefix such as '10.0.0.0/16' Should be a CIDR notation prefix such as '10.0.0.0/16'
.PARAMETER Contains .PARAMETER Contains
A description of the Contains parameter. A description of the Contains parameter.
.PARAMETER Mask_Length .PARAMETER Mask_Length
CIDR mask length value CIDR mask length value
.PARAMETER VRF .PARAMETER VRF
A description of the VRF parameter. A description of the VRF parameter.
.PARAMETER VRF_Id .PARAMETER VRF_Id
A description of the VRF_Id parameter. A description of the VRF_Id parameter.
.PARAMETER Tenant .PARAMETER Tenant
A description of the Tenant parameter. A description of the Tenant parameter.
.PARAMETER Tenant_Id .PARAMETER Tenant_Id
A description of the Tenant_Id parameter. A description of the Tenant_Id parameter.
.PARAMETER Site .PARAMETER Site
A description of the Site parameter. A description of the Site parameter.
.PARAMETER Site_Id .PARAMETER Site_Id
A description of the Site_Id parameter. A description of the Site_Id parameter.
.PARAMETER Vlan_VId .PARAMETER Vlan_VId
A description of the Vlan_VId parameter. A description of the Vlan_VId parameter.
.PARAMETER Vlan_Id .PARAMETER Vlan_Id
A description of the Vlan_Id parameter. A description of the Vlan_Id parameter.
.PARAMETER Status .PARAMETER Status
A description of the Status parameter. A description of the Status parameter.
.PARAMETER Role .PARAMETER Role
A description of the Role parameter. A description of the Role parameter.
.PARAMETER Role_Id .PARAMETER Role_Id
A description of the Role_Id parameter. A description of the Role_Id parameter.
.PARAMETER Raw .PARAMETER Raw
A description of the Raw parameter. A description of the Raw parameter.
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxIPAMPrefix PS C:\> Get-NetboxIPAMPrefix
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding(DefaultParameterSetName = 'Query')] [CmdletBinding(DefaultParameterSetName = 'Query')]
param param
( (
[Parameter(ParameterSetName = 'Query', [Parameter(ParameterSetName = 'Query',
Position = 0)] Position = 0)]
[string]$Prefix, [string]$Prefix,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'ByID')] [Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id, [uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[object]$Family, [object]$Family,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[boolean]$Is_Pool, [boolean]$Is_Pool,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Within, [string]$Within,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Within_Include, [string]$Within_Include,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Contains, [string]$Contains,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[ValidateRange(0, 127)] [ValidateRange(0, 127)]
[byte]$Mask_Length, [byte]$Mask_Length,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$VRF, [string]$VRF,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$VRF_Id, [uint32]$VRF_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Tenant, [string]$Tenant,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Id, [uint32]$Tenant_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Site, [string]$Site,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Site_Id, [uint32]$Site_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Vlan_VId, [string]$Vlan_VId,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Vlan_Id, [uint32]$Vlan_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[object]$Status, [object]$Status,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Role, [string]$Role,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Role_Id, [uint32]$Role_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
# if ($null -ne $Family) { # if ($null -ne $Family) {
# $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily # $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily
# } # }
# #
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
# } # }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($Prefix_ID in $Id) { foreach ($Prefix_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID)) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName '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
} }
break break
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes')) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
break break
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,47 +13,51 @@
function New-NetboxIPAMPrefix { function New-NetboxIPAMPrefix {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[CmdletBinding()] [CmdletBinding()]
param param
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$Prefix, [string]$Prefix,
[object]$Status = 'Active', [object]$Status = 'Active',
[uint16]$Tenant, [uint16]$Tenant,
[object]$Role, [object]$Role,
[bool]$IsPool, [bool]$IsPool,
[string]$Description, [string]$Description,
[uint16]$Site, [uint16]$Site,
[uint16]$VRF, [uint16]$VRF,
[uint16]$VLAN, [uint16]$VLAN,
[hashtable]$Custom_Fields, [hashtable]$Custom_Fields,
[switch]$Raw [switch]$Raw
) )
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
<# <#
# As of 2018/10/18, this does not appear to be a validated IPAM choice # As of 2018/10/18, this does not appear to be a validated IPAM choice
if ($null -ne $Role) { if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -PrefixRole $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -PrefixRole
} }
#> #>
$segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes')) $segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186
@ -20,39 +20,39 @@ function Set-NetboxIPAMPrefix {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[string]$Prefix, [string]$Prefix,
[string]$Status, [string]$Status,
[uint16]$Tenant, [uint16]$Tenant,
[uint16]$Site, [uint16]$Site,
[uint16]$VRF, [uint16]$VRF,
[uint16]$VLAN, [uint16]$VLAN,
[object]$Role, [object]$Role,
[hashtable]$Custom_Fields, [hashtable]$Custom_Fields,
[string]$Description, [string]$Description,
[switch]$Is_Pool, [switch]$Is_Pool,
[switch]$Force [switch]$Force
) )
begin { begin {
# Write-Verbose "Validating enum properties" # Write-Verbose "Validating enum properties"
# $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0)) # $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0))
$Method = 'PATCH' $Method = 'PATCH'
# #
# # 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)]"
@ -61,22 +61,22 @@ function Set-NetboxIPAMPrefix {
# Write-Verbose "User did not provide a value for [$Property]" # Write-Verbose "User did not provide a value for [$Property]"
# } # }
# } # }
# #
# Write-Verbose "Finished enum validation" # Write-Verbose "Finished enum validation"
} }
process { process {
foreach ($PrefixId in $Id) { foreach ($PrefixId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId)) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId))
Write-Verbose "Obtaining Prefix from ID $PrefixId" Write-Verbose "Obtaining Prefix from ID $PrefixId"
$CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop $CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) { if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
} }
} }

View file

@ -3,93 +3,93 @@ function Get-NetboxIPAMRole {
<# <#
.SYNOPSIS .SYNOPSIS
Get IPAM Prefix/VLAN roles Get IPAM Prefix/VLAN roles
.DESCRIPTION .DESCRIPTION
A role indicates the function of a prefix or VLAN. For example, you might define Data, Voice, and Security roles. Generally, a prefix will be assigned the same functional role as the VLAN to which it is assigned (if any). A role indicates the function of a prefix or VLAN. For example, you might define Data, Voice, and Security roles. Generally, a prefix will be assigned the same functional role as the VLAN to which it is assigned (if any).
.PARAMETER Id .PARAMETER Id
Unique ID Unique ID
.PARAMETER Query .PARAMETER Query
Search query Search query
.PARAMETER Name .PARAMETER Name
Role name Role name
.PARAMETER Slug .PARAMETER Slug
Role URL slug Role URL slug
.PARAMETER Brief .PARAMETER Brief
Brief format Brief format
.PARAMETER Limit .PARAMETER Limit
Result limit Result limit
.PARAMETER Offset .PARAMETER Offset
Result offset Result offset
.PARAMETER Raw .PARAMETER Raw
A description of the Raw parameter. A description of the Raw parameter.
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxIPAMRole PS C:\> Get-NetboxIPAMRole
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding()]
param param
( (
[Parameter(ParameterSetName = 'Query', [Parameter(ParameterSetName = 'Query',
Position = 0)] Position = 0)]
[string]$Name, [string]$Name,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'ByID')] [Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id, [uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Slug, [string]$Slug,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[switch]$Brief, [switch]$Brief,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($Role_ID in $Id) { foreach ($Role_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles', $Role_ID)) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles', $Role_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName '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
} }
break break
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles')) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
break break
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -20,89 +20,89 @@ function Get-NetboxIPAMVLAN {
Position = 0)] Position = 0)]
[ValidateRange(1, 4096)] [ValidateRange(1, 4096)]
[uint16]$VID, [uint16]$VID,
[Parameter(ParameterSetName = 'ByID')] [Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id, [uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Name, [string]$Name,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Tenant, [string]$Tenant,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Id, [uint32]$Tenant_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$TenantGroup, [string]$TenantGroup,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$TenantGroup_Id, [uint32]$TenantGroup_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[object]$Status, [object]$Status,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Region, [string]$Region,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Site, [string]$Site,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Site_Id, [uint32]$Site_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Group, [string]$Group,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Group_Id, [uint32]$Group_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Role, [string]$Role,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint32]$Role_Id, [uint32]$Role_Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
# } # }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($VLAN_ID in $Id) { foreach ($VLAN_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_ID)) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName '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
} }
break break
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans')) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
break break
} }
} }

View file

@ -1,79 +1,82 @@
function New-NetboxIPAMVLAN { function New-NetboxIPAMVLAN {
<# <#
.SYNOPSIS .SYNOPSIS
Create a new VLAN Create a new VLAN
.DESCRIPTION .DESCRIPTION
Create a new VLAN in Netbox with a status of Active by default. Create a new VLAN in Netbox with a status of Active by default.
.PARAMETER VID .PARAMETER VID
The VLAN ID. The VLAN ID.
.PARAMETER Name .PARAMETER Name
The name of the VLAN. The name of the VLAN.
.PARAMETER Status .PARAMETER Status
Status of the VLAN. Defaults to Active Status of the VLAN. Defaults to Active
.PARAMETER Tenant .PARAMETER Tenant
Tenant ID Tenant ID
.PARAMETER Role .PARAMETER Role
Role such as anycast, loopback, etc... Defaults to nothing Role such as anycast, loopback, etc... Defaults to nothing
.PARAMETER Description .PARAMETER Description
Description of IP address Description of IP address
.PARAMETER Custom_Fields .PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service Custom field hash table. Will be validated by the API service
.PARAMETER Raw .PARAMETER Raw
Return raw results from API service Return raw results from API service
.PARAMETER Address .PARAMETER Address
IP address in CIDR notation: 192.168.1.1/24 IP address in CIDR notation: 192.168.1.1/24
.EXAMPLE .EXAMPLE
PS C:\> Create-NetboxIPAMAddress PS C:\> Create-NetboxIPAMAddress
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$VID, [uint16]$VID,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$Name, [string]$Name,
[object]$Status = 'Active', [object]$Status = 'Active',
[uint16]$Tenant, [uint16]$Tenant,
[object]$Role, [object]$Role,
[string]$Description, [string]$Description,
[hashtable]$Custom_Fields, [hashtable]$Custom_Fields,
[switch]$Raw [switch]$Raw
) )
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
#
# if ($null -ne $Role) { # if ($null -ne $Role) {
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
# } # }
$segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans')) $segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}
} }

View file

@ -1,11 +1,11 @@
function Get-NetboxHostPort { function Get-NetboxHostPort {
[CmdletBinding()] [CmdletBinding()]
param () param ()
Write-Verbose "Getting Netbox host port" Write-Verbose "Getting Netbox host port"
if ($null -eq $script:NetboxConfig.HostPort) { if ($null -eq $script:NetboxConfig.HostPort) {
throw "Netbox host port is not set! You may set it with Set-NetboxHostPort -Port 'https'" throw "Netbox host port is not set! You may set it with Set-NetboxHostPort -Port 'https'"
} }
$script:NetboxConfig.HostPort $script:NetboxConfig.HostPort
} }

View file

@ -1,11 +1,11 @@
function Get-NetboxHostScheme { function Get-NetboxHostScheme {
[CmdletBinding()] [CmdletBinding()]
param () param ()
Write-Verbose "Getting Netbox host scheme" Write-Verbose "Getting Netbox host scheme"
if ($null -eq $script:NetboxConfig.Hostscheme) { if ($null -eq $script:NetboxConfig.Hostscheme) {
throw "Netbox host sceme is not set! You may set it with Set-NetboxHostScheme -Scheme 'https'" throw "Netbox host sceme is not set! You may set it with Set-NetboxHostScheme -Scheme 'https'"
} }
$script:NetboxConfig.HostScheme $script:NetboxConfig.HostScheme
} }

View file

@ -7,7 +7,7 @@
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$Port [uint16]$Port
) )
if ($PSCmdlet.ShouldProcess('Netbox Port', 'Set')) { if ($PSCmdlet.ShouldProcess('Netbox Port', 'Set')) {
$script:NetboxConfig.HostPort = $Port $script:NetboxConfig.HostPort = $Port
$script:NetboxConfig.HostPort $script:NetboxConfig.HostPort

View file

@ -8,12 +8,12 @@
[ValidateSet('https', 'http', IgnoreCase = $true)] [ValidateSet('https', 'http', IgnoreCase = $true)]
[string]$Scheme = 'https' [string]$Scheme = 'https'
) )
if ($PSCmdlet.ShouldProcess('Netbox Host Scheme', 'Set')) { if ($PSCmdlet.ShouldProcess('Netbox Host Scheme', 'Set')) {
if ($Scheme -eq 'http') { if ($Scheme -eq 'http') {
Write-Warning "Connecting via non-secure HTTP is not-recommended" Write-Warning "Connecting via non-secure HTTP is not-recommended"
} }
$script:NetboxConfig.HostScheme = $Scheme $script:NetboxConfig.HostScheme = $Scheme
$script:NetboxConfig.HostScheme $script:NetboxConfig.HostScheme
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,105 +16,105 @@ function Get-NetboxTenant {
<# <#
.SYNOPSIS .SYNOPSIS
Get a tenent from Netbox Get a tenent from Netbox
.DESCRIPTION .DESCRIPTION
A detailed description of the Get-NetboxTenant function. A detailed description of the Get-NetboxTenant function.
.PARAMETER Name .PARAMETER Name
The specific name of the tenant. Must match exactly as is defined in Netbox The specific name of the tenant. Must match exactly as is defined in Netbox
.PARAMETER Id .PARAMETER Id
The database ID of the tenant The database ID of the tenant
.PARAMETER Query .PARAMETER Query
A standard search query that will match one or more tenants. A standard search query that will match one or more tenants.
.PARAMETER Slug .PARAMETER Slug
The specific slug of the tenant. Must match exactly as is defined in Netbox The specific slug of the tenant. Must match exactly as is defined in Netbox
.PARAMETER Group .PARAMETER Group
The specific group as defined in Netbox. The specific group as defined in Netbox.
.PARAMETER GroupID .PARAMETER GroupID
The database ID of the group in Netbox The database ID of the group in Netbox
.PARAMETER CustomFields .PARAMETER CustomFields
Hashtable in the format @{"field_name" = "value"} to search Hashtable in the format @{"field_name" = "value"} to search
.PARAMETER Limit .PARAMETER Limit
Limit the number of results to this number Limit the number of results to this number
.PARAMETER Offset .PARAMETER Offset
Start the search at this index in results Start the search at this index in results
.PARAMETER Raw .PARAMETER Raw
Return the unparsed data from the HTTP request Return the unparsed data from the HTTP request
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxTenant PS C:\> Get-NetboxTenant
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding(DefaultParameterSetName = 'Query')] [CmdletBinding(DefaultParameterSetName = 'Query')]
param param
( (
[Parameter(ParameterSetName = 'Query', [Parameter(ParameterSetName = 'Query',
Position = 0)] Position = 0)]
[string]$Name, [string]$Name,
[Parameter(ParameterSetName = 'ByID')] [Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id, [uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Slug, [string]$Slug,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[string]$Group, [string]$Group,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$GroupID, [uint16]$GroupID,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[hashtable]$CustomFields, [hashtable]$CustomFields,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')] [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($Tenant_ID in $Id) { foreach ($Tenant_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants', $Tenant_ID)) $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants', $Tenant_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName '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
} }
break break
} }
default { default {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants')) $Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
break break
} }
} }

View file

@ -1,36 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
Created on: 5/29/2018 1:45 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: Tenancy.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
#region GET commands
#endregion GET commands
#region SET commands
#endregion SET commands
#region ADD/NEW commands
#endregion ADD/NEW commands
#region REMOVE commands
#endregion REMOVE commands

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,143 +13,145 @@
function Get-NetboxVirtualMachine { function Get-NetboxVirtualMachine {
<# <#
.SYNOPSIS .SYNOPSIS
Obtains virtual machines from Netbox. Obtains virtual machines from Netbox.
.DESCRIPTION .DESCRIPTION
Obtains one or more virtual machines based on provided filters. Obtains one or more virtual machines based on provided filters.
.PARAMETER Limit .PARAMETER Limit
Number of results to return per page Number of results to return per page
.PARAMETER Offset .PARAMETER Offset
The initial index from which to return the results The initial index from which to return the results
.PARAMETER Query .PARAMETER Query
A general query used to search for a VM A general query used to search for a VM
.PARAMETER Name .PARAMETER Name
Name of the VM Name of the VM
.PARAMETER Id .PARAMETER Id
Database ID of the VM Database ID of the VM
.PARAMETER Status .PARAMETER Status
Status of the VM Status of the VM
.PARAMETER Tenant .PARAMETER Tenant
String value of tenant String value of tenant
.PARAMETER Tenant_ID .PARAMETER Tenant_ID
Database ID of the tenant. Database ID of the tenant.
.PARAMETER Platform .PARAMETER Platform
String value of the platform String value of the platform
.PARAMETER Platform_ID .PARAMETER Platform_ID
Database ID of the platform Database ID of the platform
.PARAMETER Cluster_Group .PARAMETER Cluster_Group
String value of the cluster group. String value of the cluster group.
.PARAMETER Cluster_Group_Id .PARAMETER Cluster_Group_Id
Database ID of the cluster group. Database ID of the cluster group.
.PARAMETER Cluster_Type .PARAMETER Cluster_Type
String value of the Cluster type. String value of the Cluster type.
.PARAMETER Cluster_Type_Id .PARAMETER Cluster_Type_Id
Database ID of the cluster type. Database ID of the cluster type.
.PARAMETER Cluster_Id .PARAMETER Cluster_Id
Database ID of the cluster. Database ID of the cluster.
.PARAMETER Site .PARAMETER Site
String value of the site. String value of the site.
.PARAMETER Site_Id .PARAMETER Site_Id
Database ID of the site. Database ID of the site.
.PARAMETER Role .PARAMETER Role
String value of the role. String value of the role.
.PARAMETER Role_Id .PARAMETER Role_Id
Database ID of the role. Database ID of the role.
.PARAMETER Raw .PARAMETER Raw
A description of the Raw parameter. A description of the Raw parameter.
.PARAMETER TenantID .PARAMETER TenantID
Database ID of tenant Database ID of tenant
.PARAMETER PlatformID .PARAMETER PlatformID
Database ID of the platform Database ID of the platform
.PARAMETER id__in .PARAMETER id__in
Database IDs of VMs Database IDs of VMs
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxVirtualMachine PS C:\> Get-NetboxVirtualMachine
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding()]
param param
( (
[Alias('q')] [Alias('q')]
[string]$Query, [string]$Query,
[string]$Name, [string]$Name,
[uint16[]]$Id, [uint16[]]$Id,
[object]$Status, [object]$Status,
[string]$Tenant, [string]$Tenant,
[uint16]$Tenant_ID, [uint16]$Tenant_ID,
[string]$Platform, [string]$Platform,
[uint16]$Platform_ID, [uint16]$Platform_ID,
[string]$Cluster_Group, [string]$Cluster_Group,
[uint16]$Cluster_Group_Id, [uint16]$Cluster_Group_Id,
[string]$Cluster_Type, [string]$Cluster_Type,
[uint16]$Cluster_Type_Id, [uint16]$Cluster_Type_Id,
[uint16]$Cluster_Id, [uint16]$Cluster_Id,
[string]$Site, [string]$Site,
[uint16]$Site_Id, [uint16]$Site_Id,
[string]$Role, [string]$Role,
[uint16]$Role_Id, [uint16]$Role_Id,
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
if ($null -ne $Status) { process {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
}
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
} }
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,55 +13,58 @@
function New-NetboxVirtualMachine { function New-NetboxVirtualMachine {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$Name, [string]$Name,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$Cluster, [uint16]$Cluster,
[uint16]$Tenant, [uint16]$Tenant,
[object]$Status = 'Active', [object]$Status = 'Active',
[uint16]$Role, [uint16]$Role,
[uint16]$Platform, [uint16]$Platform,
[uint16]$vCPUs, [uint16]$vCPUs,
[uint16]$Memory, [uint16]$Memory,
[uint16]$Disk, [uint16]$Disk,
[uint16]$Primary_IP4, [uint16]$Primary_IP4,
[uint16]$Primary_IP6, [uint16]$Primary_IP6,
[hashtable]$Custom_Fields, [hashtable]$Custom_Fields,
[string]$Comments [string]$Comments
) )
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
#
# # Validate the status against the APIDefinition # # Validate the status against the APIDefinition
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) { # if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
# } # }
#
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
}
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,23 +16,23 @@ function Remove-NetboxVirtualMachine {
<# <#
.SYNOPSIS .SYNOPSIS
Delete a virtual machine Delete a virtual machine
.DESCRIPTION .DESCRIPTION
Deletes a virtual machine from Netbox by ID Deletes a virtual machine from Netbox by ID
.PARAMETER Id .PARAMETER Id
Database ID of the virtual machine Database ID of the virtual machine
.PARAMETER Force .PARAMETER Force
Force deletion without any prompts Force deletion without any prompts
.EXAMPLE .EXAMPLE
PS C:\> Remove-NetboxVirtualMachine -Id $value1 PS C:\> Remove-NetboxVirtualMachine -Id $value1
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding(ConfirmImpact = 'High', [CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
param param
@ -40,29 +40,29 @@ function Remove-NetboxVirtualMachine {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[switch]$Force [switch]$Force
) )
begin { begin {
} }
process { process {
foreach ($VMId in $Id) { foreach ($VMId in $Id) {
$CurrentVM = Get-NetboxVirtualMachine -Id $VMId -ErrorAction Stop $CurrentVM = Get-NetboxVirtualMachine -Id $VMId -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentVM.Name)/$($CurrentVM.Id)", "Remove")) { if ($Force -or $pscmdlet.ShouldProcess("$($CurrentVM.Name)/$($CurrentVM.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $CurrentVM.Id)) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $CurrentVM.Id))
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE InvokeNetboxRequest -URI $URI -Method DELETE
} }
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -14,59 +14,61 @@
function Set-NetboxVirtualMachine { function Set-NetboxVirtualMachine {
[CmdletBinding(ConfirmImpact = 'Medium', [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
param param
( (
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16]$Id, [uint16]$Id,
[string]$Name, [string]$Name,
[uint16]$Role, [uint16]$Role,
[uint16]$Cluster, [uint16]$Cluster,
[object]$Status, [object]$Status,
[uint16]$Platform, [uint16]$Platform,
[uint16]$Primary_IP4, [uint16]$Primary_IP4,
[uint16]$Primary_IP6, [uint16]$Primary_IP6,
[byte]$VCPUs, [byte]$VCPUs,
[uint16]$Memory, [uint16]$Memory,
[uint16]$Disk, [uint16]$Disk,
[uint16]$Tenant, [uint16]$Tenant,
[string]$Comments, [string]$Comments,
[hashtable]$Custom_Fields, [hashtable]$Custom_Fields,
[switch]$Force [switch]$Force
) )
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# } # }
#
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
Write-Verbose "Obtaining VM from ID $Id"
Write-Verbose "Obtaining VM from ID $Id"
#$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop
#$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop
Write-Verbose "Finished obtaining VM"
Write-Verbose "Finished obtaining VM"
if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -18,28 +18,28 @@ function Add-NetboxVirtualMachineInterface {
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$Name, [string]$Name,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[uint16]$Virtual_Machine, [uint16]$Virtual_Machine,
[boolean]$Enabled = $true, [boolean]$Enabled = $true,
[string]$MAC_Address, [string]$MAC_Address,
[uint16]$MTU, [uint16]$MTU,
[string]$Description, [string]$Description,
[switch]$Raw [switch]$Raw
) )
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$PSBoundParameters.Enabled = $Enabled $PSBoundParameters.Enabled = $Enabled
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments $uri = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -13,82 +13,84 @@
function Get-NetboxVirtualMachineInterface { function Get-NetboxVirtualMachineInterface {
<# <#
.SYNOPSIS .SYNOPSIS
Gets VM interfaces Gets VM interfaces
.DESCRIPTION .DESCRIPTION
Obtains the interface objects for one or more VMs Obtains the interface objects for one or more VMs
.PARAMETER Limit .PARAMETER Limit
Number of results to return per page. Number of results to return per page.
.PARAMETER Offset .PARAMETER Offset
The initial index from which to return the results. The initial index from which to return the results.
.PARAMETER Id .PARAMETER Id
Database ID of the interface Database ID of the interface
.PARAMETER Name .PARAMETER Name
Name of the interface Name of the interface
.PARAMETER Enabled .PARAMETER Enabled
True/False if the interface is enabled True/False if the interface is enabled
.PARAMETER MTU .PARAMETER MTU
Maximum Transmission Unit size. Generally 1500 or 9000 Maximum Transmission Unit size. Generally 1500 or 9000
.PARAMETER Virtual_Machine_Id .PARAMETER Virtual_Machine_Id
ID of the virtual machine to which the interface(s) are assigned. ID of the virtual machine to which the interface(s) are assigned.
.PARAMETER Virtual_Machine .PARAMETER Virtual_Machine
Name of the virtual machine to get interfaces Name of the virtual machine to get interfaces
.PARAMETER MAC_Address .PARAMETER MAC_Address
MAC address assigned to the interface MAC address assigned to the interface
.PARAMETER Raw .PARAMETER Raw
A description of the Raw parameter. A description of the Raw parameter.
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxVirtualMachineInterface PS C:\> Get-NetboxVirtualMachineInterface
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding()]
param param
( (
[Parameter(ValueFromPipeline = $true)] [Parameter(ValueFromPipeline = $true)]
[uint16]$Id, [uint16]$Id,
[string]$Name, [string]$Name,
[string]$Query, [string]$Query,
[boolean]$Enabled, [boolean]$Enabled,
[uint16]$MTU, [uint16]$MTU,
[uint16]$Virtual_Machine_Id, [uint16]$Virtual_Machine_Id,
[string]$Virtual_Machine, [string]$Virtual_Machine,
[string]$MAC_Address, [string]$MAC_Address,
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
}
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -21,45 +21,45 @@ function Set-NetboxVirtualMachineInterface {
[Parameter(Mandatory = $true, [Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)] ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id, [uint16[]]$Id,
[string]$Name, [string]$Name,
[string]$MAC_Address, [string]$MAC_Address,
[uint16]$MTU, [uint16]$MTU,
[string]$Description, [string]$Description,
[boolean]$Enabled, [boolean]$Enabled,
[uint16]$Virtual_Machine, [uint16]$Virtual_Machine,
[switch]$Force [switch]$Force
) )
begin { begin {
} }
process { process {
foreach ($VMI_ID in $Id) { foreach ($VMI_ID in $Id) {
Write-Verbose "Obtaining VM Interface..." Write-Verbose "Obtaining VM Interface..."
$CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop $CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop
Write-Verbose "Finished obtaining VM Interface" Write-Verbose "Finished obtaining VM Interface"
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id)) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id))
if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) { if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
} }
end { end {
} }
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -16,87 +16,87 @@ function Get-NetboxVirtualizationCluster {
<# <#
.SYNOPSIS .SYNOPSIS
Obtains virtualization clusters from Netbox. Obtains virtualization clusters from Netbox.
.DESCRIPTION .DESCRIPTION
Obtains one or more virtualization clusters based on provided filters. Obtains one or more virtualization clusters based on provided filters.
.PARAMETER Limit .PARAMETER Limit
Number of results to return per page Number of results to return per page
.PARAMETER Offset .PARAMETER Offset
The initial index from which to return the results The initial index from which to return the results
.PARAMETER Query .PARAMETER Query
A general query used to search for a cluster A general query used to search for a cluster
.PARAMETER Name .PARAMETER Name
Name of the cluster Name of the cluster
.PARAMETER Id .PARAMETER Id
Database ID(s) of the cluster Database ID(s) of the cluster
.PARAMETER Group .PARAMETER Group
String value of the cluster group. String value of the cluster group.
.PARAMETER Group_Id .PARAMETER Group_Id
Database ID of the cluster group. Database ID of the cluster group.
.PARAMETER Type .PARAMETER Type
String value of the Cluster type. String value of the Cluster type.
.PARAMETER Type_Id .PARAMETER Type_Id
Database ID of the cluster type. Database ID of the cluster type.
.PARAMETER Site .PARAMETER Site
String value of the site. String value of the site.
.PARAMETER Site_Id .PARAMETER Site_Id
Database ID of the site. Database ID of the site.
.PARAMETER Raw .PARAMETER Raw
A description of the Raw parameter. A description of the Raw parameter.
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxVirtualizationCluster PS C:\> Get-NetboxVirtualizationCluster
.NOTES .NOTES
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding()]
param param
( (
[string]$Name, [string]$Name,
[Alias('q')] [Alias('q')]
[string]$Query, [string]$Query,
[uint16[]]$Id, [uint16[]]$Id,
[string]$Group, [string]$Group,
[uint16]$Group_Id, [uint16]$Group_Id,
[string]$Type, [string]$Type,
[uint16]$Type_Id, [uint16]$Type_Id,
[string]$Site, [string]$Site,
[uint16]$Site_Id, [uint16]$Site_Id,
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
} }

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
@ -17,27 +17,27 @@ function Get-NetboxVirtualizationClusterGroup {
param param
( (
[string]$Name, [string]$Name,
[string]$Slug, [string]$Slug,
[string]$Description, [string]$Description,
[string]$Query, [string]$Query,
[uint32[]]$Id, [uint32[]]$Id,
[uint16]$Limit, [uint16]$Limit,
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$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
} }

View file

@ -3,7 +3,7 @@
# #
# Generated by: Ben Claussen # Generated by: Ben Claussen
# #
# Generated on: 2021-07-22 # Generated on: 2021-07-23
# #
@{ @{
@ -12,7 +12,7 @@
RootModule = 'NetboxPS.psm1' RootModule = 'NetboxPS.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '1.4' ModuleVersion = '1.5.0'
# Supported PSEditions # Supported PSEditions
# CompatiblePSEditions = @() # CompatiblePSEditions = @()

View file

@ -10,7 +10,7 @@
Script generated by PowerShell Studio 2020 Script generated by PowerShell Studio 2020
#> #>
# Build a list of common paramters so we can omit them to build URI parameters # Build a list of common parameters so we can omit them to build URI parameters
$script:CommonParameterNames = New-Object System.Collections.ArrayList $script:CommonParameterNames = New-Object System.Collections.ArrayList
[void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters)) [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters))
[void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::OptionalCommonParameters)) [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::OptionalCommonParameters))

View file

@ -3,7 +3,7 @@
# #
# Generated by: Ben Claussen # Generated by: Ben Claussen
# #
# Generated on: 2021-07-22 # Generated on: 2021-07-23
# #
@{ @{
@ -12,7 +12,7 @@
RootModule = 'NetboxPS.psm1' RootModule = 'NetboxPS.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '1.4' ModuleVersion = '1.5.0'
# Supported PSEditions # Supported PSEditions
# CompatiblePSEditions = @() # CompatiblePSEditions = @()

File diff suppressed because it is too large Load diff

View file

@ -4,10 +4,29 @@
# Disclaimer # Disclaimer
This module is beta. Use it at your own risk. I have only added functions as I have needed them, so not everything is available. This module is beta. Use it at your own risk. I have only added functions as I have needed them, so not everything is available.
All functions are exported at the moment, including internal/private functions.
# Description # Description
This module is a wrapper for the [Netbox](https://github.com/netbox-community/netbox) API. This module is a wrapper for the [Netbox](https://github.com/netbox-community/netbox) API.
# Usage # Usage
1. Install module from the `netboxPS` folder 1. Install module from the `netboxPS` folder
2. Import module 2. Import module
3. Connect to an API endpoint by using `Connect-NetboxAPI -Hostname netbox.example.com` 3. Connect to an API endpoint by using `Connect-NetboxAPI -Hostname netbox.example.com`
# Notes
I started this project years ago with Powershell Studio using the built in deployment methods, learning Git, and learning PS best practices. So please forgive any "obvious" mistakes 😅
Over time I have had to adjust my methods for deployment... change the design of functions, and refactor code as I learn new and better things.
This was built out of a need at my job to interact with Netbox for automation. Only recently has it become a "public" project with other collaborators (which I truly appreciate!).
I have done my best to ensure each function does exactly one thing according to the API.
I will do my best to keep up, but please understand it is given attention as I can at work. As time permits, I will open issues for TODOs for things I have wanted to do for a while, just haven't had time or enough "need" to do them.
# Contributing
- Follow [Powershell Practice and Style Guidelines](https://poshcode.gitbook.io/powershell-practice-and-style/) when writing code
- Use discussions for general questions
- Open issues for bug fixes or enhancements
- Submit all pull requests against the dev branch
I am always open to suggestions for improvement with reasons and data to back up the suggestion.

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
@ -24,7 +24,7 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true return $true
} }
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod # Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{ return [ordered]@{
@ -36,375 +36,375 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture {
'Body' = $Body 'Body' = $Body
} }
} }
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
} }
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com' return 'netbox.domain.com'
} }
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
$script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json) $script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "Get-NetboxDCIMDevice" -Fixture { Context -Name "Get-NetboxDCIMDevice" -Fixture {
It "Should request the default number of devices" { It "Should request the default number of devices" {
$Result = Get-NetboxDCIMDevice $Result = Get-NetboxDCIMDevice
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a limit and offset" { It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMDevice -Limit 10 -Offset 100 $Result = Get-NetboxDCIMDevice -Limit 10 -Offset 100
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?offset=100&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a query" { It "Should request with a query" {
$Result = Get-NetboxDCIMDevice -Query 'testdevice' $Result = Get-NetboxDCIMDevice -Query 'testdevice'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=testdevice' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with an escaped query" { It "Should request with an escaped query" {
$Result = Get-NetboxDCIMDevice -Query 'test device' $Result = Get-NetboxDCIMDevice -Query 'test device'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=test+device' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=test+device'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a name" { It "Should request with a name" {
$Result = Get-NetboxDCIMDevice -Name 'testdevice' $Result = Get-NetboxDCIMDevice -Name 'testdevice'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?name=testdevice' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?name=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a single ID" { It "Should request with a single ID" {
$Result = Get-NetboxDCIMDevice -Id 10 $Result = Get-NetboxDCIMDevice -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a device by ID from the pipeline" { It "Should request a device by ID from the pipeline" {
$Result = [pscustomobject]@{ $Result = [pscustomobject]@{
'id' = 10 'id' = 10
} | Get-NetboxDCIMDevice } | Get-NetboxDCIMDevice
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with multiple IDs" { It "Should request with multiple IDs" {
$Result = Get-NetboxDCIMDevice -Id 10, 12, 15 $Result = Get-NetboxDCIMDevice -Id 10, 12, 15
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?id__in=10,12,15' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a status" { It "Should request a status" {
$Result = Get-NetboxDCIMDevice -Status 'Active' $Result = Get-NetboxDCIMDevice -Status 'Active'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?status=1' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?status=1'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should throw for an invalid status" { It "Should throw for an invalid status" {
{ {
Get-NetboxDCIMDevice -Status 'Fake' Get-NetboxDCIMDevice -Status 'Fake'
} | Should -Throw } | Should -Throw
} }
It "Should request devices that are a PDU" { It "Should request devices that are a PDU" {
$Result = Get-NetboxDCIMDevice -Is_PDU $True $Result = Get-NetboxDCIMDevice -Is_PDU $True
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/devices/?is_pdu=True' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/devices/?is_pdu=True'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "Get-NetboxDCIMDeviceType" -Fixture { Context -Name "Get-NetboxDCIMDeviceType" -Fixture {
It "Should request the default number of devices types" { It "Should request the default number of devices types" {
$Result = Get-NetboxDCIMDeviceType $Result = Get-NetboxDCIMDeviceType
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a limit and offset" { It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMDeviceType -Limit 10 -Offset 100 $Result = Get-NetboxDCIMDeviceType -Limit 10 -Offset 100
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?offset=100&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a query" { It "Should request with a query" {
$Result = Get-NetboxDCIMDeviceType -Query 'testdevice' $Result = Get-NetboxDCIMDeviceType -Query 'testdevice'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=testdevice' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with an escaped query" { It "Should request with an escaped query" {
$Result = Get-NetboxDCIMDeviceType -Query 'test device' $Result = Get-NetboxDCIMDeviceType -Query 'test device'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=test+device' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=test+device'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a slug" { It "Should request with a slug" {
$Result = Get-NetboxDCIMDeviceType -Slug 'testdevice' $Result = Get-NetboxDCIMDeviceType -Slug 'testdevice'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?slug=testdevice' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?slug=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a single ID" { It "Should request with a single ID" {
$Result = Get-NetboxDCIMDeviceType -Id 10 $Result = Get-NetboxDCIMDeviceType -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with multiple IDs" { It "Should request with multiple IDs" {
$Result = Get-NetboxDCIMDeviceType -Id 10, 12, 15 $Result = Get-NetboxDCIMDeviceType -Id 10, 12, 15
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?id__in=10,12,15' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a device type that is PDU" { It "Should request a device type that is PDU" {
$Result = Get-NetboxDCIMDeviceType -Is_PDU $true $Result = Get-NetboxDCIMDeviceType -Is_PDU $true
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?is_pdu=True' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?is_pdu=True'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "Get-NetboxDCIMDeviceRole" -Fixture { Context -Name "Get-NetboxDCIMDeviceRole" -Fixture {
It "Should request the default number of devices types" { It "Should request the default number of devices types" {
$Result = Get-NetboxDCIMDeviceRole $Result = Get-NetboxDCIMDeviceRole
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a device role by Id" { It "Should request a device role by Id" {
$Result = Get-NetboxDCIMDeviceRole -Id 10 $Result = Get-NetboxDCIMDeviceRole -Id 10
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request multiple roles by Id" { It "Should request multiple roles by Id" {
$Result = Get-NetboxDCIMDeviceRole -Id 10, 12 $Result = Get-NetboxDCIMDeviceRole -Id 10, 12
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 2 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 2 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET', 'GET' $Result.Method | Should -Be 'GET', 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/', 'https://netbox.domain.com/api/dcim/device-roles/12/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/', 'https://netbox.domain.com/api/dcim/device-roles/12/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
It "Should request single role by Id and color" { It "Should request single role by Id and color" {
$Result = Get-NetboxDCIMDeviceRole -Id 10 -Color '0fab12' $Result = Get-NetboxDCIMDeviceRole -Id 10 -Color '0fab12'
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/?color=0fab12' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/?color=0fab12'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request multiple roles by Id and color" { It "Should request multiple roles by Id and color" {
$Result = Get-NetboxDCIMDeviceRole -Id 10, 12 -Color '0fab12' $Result = Get-NetboxDCIMDeviceRole -Id 10, 12 -Color '0fab12'
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 2 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 2 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET', 'GET' $Result.Method | Should -Be 'GET', 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/?color=0fab12', 'https://netbox.domain.com/api/dcim/device-roles/12/?color=0fab12' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/10/?color=0fab12', 'https://netbox.domain.com/api/dcim/device-roles/12/?color=0fab12'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
It "Should request with a limit and offset" { It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMDeviceRole -Limit 10 -Offset 100 $Result = Get-NetboxDCIMDeviceRole -Limit 10 -Offset 100
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?offset=100&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a slug" { It "Should request with a slug" {
$Result = Get-NetboxDCIMDeviceRole -Slug 'testdevice' $Result = Get-NetboxDCIMDeviceRole -Slug 'testdevice'
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?slug=testdevice' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?slug=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a name" { It "Should request with a name" {
$Result = Get-NetboxDCIMDeviceRole -Name 'TestRole' $Result = Get-NetboxDCIMDeviceRole -Name 'TestRole'
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?name=TestRole' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?name=TestRole'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request those that are VM role" { It "Should request those that are VM role" {
$Result = Get-NetboxDCIMDeviceRole -VM_Role $true $Result = Get-NetboxDCIMDeviceRole -VM_Role $true
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?vm_role=True' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?vm_role=True'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "New-NetboxDCIMDevice" -Fixture { Context -Name "New-NetboxDCIMDevice" -Fixture {
It "Should create a new device" { It "Should create a new device" {
$Result = New-NetboxDCIMDevice -Name "newdevice" -Device_Role 4 -Device_Type 10 -Site 1 -Face 0 $Result = New-NetboxDCIMDevice -Name "newdevice" -Device_Role 4 -Device_Type 10 -Site 1 -Face 0
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"site":1,"face":0,"name":"newdevice","status":1,"device_type":10,"device_role":4}' $Result.Body | Should -Be '{"site":1,"face":0,"name":"newdevice","status":1,"device_type":10,"device_role":4}'
} }
It "Should throw because of an invalid status" { It "Should throw because of an invalid status" {
{ {
New-NetboxDCIMDevice -Name "newdevice" -Device_Role 4 -Device_Type 10 -Site 1 -Status 5555 New-NetboxDCIMDevice -Name "newdevice" -Device_Role 4 -Device_Type 10 -Site 1 -Status 5555
} | Should -Throw } | Should -Throw
} }
} }
Mock -CommandName "Get-NetboxDCIMDevice" -ModuleName NetboxPS -MockWith { Mock -CommandName "Get-NetboxDCIMDevice" -ModuleName NetboxPS -MockWith {
return [pscustomobject]@{ return [pscustomobject]@{
'Id' = $Id 'Id' = $Id
'Name' = $Name 'Name' = $Name
} }
} }
Context -Name "Set-NetboxDCIMDevice" -Fixture { Context -Name "Set-NetboxDCIMDevice" -Fixture {
It "Should set a device to a new name" { It "Should set a device to a new name" {
$Result = Set-NetboxDCIMDevice -Id 1234 -Name 'newtestname' -Force $Result = Set-NetboxDCIMDevice -Id 1234 -Name 'newtestname' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"name":"newtestname"}' $Result.Body | Should -Be '{"name":"newtestname"}'
} }
It "Should set a device with new properties" { It "Should set a device with new properties" {
$Result = Set-NetboxDCIMDevice -Id 1234 -Name 'newtestname' -Cluster 10 -Platform 20 -Site 15 -Force $Result = Set-NetboxDCIMDevice -Id 1234 -Name 'newtestname' -Cluster 10 -Platform 20 -Site 15 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"cluster":10,"platform":20,"name":"newtestname","site":15}' $Result.Body | Should -Be '{"cluster":10,"platform":20,"name":"newtestname","site":15}'
} }
It "Should set multiple devices with new properties" { It "Should set multiple devices with new properties" {
$Result = Set-NetboxDCIMDevice -Id 1234, 3214 -Cluster 10 -Platform 20 -Site 15 -Force $Result = Set-NetboxDCIMDevice -Id 1234, 3214 -Cluster 10 -Platform 20 -Site 15 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/', 'https://netbox.domain.com/api/dcim/devices/3214/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/1234/', 'https://netbox.domain.com/api/dcim/devices/3214/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"cluster":10,"platform":20,"site":15}', '{"cluster":10,"platform":20,"site":15}' $Result.Body | Should -Be '{"cluster":10,"platform":20,"site":15}', '{"cluster":10,"platform":20,"site":15}'
} }
It "Should set multiple devices with new properties from the pipeline" { It "Should set multiple devices with new properties from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -414,51 +414,51 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture {
'id' = 3241 'id' = 3241
} }
) | Set-NetboxDCIMDevice -Cluster 10 -Platform 20 -Site 15 -Force ) | Set-NetboxDCIMDevice -Cluster 10 -Platform 20 -Site 15 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/4432/', 'https://netbox.domain.com/api/dcim/devices/3241/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/4432/', 'https://netbox.domain.com/api/dcim/devices/3241/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"cluster":10,"platform":20,"site":15}', '{"cluster":10,"platform":20,"site":15}' $Result.Body | Should -Be '{"cluster":10,"platform":20,"site":15}', '{"cluster":10,"platform":20,"site":15}'
} }
} }
Context -Name "Remove-NetboxDCIMDevice" -Fixture { Context -Name "Remove-NetboxDCIMDevice" -Fixture {
It "Should remove a device" { It "Should remove a device" {
$Result = Remove-NetboxDCIMDevice -Id 10 -Force $Result = Remove-NetboxDCIMDevice -Id 10 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove multiple devices" { It "Should remove multiple devices" {
$Result = Remove-NetboxDCIMDevice -Id 10, 12 -Force $Result = Remove-NetboxDCIMDevice -Id 10, 12 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/', 'https://netbox.domain.com/api/dcim/devices/12/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/', 'https://netbox.domain.com/api/dcim/devices/12/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
It "Should remove a device from the pipeline" { It "Should remove a device from the pipeline" {
$Result = Get-NetboxDCIMDevice -Id 20 | Remove-NetboxDCIMDevice -Force $Result = Get-NetboxDCIMDevice -Id 20 | Remove-NetboxDCIMDevice -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/20/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/20/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove mulitple devices from the pipeline" { It "Should remove mulitple devices from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -468,10 +468,10 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture {
'Id' = 40 'Id' = 40
} }
) | Remove-NetboxDCIMDevice -Force ) | Remove-NetboxDCIMDevice -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMDevice' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/30/', 'https://netbox.domain.com/api/dcim/devices/40/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/devices/30/', 'https://netbox.domain.com/api/dcim/devices/40/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
@ -24,7 +24,7 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true return $true
} }
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod # Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{ return [ordered]@{
@ -36,107 +36,107 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
'Body' = $Body 'Body' = $Body
} }
} }
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
} }
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com' return 'netbox.domain.com'
} }
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
$script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json) $script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "Get-NetboxDCIMInterface" -Fixture { Context -Name "Get-NetboxDCIMInterface" -Fixture {
It "Should request the default number of interfaces" { It "Should request the default number of interfaces" {
$Result = Get-NetboxDCIMInterface $Result = Get-NetboxDCIMInterface
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a limit and offset" { It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMInterface -Limit 10 -Offset 100 $Result = Get-NetboxDCIMInterface -Limit 10 -Offset 100
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/?offset=100&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with enabled" { It "Should request with enabled" {
$Result = Get-NetboxDCIMInterface -Enabled $true $Result = Get-NetboxDCIMInterface -Enabled $true
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/?enabled=True' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/?enabled=True'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a form factor name" { It "Should request with a form factor name" {
$Result = Get-NetboxDCIMInterface -Form_Factor '10GBASE-T (10GE)' $Result = Get-NetboxDCIMInterface -Form_Factor '10GBASE-T (10GE)'
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/?form_factor=1150' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/?form_factor=1150'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should throw for an invalid form factor" { It "Should throw for an invalid form factor" {
{ {
Get-NetboxDCIMInterface -Form_Factor 'Fake' Get-NetboxDCIMInterface -Form_Factor 'Fake'
} | Should -Throw } | Should -Throw
} }
It "Should request devices that are mgmt only" { It "Should request devices that are mgmt only" {
$Result = Get-NetboxDCIMInterface -MGMT_Only $True $Result = Get-NetboxDCIMInterface -MGMT_Only $True
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/?mgmt_only=True' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/?mgmt_only=True'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request an interface from the pipeline" { It "Should request an interface from the pipeline" {
$Result = [pscustomobject]@{ $Result = [pscustomobject]@{
'Id' = 1234 'Id' = 1234
} | Get-NetboxDCIMInterface } | Get-NetboxDCIMInterface
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/1234/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "Add-NetboxDCIMInterface" -Fixture { Context -Name "Add-NetboxDCIMInterface" -Fixture {
It "Should add a basic interface to a device" { It "Should add a basic interface to a device" {
$Result = Add-NetboxDCIMInterface -Device 111 -Name "TestInterface" $Result = Add-NetboxDCIMInterface -Device 111 -Name "TestInterface"
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"name":"TestInterface","device":111}' $Result.Body | Should -Be '{"name":"TestInterface","device":111}'
} }
It "Should add an interface to a device with lots of properties" { It "Should add an interface to a device with lots of properties" {
$paramAddNetboxDCIMInterface = @{ $paramAddNetboxDCIMInterface = @{
Device = 123 Device = 123
@ -147,77 +147,77 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
Description = 'Test Description' Description = 'Test Description'
Mode = 'Access' Mode = 'Access'
} }
$Result = Add-NetboxDCIMInterface @paramAddNetboxDCIMInterface $Result = Add-NetboxDCIMInterface @paramAddNetboxDCIMInterface
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"mtu":9000,"mgmt_only":true,"description":"Test Description","mode":100,"name":"TestInterface","device":123,"form_factor":1150}' $Result.Body | Should -Be '{"mtu":9000,"mgmt_only":true,"description":"Test Description","mode":100,"name":"TestInterface","device":123,"form_factor":1150}'
} }
It "Should add an interface with multiple tagged VLANs" { It "Should add an interface with multiple tagged VLANs" {
$Result = Add-NetboxDCIMInterface -Device 444 -Name "TestInterface" -Mode 'Tagged' -Tagged_VLANs 1, 2, 3, 4 $Result = Add-NetboxDCIMInterface -Device 444 -Name "TestInterface" -Mode 'Tagged' -Tagged_VLANs 1, 2, 3, 4
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"mode":200,"name":"TestInterface","device":444,"tagged_vlans":[1,2,3,4]}' $Result.Body | Should -Be '{"mode":200,"name":"TestInterface","device":444,"tagged_vlans":[1,2,3,4]}'
} }
It "Should throw for invalid mode" { It "Should throw for invalid mode" {
{ {
Add-NetboxDCIMInterface -Device 321 -Name "Test123" -Mode 'Fake' Add-NetboxDCIMInterface -Device 321 -Name "Test123" -Mode 'Fake'
} | Should -Throw } | Should -Throw
} }
It "Should throw for out of range VLAN" { It "Should throw for out of range VLAN" {
{ {
Add-NetboxDCIMInterface -Device 321 -Name "Test123" -Untagged_VLAN 4100 Add-NetboxDCIMInterface -Device 321 -Name "Test123" -Untagged_VLAN 4100
} | Should -Throw } | Should -Throw
} }
} }
Mock -CommandName "Get-NetboxDCIMInterface" -ModuleName "NetboxPS" -MockWith { Mock -CommandName "Get-NetboxDCIMInterface" -ModuleName "NetboxPS" -MockWith {
return [pscustomobject]@{ return [pscustomobject]@{
'Id' = $Id 'Id' = $Id
} }
} }
Context -Name "Set-NetboxDCIMInterface" -Fixture { Context -Name "Set-NetboxDCIMInterface" -Fixture {
It "Should set an interface to a new name" { It "Should set an interface to a new name" {
$Result = Set-NetboxDCIMInterface -Id 123 -Name "TestInterface" $Result = Set-NetboxDCIMInterface -Id 123 -Name "TestInterface"
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 1 -Exactly -Scope 'It'
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/123/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/123/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"name":"TestInterface"}' $Result.Body | Should -Be '{"name":"TestInterface"}'
} }
It "Should set multiple interfaces to a new name" { It "Should set multiple interfaces to a new name" {
$Result = Set-NetboxDCIMInterface -Id 456, 789 -Name "TestInterface" $Result = Set-NetboxDCIMInterface -Id 456, 789 -Name "TestInterface"
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It'
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/456/', 'https://netbox.domain.com/api/dcim/interfaces/789/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/456/', 'https://netbox.domain.com/api/dcim/interfaces/789/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"name":"TestInterface"}', '{"name":"TestInterface"}' $Result.Body | Should -Be '{"name":"TestInterface"}', '{"name":"TestInterface"}'
} }
It "Should set multiple interfaces to a new name from the pipeline" { It "Should set multiple interfaces to a new name from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -227,58 +227,58 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
'Id' = 4231 'Id' = 4231
} }
) | Set-NetboxDCIMInterface -Name "TestInterface" ) | Set-NetboxDCIMInterface -Name "TestInterface"
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It'
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/1234/', 'https://netbox.domain.com/api/dcim/interfaces/4231/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interfaces/1234/', 'https://netbox.domain.com/api/dcim/interfaces/4231/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"name":"TestInterface"}', '{"name":"TestInterface"}' $Result.Body | Should -Be '{"name":"TestInterface"}', '{"name":"TestInterface"}'
} }
It "Should throw for invalid form factor" { It "Should throw for invalid form factor" {
{ {
Set-NetboxDCIMInterface -Id 1234 -Form_Factor 'fake' Set-NetboxDCIMInterface -Id 1234 -Form_Factor 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "Remove-NetboxDCIMInterface" -Fixture { Context -Name "Remove-NetboxDCIMInterface" -Fixture {
It "Should remove an interface" { It "Should remove an interface" {
$Result = Remove-NetboxDCIMInterface -Id 10 -Force $Result = Remove-NetboxDCIMInterface -Id 10 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/10/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove multiple interfaces" { It "Should remove multiple interfaces" {
$Result = Remove-NetboxDCIMInterface -Id 10, 12 -Force $Result = Remove-NetboxDCIMInterface -Id 10, 12 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/10/', 'https://netbox.domain.com/api/dcim/interfaces/12/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/10/', 'https://netbox.domain.com/api/dcim/interfaces/12/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
It "Should remove an interface from the pipeline" { It "Should remove an interface from the pipeline" {
$Result = Get-NetboxDCIMInterface -Id 20 | Remove-NetboxDCIMInterface -Force $Result = Get-NetboxDCIMInterface -Id 20 | Remove-NetboxDCIMInterface -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/20/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/20/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove mulitple interfaces from the pipeline" { It "Should remove mulitple interfaces from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -288,124 +288,124 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
'Id' = 40 'Id' = 40
} }
) | Remove-NetboxDCIMInterface -Force ) | Remove-NetboxDCIMInterface -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterface' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/30/', 'https://netbox.domain.com/api/dcim/interfaces/40/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interfaces/30/', 'https://netbox.domain.com/api/dcim/interfaces/40/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
} }
Context -Name "Get-NetboxDCIMInterfaceConnection" -Fixture { Context -Name "Get-NetboxDCIMInterfaceConnection" -Fixture {
It "Should request the default number of interface connections" { It "Should request the default number of interface connections" {
$Result = Get-NetboxDCIMInterfaceConnection $Result = Get-NetboxDCIMInterfaceConnection
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a limit and offset" { It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMInterfaceConnection -Limit 10 -Offset 100 $Result = Get-NetboxDCIMInterfaceConnection -Limit 10 -Offset 100
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/?offset=100&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request connected interfaces" { It "Should request connected interfaces" {
$Result = Get-NetboxDCIMInterfaceConnection -Connection_Status 'Connected' $Result = Get-NetboxDCIMInterfaceConnection -Connection_Status 'Connected'
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/?connection_status=True' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/?connection_status=True'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should throw for an invalid connection status" { It "Should throw for an invalid connection status" {
{ {
Get-NetboxDCIMInterfaceConnection -Connection_Status 'Fake' Get-NetboxDCIMInterfaceConnection -Connection_Status 'Fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "Add-NetboxDCIMInterfaceConnection" -Fixture { Context -Name "Add-NetboxDCIMInterfaceConnection" -Fixture {
It "Should add a new interface connection" { It "Should add a new interface connection" {
$Result = Add-NetboxDCIMInterfaceConnection -Interface_A 21 -Interface_B 22 $Result = Add-NetboxDCIMInterfaceConnection -Interface_A 21 -Interface_B 22
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"interface_b":22,"interface_a":21}' $Result.Body | Should -Be '{"interface_b":22,"interface_a":21}'
} }
It "Should throw because of an invalid connection status" { It "Should throw because of an invalid connection status" {
{ {
Add-NetboxDCIMInterfaceConnection -Interface_A 21 -Interface_B 22 -Connection_Status 'fake' Add-NetboxDCIMInterfaceConnection -Interface_A 21 -Interface_B 22 -Connection_Status 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Mock -CommandName "Get-NetboxDCIMInterfaceConnection" -ModuleName 'NetboxPS' -MockWith { Mock -CommandName "Get-NetboxDCIMInterfaceConnection" -ModuleName 'NetboxPS' -MockWith {
[pscustomobject]@{ [pscustomobject]@{
'Id' = $Id 'Id' = $Id
} }
} }
Context -Name "Set-NetboxDCIMInterfaceConnection" -Fixture { Context -Name "Set-NetboxDCIMInterfaceConnection" -Fixture {
It "Should set an interface connection" { It "Should set an interface connection" {
$Result = Set-NetboxDCIMInterfaceConnection -Id 123 -Interface_B 2 -Force $Result = Set-NetboxDCIMInterfaceConnection -Id 123 -Interface_B 2 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/123/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/123/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"interface_b":2}' $Result.Body | Should -Be '{"interface_b":2}'
} }
It "Should set multiple interface connections to a new status" { It "Should set multiple interface connections to a new status" {
$Result = Set-NetboxDCIMInterfaceConnection -Id 456, 789 -Connection_Status 'Planned' -Force $Result = Set-NetboxDCIMInterfaceConnection -Id 456, 789 -Connection_Status 'Planned' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/456/', 'https://netbox.domain.com/api/dcim/interface-connections/789/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/456/', 'https://netbox.domain.com/api/dcim/interface-connections/789/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"connection_status":false}', '{"connection_status":false}' $Result.Body | Should -Be '{"connection_status":false}', '{"connection_status":false}'
} }
It "Should set an interface connection from the pipeline" { It "Should set an interface connection from the pipeline" {
$Result = [pscustomobject]@{ $Result = [pscustomobject]@{
'id' = 3 'id' = 3
} | Set-NetboxDCIMInterfaceConnection -Connection_Status 'Planned' -Force } | Set-NetboxDCIMInterfaceConnection -Connection_Status 'Planned' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/3/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/3/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"connection_status":false}' $Result.Body | Should -Be '{"connection_status":false}'
} }
It "Should set multiple interface connections from the pipeline" { It "Should set multiple interface connections from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -415,57 +415,57 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
'id' = 789 'id' = 789
} }
) | Set-NetboxDCIMInterfaceConnection -Connection_Status 'Planned' -Force ) | Set-NetboxDCIMInterfaceConnection -Connection_Status 'Planned' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/456/', 'https://netbox.domain.com/api/dcim/interface-connections/789/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/interface-connections/456/', 'https://netbox.domain.com/api/dcim/interface-connections/789/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"connection_status":false}', '{"connection_status":false}' $Result.Body | Should -Be '{"connection_status":false}', '{"connection_status":false}'
} }
It "Should throw trying to set multiple connections to the same interface" { It "Should throw trying to set multiple connections to the same interface" {
{ {
Set-NetboxDCIMInterfaceConnection -Id 456, 789 -Interface_B 22 -Force Set-NetboxDCIMInterfaceConnection -Id 456, 789 -Interface_B 22 -Force
} | Should -Throw -ExpectedMessage "Cannot set multiple connections to the same interface" } | Should -Throw -ExpectedMessage "Cannot set multiple connections to the same interface"
} }
} }
Context -Name "Remove-NetboxDCIMInterfaceConnection" -Fixture { Context -Name "Remove-NetboxDCIMInterfaceConnection" -Fixture {
It "Should remove an interface connection" { It "Should remove an interface connection" {
$Result = Remove-NetboxDCIMInterfaceConnection -Id 10 -Force $Result = Remove-NetboxDCIMInterfaceConnection -Id 10 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/10/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove multiple interface connections" { It "Should remove multiple interface connections" {
$Result = Remove-NetboxDCIMInterfaceConnection -Id 10, 12 -Force $Result = Remove-NetboxDCIMInterfaceConnection -Id 10, 12 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/10/', 'https://netbox.domain.com/api/dcim/interface-connections/12/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/10/', 'https://netbox.domain.com/api/dcim/interface-connections/12/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
It "Should remove an interface connection from the pipeline" { It "Should remove an interface connection from the pipeline" {
$Result = Get-NetboxDCIMInterfaceConnection -Id 20 | Remove-NetboxDCIMInterfaceConnection -Force $Result = Get-NetboxDCIMInterfaceConnection -Id 20 | Remove-NetboxDCIMInterfaceConnection -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/20/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/20/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove mulitple interface connections from the pipeline" { It "Should remove mulitple interface connections from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -475,10 +475,10 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
'Id' = 40 'Id' = 40
} }
) | Remove-NetboxDCIMInterfaceConnection -Force ) | Remove-NetboxDCIMInterfaceConnection -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxDCIMInterfaceConnection' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/30/', 'https://netbox.domain.com/api/dcim/interface-connections/40/' $Result.URI | Should -Be 'https://netbox.domain.com/api/dcim/interface-connections/30/', 'https://netbox.domain.com/api/dcim/interface-connections/40/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
@ -24,7 +24,7 @@ Describe -Name "DCIM Platforms Tests" -Tag 'DCIM', 'platforms' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true return $true
} }
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod # Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{ return [ordered]@{
@ -36,78 +36,78 @@ Describe -Name "DCIM Platforms Tests" -Tag 'DCIM', 'platforms' -Fixture {
'Body' = $Body 'Body' = $Body
} }
} }
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
} }
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com' return 'netbox.domain.com'
} }
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
Context -Name "Get-NetboxDCIMPlatform" -Fixture { Context -Name "Get-NetboxDCIMPlatform" -Fixture {
It "Should request the default number of platforms" { It "Should request the default number of platforms" {
$Result = Get-NetboxDCIMPlatform $Result = Get-NetboxDCIMPlatform
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a limit and offset" { It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMPlatform -Limit 10 -Offset 100 $Result = Get-NetboxDCIMPlatform -Limit 10 -Offset 100
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?offset=100&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a platform name" { It "Should request with a platform name" {
$Result = Get-NetboxDCIMPlatform -Name "Windows Server 2016" $Result = Get-NetboxDCIMPlatform -Name "Windows Server 2016"
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?name=Windows+Server+2016' $Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?name=Windows+Server+2016'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a platform by manufacturer" { It "Should request a platform by manufacturer" {
$Result = Get-NetboxDCIMPlatform -Manufacturer 'Cisco' $Result = Get-NetboxDCIMPlatform -Manufacturer 'Cisco'
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/?manufacturer=Cisco' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/?manufacturer=Cisco'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a platform by ID" { It "Should request a platform by ID" {
$Result = Get-NetboxDCIMPlatform -Id 10 $Result = Get-NetboxDCIMPlatform -Id 10
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/10/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request multiple platforms by ID" { It "Should request multiple platforms by ID" {
$Result = Get-NetboxDCIMPlatform -Id 10, 20 $Result = Get-NetboxDCIMPlatform -Id 10, 20
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Scope 'It' -Exactly Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET', 'GET' $Result.Method | Should -Be 'GET', 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/10/', 'https://netbox.domain.com/api/dcim/platforms/20/' $Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/10/', 'https://netbox.domain.com/api/dcim/platforms/20/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
@ -26,17 +26,17 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
Check-NetboxIsConnected Check-NetboxIsConnected
} | Should -Throw } | Should -Throw
} }
Mock -CommandName 'CheckNetboxIsConnected' -MockWith { Mock -CommandName 'CheckNetboxIsConnected' -MockWith {
return $true return $true
} -ModuleName 'NetboxPS' } -ModuleName 'NetboxPS'
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
Context -Name "Building URIBuilder" -Fixture { Context -Name "Building URIBuilder" -Fixture {
It "Should give a basic URI object" { It "Should give a basic URI object" {
BuildNewURI -HostName 'netbox.domain.com' | Should -BeOfType [System.UriBuilder] BuildNewURI -HostName 'netbox.domain.com' | Should -BeOfType [System.UriBuilder]
} }
It "Should generate a URI using only a supplied hostname" { It "Should generate a URI using only a supplied hostname" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" $URIBuilder = BuildNewURI -Hostname "netbox.domain.com"
$URIBuilder.Host | Should -BeExactly 'netbox.domain.com' $URIBuilder.Host | Should -BeExactly 'netbox.domain.com'
@ -45,51 +45,51 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$URIBuilder.Port | Should -Be 443 $URIBuilder.Port | Should -Be 443
$URIBuilder.URI.AbsoluteUri | Should -Be 'https://netbox.domain.com/api//' $URIBuilder.URI.AbsoluteUri | Should -Be 'https://netbox.domain.com/api//'
} }
It "Should generate a URI using a hostname and segments" { It "Should generate a URI using a hostname and segments" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2'
$URIBuilder.Host | Should -BeExactly 'netbox.domain.com' $URIBuilder.Host | Should -BeExactly 'netbox.domain.com'
$URIBuilder.Path | Should -BeExactly 'api/seg1/seg2/' $URIBuilder.Path | Should -BeExactly 'api/seg1/seg2/'
$URIBuilder.URI.AbsoluteUri | Should -BeExactly 'https://netbox.domain.com/api/seg1/seg2/' $URIBuilder.URI.AbsoluteUri | Should -BeExactly 'https://netbox.domain.com/api/seg1/seg2/'
} }
It "Should generate a URI using insecure HTTP and default to port 80" { It "Should generate a URI using insecure HTTP and default to port 80" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -HTTPS $false -WarningAction 'SilentlyContinue' $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -HTTPS $false -WarningAction 'SilentlyContinue'
$URIBuilder.Scheme | Should -Be 'http' $URIBuilder.Scheme | Should -Be 'http'
$URIBuilder.Port | Should -Be 80 $URIBuilder.Port | Should -Be 80
$URIBuilder.URI.AbsoluteURI | Should -Be 'http://netbox.domain.com/api/seg1/seg2/' $URIBuilder.URI.AbsoluteURI | Should -Be 'http://netbox.domain.com/api/seg1/seg2/'
} }
It "Should generate a URI using HTTPS on port 1234" { It "Should generate a URI using HTTPS on port 1234" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -Port 1234 $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -Port 1234
$URIBuilder.Scheme | Should -Be 'https' $URIBuilder.Scheme | Should -Be 'https'
$URIBuilder.Port | Should -Be 1234 $URIBuilder.Port | Should -Be 1234
$URIBuilder.URI.AbsoluteURI | Should -BeExactly 'https://netbox.domain.com:1234/api/seg1/seg2/' $URIBuilder.URI.AbsoluteURI | Should -BeExactly 'https://netbox.domain.com:1234/api/seg1/seg2/'
} }
It "Should generate a URI using HTTP on port 4321" { It "Should generate a URI using HTTP on port 4321" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -HTTPS $false -Port 4321 -WarningAction 'SilentlyContinue' $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -HTTPS $false -Port 4321 -WarningAction 'SilentlyContinue'
$URIBuilder.Scheme | Should -Be 'http' $URIBuilder.Scheme | Should -Be 'http'
$URIBuilder.Port | Should -Be 4321 $URIBuilder.Port | Should -Be 4321
$URIBuilder.URI.AbsoluteURI | Should -BeExactly 'http://netbox.domain.com:4321/api/seg1/seg2/' $URIBuilder.URI.AbsoluteURI | Should -BeExactly 'http://netbox.domain.com:4321/api/seg1/seg2/'
} }
It "Should generate a URI with parameters" { It "Should generate a URI with parameters" {
$URIParameters = @{ $URIParameters = @{
'param1' = 'paramval1' 'param1' = 'paramval1'
'param2' = 'paramval2' 'param2' = 'paramval2'
} }
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -Parameters $URIParameters $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' -Parameters $URIParameters
$URIBuilder.Query | Should -BeExactly '?param1=paramval1&param2=paramval2' $URIBuilder.Query | Should -BeExactly '?param1=paramval1&param2=paramval2'
$URIBuilder.URI.AbsoluteURI | Should -BeExactly 'https://netbox.domain.com/api/seg1/seg2/?param1=paramval1&param2=paramval2' $URIBuilder.URI.AbsoluteURI | Should -BeExactly 'https://netbox.domain.com/api/seg1/seg2/?param1=paramval1&param2=paramval2'
} }
} }
Context -Name "Building URI components" -Fixture { Context -Name "Building URI components" -Fixture {
It "Should give a basic hashtable" { It "Should give a basic hashtable" {
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1} $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1}
$URIComponents | Should -BeOfType [hashtable] $URIComponents | Should -BeOfType [hashtable]
$URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys.Count | Should -BeExactly 2
$URIComponents.Keys | Should -Be @("Segments", "Parameters") $URIComponents.Keys | Should -Be @("Segments", "Parameters")
@ -98,10 +98,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters | Should -BeOfType [hashtable]
$URIComponents.Parameters['param1'] | Should -Be 1 $URIComponents.Parameters['param1'] | Should -Be 1
} }
It "Should add a single ID parameter to the segments" { It "Should add a single ID parameter to the segments" {
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = 123} $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = 123}
$URIComponents | Should -BeOfType [hashtable] $URIComponents | Should -BeOfType [hashtable]
$URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys.Count | Should -BeExactly 2
$URIComponents.Keys | Should -Be @("Segments", "Parameters") $URIComponents.Keys | Should -Be @("Segments", "Parameters")
@ -109,10 +109,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$URIComponents.Parameters.Count | Should -BeExactly 0 $URIComponents.Parameters.Count | Should -BeExactly 0
$URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters | Should -BeOfType [hashtable]
} }
It "Should add multiple IDs to the parameters id__in" { It "Should add multiple IDs to the parameters id__in" {
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = "123", "456"} $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = "123", "456"}
$URIComponents | Should -BeOfType [hashtable] $URIComponents | Should -BeOfType [hashtable]
$URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys.Count | Should -BeExactly 2
$URIComponents.Keys | Should -Be @("Segments", "Parameters") $URIComponents.Keys | Should -Be @("Segments", "Parameters")
@ -121,10 +121,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters | Should -BeOfType [hashtable]
$URIComponents.Parameters['id__in'] | Should -Be '123,456' $URIComponents.Parameters['id__in'] | Should -Be '123,456'
} }
It "Should skip a particular parameter name" { It "Should skip a particular parameter name" {
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1; 'param2' = 2} -SkipParameterByName 'param2' $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1; 'param2' = 2} -SkipParameterByName 'param2'
$URIComponents | Should -BeOfType [hashtable] $URIComponents | Should -BeOfType [hashtable]
$URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys.Count | Should -BeExactly 2
$URIComponents.Keys | Should -Be @("Segments", "Parameters") $URIComponents.Keys | Should -Be @("Segments", "Parameters")
@ -134,10 +134,10 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$URIComponents.Parameters['param1'] | Should -Be 1 $URIComponents.Parameters['param1'] | Should -Be 1
$URIComponents.Parameters['param2'] | Should -BeNullOrEmpty $URIComponents.Parameters['param2'] | Should -BeNullOrEmpty
} }
It "Should add a query (q) parameter" { It "Should add a query (q) parameter" {
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'query' = 'mytestquery'} $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'query' = 'mytestquery'}
$URIComponents | Should -BeOfType [hashtable] $URIComponents | Should -BeOfType [hashtable]
$URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys.Count | Should -BeExactly 2
$URIComponents.Keys | Should -Be @("Segments", "Parameters") $URIComponents.Keys | Should -Be @("Segments", "Parameters")
@ -146,7 +146,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters | Should -BeOfType [hashtable]
$URIComponents.Parameters['q'] | Should -Be 'mytestquery' $URIComponents.Parameters['q'] | Should -Be 'mytestquery'
} }
It "Should generate custom field parameters" { It "Should generate custom field parameters" {
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{ $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{
'CustomFields' = @{ 'CustomFields' = @{
@ -154,7 +154,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
'Customer_Id' = 'abc' 'Customer_Id' = 'abc'
} }
} }
$URIComponents | Should -BeOfType [hashtable] $URIComponents | Should -BeOfType [hashtable]
$URIComponents.Keys.Count | Should -BeExactly 2 $URIComponents.Keys.Count | Should -BeExactly 2
$URIComponents.Keys | Should -Be @("Segments", "Parameters") $URIComponents.Keys | Should -Be @("Segments", "Parameters")
@ -165,7 +165,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$URIComponents.Parameters['cf_customer_id'] | Should -Be 'abc' $URIComponents.Parameters['cf_customer_id'] | Should -Be 'abc'
} }
} }
Context -Name "Invoking request tests" -Fixture { Context -Name "Invoking request tests" -Fixture {
Mock -CommandName 'Invoke-RestMethod' -Verifiable -MockWith { Mock -CommandName 'Invoke-RestMethod' -Verifiable -MockWith {
# Return an object of the items we would normally pass to Invoke-RestMethod # Return an object of the items we would normally pass to Invoke-RestMethod
@ -179,29 +179,29 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
'results' = 'Only results' 'results' = 'Only results'
} }
} }
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
} }
It "Should return direct results instead of the raw request" { It "Should return direct results instead of the raw request" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2'
$Result = InvokeNetboxRequest -URI $URIBuilder $Result = InvokeNetboxRequest -URI $URIBuilder
Assert-VerifiableMock Assert-VerifiableMock
$Result | Should -BeOfType [string] $Result | Should -BeOfType [string]
$Result | Should -BeExactly "Only results" $Result | Should -BeExactly "Only results"
} }
It "Should generate a basic request" { It "Should generate a basic request" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2'
$Result = InvokeNetboxRequest -URI $URIBuilder -Raw $Result = InvokeNetboxRequest -URI $URIBuilder -Raw
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be $URIBuilder.Uri.AbsoluteUri $Result.Uri | Should -Be $URIBuilder.Uri.AbsoluteUri
$Result.Headers | Should -BeOfType [System.Collections.HashTable] $Result.Headers | Should -BeOfType [System.Collections.HashTable]
@ -210,49 +210,49 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
$Result.ContentType | Should -Be 'application/json' $Result.ContentType | Should -Be 'application/json'
$Result.Body | Should -Be $null # We did not supply a body $Result.Body | Should -Be $null # We did not supply a body
} }
It "Should generate a POST request with body" { It "Should generate a POST request with body" {
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2'
$Result = InvokeNetboxRequest -URI $URIBuilder -Method POST -Body @{ $Result = InvokeNetboxRequest -URI $URIBuilder -Method POST -Body @{
'bodyparam1' = 'val1' 'bodyparam1' = 'val1'
} -Raw } -Raw
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Body | Should -Be '{"bodyparam1":"val1"}' $Result.Body | Should -Be '{"bodyparam1":"val1"}'
} }
It "Should generate a POST request with an extra header" { It "Should generate a POST request with an extra header" {
$Headers = @{ $Headers = @{
'Connection' = 'keep-alive' 'Connection' = 'keep-alive'
} }
$Body = @{ $Body = @{
'bodyparam1' = 'val1' 'bodyparam1' = 'val1'
} }
$URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URIBuilder = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2'
$Result = InvokeNetboxRequest -URI $URIBuilder -Method POST -Body $Body -Headers $Headers -Raw $Result = InvokeNetboxRequest -URI $URIBuilder -Method POST -Body $Body -Headers $Headers -Raw
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Body | Should -Be '{"bodyparam1":"val1"}' $Result.Body | Should -Be '{"bodyparam1":"val1"}'
$Result.Headers.Count | Should -BeExactly 2 $Result.Headers.Count | Should -BeExactly 2
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
$Result.Headers.Connection | Should -Be "keep-alive" $Result.Headers.Connection | Should -Be "keep-alive"
} }
It "Should throw because of an invalid method" { It "Should throw because of an invalid method" {
{ {
$URI = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URI = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2'
InvokeNetboxRequest -URI $URI -Method 'Fake' InvokeNetboxRequest -URI $URI -Method 'Fake'
} | Should -Throw } | Should -Throw
} }
It "Should throw because of an out-of-range timeout" { It "Should throw because of an out-of-range timeout" {
{ {
$URI = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2' $URI = BuildNewURI -Hostname "netbox.domain.com" -Segments 'seg1', 'seg2'
@ -260,222 +260,222 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "Validating choices" -Fixture { Context -Name "Validating choices" -Fixture {
Context -Name "Virtualization choices" -Fixture { Context -Name "Virtualization choices" -Fixture {
$MajorObject = 'Virtualization' $MajorObject = 'Virtualization'
$script:NetboxConfig.Choices.Virtualization = (Get-Content "$PSScriptRoot\VirtualizationChoices.json" -ErrorAction Stop | ConvertFrom-Json) $script:NetboxConfig.Choices.Virtualization = (Get-Content "$PSScriptRoot\VirtualizationChoices.json" -ErrorAction Stop | ConvertFrom-Json)
It "Should return a valid integer for status when provided a name" { It "Should return a valid integer for status when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 'Active' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 'Active'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should return a valid integer for status when provided an integer" { It "Should return a valid integer for status when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 0 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 0
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 0 $Result | Should -BeExactly 0
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 'Fake' ValidateChoice -MajorObject $MajorObject -ChoiceName 'virtual-machine:status' -ProvidedValue 'Fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "IPAM choices" -Fixture { Context -Name "IPAM choices" -Fixture {
$MajorObject = 'IPAM' $MajorObject = 'IPAM'
$script:NetboxConfig.Choices.IPAM = (Get-Content "$PSScriptRoot\IPAMChoices.json" -ErrorAction Stop | ConvertFrom-Json) $script:NetboxConfig.Choices.IPAM = (Get-Content "$PSScriptRoot\IPAMChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "aggregate:family" -Fixture { Context -Name "aggregate:family" -Fixture {
$ChoiceName = 'aggregate:family' $ChoiceName = 'aggregate:family'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 4 $Result | Should -BeExactly 4
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 4 $Result | Should -BeExactly 4
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "prefix:family" { Context -Name "prefix:family" {
$ChoiceName = 'prefix:family' $ChoiceName = 'prefix:family'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 4 $Result | Should -BeExactly 4
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 4 $Result | Should -BeExactly 4
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "prefix:status" { Context -Name "prefix:status" {
$ChoiceName = 'prefix:status' $ChoiceName = 'prefix:status'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "ip-address:family" { Context -Name "ip-address:family" {
$ChoiceName = 'ip-address:family' $ChoiceName = 'ip-address:family'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'IPv4'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 4 $Result | Should -BeExactly 4
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 4
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 4 $Result | Should -BeExactly 4
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "ip-address:status" { Context -Name "ip-address:status" {
$ChoiceName = 'ip-address:status' $ChoiceName = 'ip-address:status'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 10
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "ip-address:role" { Context -Name "ip-address:role" {
$ChoiceName = 'ip-address:role' $ChoiceName = 'ip-address:role'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Anycast' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Anycast'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 30 $Result | Should -BeExactly 30
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 30 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 30
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 30 $Result | Should -BeExactly 30
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "vlan:status" { Context -Name "vlan:status" {
$ChoiceName = 'vlan:status' $ChoiceName = 'vlan:status'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "service:protocol" { Context -Name "service:protocol" {
$ChoiceName = 'service:protocol' $ChoiceName = 'service:protocol'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'TCP' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'TCP'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 6 $Result | Should -BeExactly 6
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 6 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 6
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 6 $Result | Should -BeExactly 6
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0
@ -483,241 +483,241 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
} }
} }
} }
Context -Name "DCIM choices" -Fixture { Context -Name "DCIM choices" -Fixture {
$MajorObject = 'DCIM' $MajorObject = 'DCIM'
$script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json) $script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "device:face" -Fixture { Context -Name "device:face" -Fixture {
$ChoiceName = 'device:face' $ChoiceName = 'device:face'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Front' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Front'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 0 $Result | Should -BeExactly 0
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "device:status" -Fixture { Context -Name "device:status" -Fixture {
$ChoiceName = 'device:status' $ChoiceName = 'device:status'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Active'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1 $Result | Should -BeExactly 1
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 0
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 0 $Result | Should -BeExactly 0
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "console-port:connection_status" -Fixture { Context -Name "console-port:connection_status" -Fixture {
$ChoiceName = 'console-port:connection_status' $ChoiceName = 'console-port:connection_status'
It "Should return a valid string when provided a name" { It "Should return a valid string when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned'
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $false $Result | Should -Be $false
} }
It "Should return a valid string when provided a string" { It "Should return a valid string when provided a string" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false'
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $false $Result | Should -Be $false
} }
It "Should return a valid string when provided a boolean" { It "Should return a valid string when provided a boolean" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $true $Result | Should -Be $true
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "interface:form_factor" -Fixture { Context -Name "interface:form_factor" -Fixture {
$ChoiceName = 'interface:form_factor' $ChoiceName = 'interface:form_factor'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '10GBASE-CX4 (10GE)' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '10GBASE-CX4 (10GE)'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1170 $Result | Should -BeExactly 1170
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1500 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1500
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1500 $Result | Should -BeExactly 1500
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "interface-connection:connection_status" -Fixture { Context -Name "interface-connection:connection_status" -Fixture {
$ChoiceName = 'interface-connection:connection_status' $ChoiceName = 'interface-connection:connection_status'
It "Should return a valid string when provided a name" { It "Should return a valid string when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned'
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $false $Result | Should -Be $false
} }
It "Should return a valid string when provided a string" { It "Should return a valid string when provided a string" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false'
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $false $Result | Should -Be $false
} }
It "Should return a valid string when provided a boolean" { It "Should return a valid string when provided a boolean" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $true $Result | Should -Be $true
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "interface-template:form_factor" -Fixture { Context -Name "interface-template:form_factor" -Fixture {
$ChoiceName = 'interface-template:form_factor' $ChoiceName = 'interface-template:form_factor'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '10GBASE-CX4 (10GE)' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '10GBASE-CX4 (10GE)'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1170 $Result | Should -BeExactly 1170
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1500 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 1500
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 1500 $Result | Should -BeExactly 1500
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "power-port:connection_status" -Fixture { Context -Name "power-port:connection_status" -Fixture {
$ChoiceName = 'power-port:connection_status' $ChoiceName = 'power-port:connection_status'
It "Should return a valid string when provided a name" { It "Should return a valid string when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'Planned'
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $false $Result | Should -Be $false
} }
It "Should return a valid string when provided a string" { It "Should return a valid string when provided a string" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'false'
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $false $Result | Should -Be $false
} }
It "Should return a valid string when provided a boolean" { It "Should return a valid string when provided a boolean" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue $true
$Result | Should -BeOfType [bool] $Result | Should -BeOfType [bool]
$Result | Should -Be $true $Result | Should -Be $true
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "rack:type" -Fixture { Context -Name "rack:type" -Fixture {
$ChoiceName = 'rack:type' $ChoiceName = 'rack:type'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '2-post frame' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '2-post frame'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 100 $Result | Should -BeExactly 100
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 300 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 300
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 300 $Result | Should -BeExactly 300
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'
} | Should -Throw } | Should -Throw
} }
} }
Context -Name "rack:width" -Fixture { Context -Name "rack:width" -Fixture {
$ChoiceName = 'rack:width' $ChoiceName = 'rack:width'
It "Should return a valid integer when provided a name" { It "Should return a valid integer when provided a name" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '19 inches' $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue '19 inches'
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 19 $Result | Should -BeExactly 19
} }
It "Should return a valid integer when provided an integer" { It "Should return a valid integer when provided an integer" {
$Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 23 $Result = ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 23
$Result | Should -BeOfType [uint16] $Result | Should -BeOfType [uint16]
$Result | Should -BeExactly 23 $Result | Should -BeExactly 23
} }
It "Should throw because of an invalid choice" { It "Should throw because of an invalid choice" {
{ {
ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake' ValidateChoice -MajorObject $MajorObject -ChoiceName $ChoiceName -ProvidedValue 'fake'

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
@ -25,7 +25,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true return $true
} }
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod # Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{ return [ordered]@{
@ -37,387 +37,387 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
'Body' = $Body 'Body' = $Body
} }
} }
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
} }
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com' return 'netbox.domain.com'
} }
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
$script:NetboxConfig.Choices.IPAM = (Get-Content "$PSScriptRoot\IPAMChoices.json" -ErrorAction Stop | ConvertFrom-Json) $script:NetboxConfig.Choices.IPAM = (Get-Content "$PSScriptRoot\IPAMChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "Get-NetboxIPAMAggregate" -Fixture { Context -Name "Get-NetboxIPAMAggregate" -Fixture {
It "Should request the default number of aggregates" { It "Should request the default number of aggregates" {
$Result = Get-NetboxIPAMAggregate $Result = Get-NetboxIPAMAggregate
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with limit and offset" { It "Should request with limit and offset" {
$Result = Get-NetboxIPAMAggregate -Limit 10 -Offset 12 $Result = Get-NetboxIPAMAggregate -Limit 10 -Offset 12
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with a query" { It "Should request with a query" {
$Result = Get-NetboxIPAMAggregate -Query '10.10.0.0' $Result = Get-NetboxIPAMAggregate -Query '10.10.0.0'
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with an escaped query" { It "Should request with an escaped query" {
$Result = Get-NetboxIPAMAggregate -Query 'my aggregate' $Result = Get-NetboxIPAMAggregate -Query 'my aggregate'
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with a single ID" { It "Should request with a single ID" {
$Result = Get-NetboxIPAMAggregate -Id 10 $Result = Get-NetboxIPAMAggregate -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with multiple IDs" { It "Should request with multiple IDs" {
$Result = Get-NetboxIPAMAggregate -Id 10, 12, 15 $Result = Get-NetboxIPAMAggregate -Id 10, 12, 15
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
} }
Context -Name "Get-NetboxIPAMAddress" -Fixture { Context -Name "Get-NetboxIPAMAddress" -Fixture {
It "Should request the default number of addresses" { It "Should request the default number of addresses" {
$Result = Get-NetboxIPAMAddress $Result = Get-NetboxIPAMAddress
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with limit and offset" { It "Should request with limit and offset" {
$Result = Get-NetboxIPAMAddress -Limit 10 -Offset 12 $Result = Get-NetboxIPAMAddress -Limit 10 -Offset 12
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with a query" { It "Should request with a query" {
$Result = Get-NetboxIPAMAddress -Query '10.10.10.10' $Result = Get-NetboxIPAMAddress -Query '10.10.10.10'
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with an escaped query" { It "Should request with an escaped query" {
$Result = Get-NetboxIPAMAddress -Query 'my ip address' $Result = Get-NetboxIPAMAddress -Query 'my ip address'
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with a single ID" { It "Should request with a single ID" {
$Result = Get-NetboxIPAMAddress -Id 10 $Result = Get-NetboxIPAMAddress -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with multiple IDs" { It "Should request with multiple IDs" {
$Result = Get-NetboxIPAMAddress -Id 10, 12, 15 $Result = Get-NetboxIPAMAddress -Id 10, 12, 15
Assert-VerifiableMock Assert-VerifiableMock
$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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with a family number" { It "Should request with a family number" {
$Result = Get-NetboxIPAMAddress -Family 4 $Result = Get-NetboxIPAMAddress -Family 4
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?family=4' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?family=4'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a family name" { It "Should request with a family name" {
$Result = Get-NetboxIPAMAddress -Family 'IPv4' $Result = Get-NetboxIPAMAddress -Family 'IPv4'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?family=4' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/?family=4'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "Get-NetboxIPAMAvailableIP" -Fixture { Context -Name "Get-NetboxIPAMAvailableIP" -Fixture {
It "Should request the default number of available IPs" { It "Should request the default number of available IPs" {
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 10 $Result = Get-NetboxIPAMAvailableIP -Prefix_Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/available-ips/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/available-ips/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request 10 available IPs" { It "Should request 10 available IPs" {
$Result = Get-NetboxIPAMAvailableIP -Prefix_Id 1504 -NumberOfIPs 10 $Result = Get-NetboxIPAMAvailableIP -Prefix_Id 1504 -NumberOfIPs 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/1504/available-ips/?limit=10' $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.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
} }
Context -Name "Get-NetboxIPAMPrefix" -Fixture { Context -Name "Get-NetboxIPAMPrefix" -Fixture {
It "Should request the default number of prefixes" { It "Should request the default number of prefixes" {
$Result = Get-NetboxIPAMPrefix $Result = Get-NetboxIPAMPrefix
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with limit and offset" { It "Should request with limit and offset" {
$Result = Get-NetboxIPAMPrefix -Limit 10 -Offset 12 $Result = Get-NetboxIPAMPrefix -Limit 10 -Offset 12
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?offset=12&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with a query" { It "Should request with a query" {
$Result = Get-NetboxIPAMPrefix -Query '10.10.10.10' $Result = Get-NetboxIPAMPrefix -Query '10.10.10.10'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=10.10.10.10' $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.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with an escaped query" { It "Should request with an escaped query" {
$Result = Get-NetboxIPAMPrefix -Query 'my ip address' $Result = Get-NetboxIPAMPrefix -Query 'my ip address'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?q=my+ip+address' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?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" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with a single ID" { It "Should request with a single ID" {
$Result = Get-NetboxIPAMPrefix -Id 10 $Result = Get-NetboxIPAMPrefix -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with multiple IDs" { It "Should request with multiple IDs" {
$Result = Get-NetboxIPAMPrefix -Id 10, 12, 15 $Result = Get-NetboxIPAMPrefix -Id 10, 12, 15
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?id__in=10,12,15' $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.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with VLAN vID" { It "Should request with VLAN vID" {
$Result = Get-NetboxIPAMPrefix -VLAN_VID 10 $Result = Get-NetboxIPAMPrefix -VLAN_VID 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?vlan_vid=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?vlan_vid=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should request with family of 4" { It "Should request with family of 4" {
$Result = Get-NetboxIPAMPrefix -Family 4 $Result = Get-NetboxIPAMPrefix -Family 4
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?family=4' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?family=4'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
It "Should throw because the mask length is too large" { It "Should throw because the mask length is too large" {
{ {
Get-NetboxIPAMPrefix -Mask_length 128 Get-NetboxIPAMPrefix -Mask_length 128
} | Should -Throw } | Should -Throw
} }
It "Should throw because the mask length is too small" { It "Should throw because the mask length is too small" {
{ {
Get-NetboxIPAMPrefix -Mask_length -1 Get-NetboxIPAMPrefix -Mask_length -1
} | Should -Throw } | Should -Throw
} }
It "Should not throw because the mask length is just right" { It "Should not throw because the mask length is just right" {
{ {
Get-NetboxIPAMPrefix -Mask_length 24 Get-NetboxIPAMPrefix -Mask_length 24
} | Should -Not -Throw } | Should -Not -Throw
} }
It "Should request with mask length 24" { It "Should request with mask length 24" {
$Result = Get-NetboxIPAMPrefix -Mask_length 24 $Result = Get-NetboxIPAMPrefix -Mask_length 24
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?mask_length=24' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/?mask_length=24'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Headers.Authorization | Should -Be "Token faketoken" $Result.Headers.Authorization | Should -Be "Token faketoken"
} }
} }
Context -Name "New-NetboxIPAMPrefix" -Fixture { Context -Name "New-NetboxIPAMPrefix" -Fixture {
It "Should create a basic prefix" { It "Should create a basic prefix" {
$Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24"
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1}' $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1}'
} }
It "Should create a prefix with a status and role names" { It "Should create a prefix with a status and role names" {
$Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"role":"Active"}' $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"role":"Active"}'
} }
It "Should create a prefix with a status, role name, and tenant ID" { It "Should create a prefix with a status, role name, and tenant ID" {
$Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' -Tenant 15 $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' -Tenant 15
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"tenant":15,"role":"Active"}' $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"tenant":15,"role":"Active"}'
} }
} }
Context -Name "New-NetboxIPAMAddress" -Fixture { Context -Name "New-NetboxIPAMAddress" -Fixture {
It "Should create a basic IP address" { It "Should create a basic IP address" {
$Result = New-NetboxIPAMAddress -Address '10.0.0.1/24' $Result = New-NetboxIPAMAddress -Address '10.0.0.1/24'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$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.Body | Should -Be '{"status":1,"address":"10.0.0.1/24"}' $Result.Body | Should -Be '{"status":1,"address":"10.0.0.1/24"}'
} }
It "Should create an IP with a status and role names" { It "Should create an IP with a status and role names" {
$Result = New-NetboxIPAMAddress -Address '10.0.0.1/24' -Status 'Reserved' -Role 'Anycast' $Result = New-NetboxIPAMAddress -Address '10.0.0.1/24' -Status 'Reserved' -Role 'Anycast'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$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.Body | Should -Be '{"status":2,"address":"10.0.0.1/24","role":30}' $Result.Body | Should -Be '{"status":2,"address":"10.0.0.1/24","role":30}'
} }
It "Should create an IP with a status and role values" { It "Should create an IP with a status and role values" {
$Result = New-NetboxIPAMAddress -Address '10.0.1.1/24' -Status '1' -Role '10' $Result = New-NetboxIPAMAddress -Address '10.0.1.1/24' -Status '1' -Role '10'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$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.Body | Should -Be '{"status":1,"address":"10.0.1.1/24","role":10}' $Result.Body | Should -Be '{"status":1,"address":"10.0.1.1/24","role":10}'
} }
} }
Context -Name "Remove-NetboxIPAMAddress" -Fixture { Context -Name "Remove-NetboxIPAMAddress" -Fixture {
Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith { Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith {
return @{ return @{
@ -425,44 +425,44 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
'id' = $id 'id' = $id
} }
} }
It "Should remove a single IP" { It "Should remove a single IP" {
$Result = Remove-NetboxIPAMAddress -Id 4109 -Force $Result = Remove-NetboxIPAMAddress -Id 4109 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be $null $Result.Body | Should -Be $null
} }
It "Should remove a single IP from the pipeline" { It "Should remove a single IP from the pipeline" {
$Result = [pscustomobject]@{ $Result = [pscustomobject]@{
'id' = 4110 'id' = 4110
} | Remove-NetboxIPAMAddress -Force } | Remove-NetboxIPAMAddress -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4110/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be $null $Result.Body | Should -Be $null
} }
It "Should remove multiple IPs" { It "Should remove multiple IPs" {
$Result = Remove-NetboxIPAMAddress -Id 4109, 4110 -Force $Result = Remove-NetboxIPAMAddress -Id 4109, 4110 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope 'It' -Exactly
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4110/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
It "Should remove multiple IPs from the pipeline" { It "Should remove multiple IPs from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -472,16 +472,16 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
'id' = 4110 'id' = 4110
} }
) | Remove-NetboxIPAMAddress -Force ) | Remove-NetboxIPAMAddress -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope 'It' -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope 'It' -Exactly
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4110/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
} }
Context -Name "Set-NetboxIPAMAddress" -Fixture { Context -Name "Set-NetboxIPAMAddress" -Fixture {
Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith { Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith {
return @{ return @{
@ -489,57 +489,57 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
'id' = $id 'id' = $id
} }
} }
It "Should set an IP with a new status" { It "Should set an IP with a new status" {
$Result = Set-NetboxIPAMAddress -Id 4109 -Status 2 -Force $Result = Set-NetboxIPAMAddress -Id 4109 -Status 2 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"status":2}' $Result.Body | Should -Be '{"status":2}'
} }
It "Should set an IP from the pipeline" { It "Should set an IP from the pipeline" {
$Result = [pscustomobject]@{ $Result = [pscustomobject]@{
'Id' = 4501 'Id' = 4501
} | Set-NetboxIPAMAddress -VRF 10 -Tenant 14 -Description 'Test description' -Force } | Set-NetboxIPAMAddress -VRF 10 -Tenant 14 -Description 'Test description' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4501/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4501/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"vrf":10,"description":"Test description","tenant":14}' $Result.Body | Should -Be '{"vrf":10,"description":"Test description","tenant":14}'
} }
It "Should set mulitple IPs to a new status" { It "Should set mulitple IPs to a new status" {
$Result = Set-NetboxIPAMAddress -Id 4109, 4555 -Status 2 -Force $Result = Set-NetboxIPAMAddress -Id 4109, 4555 -Status 2 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope "It" -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope "It" -Exactly
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4555/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4109/', 'https://netbox.domain.com/api/ipam/ip-addresses/4555/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"status":2}', '{"status":2}' $Result.Body | Should -Be '{"status":2}', '{"status":2}'
} }
It "Should set an IP with VRF, Tenant, and Description" { It "Should set an IP with VRF, Tenant, and Description" {
$Result = Set-NetboxIPAMAddress -Id 4110 -VRF 10 -Tenant 14 -Description 'Test description' -Force $Result = Set-NetboxIPAMAddress -Id 4110 -VRF 10 -Tenant 14 -Description 'Test description' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 1 -Scope "It" -Exactly
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4110/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4110/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"vrf":10,"description":"Test description","tenant":14}' $Result.Body | Should -Be '{"vrf":10,"description":"Test description","tenant":14}'
} }
It "Should set multiple IPs from the pipeline" { It "Should set multiple IPs from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -549,10 +549,10 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
'Id' = 4611 'Id' = 4611
} }
) | Set-NetboxIPAMAddress -Status 2 -Force ) | Set-NetboxIPAMAddress -Status 2 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope "It" -Exactly Assert-MockCalled -CommandName "Get-NetboxIPAMAddress" -Times 2 -Scope "It" -Exactly
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4501/', 'https://netbox.domain.com/api/ipam/ip-addresses/4611/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/ipam/ip-addresses/4501/', 'https://netbox.domain.com/api/ipam/ip-addresses/4611/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
@ -24,61 +24,61 @@ Describe "Setup tests" -Tag 'Core', 'Setup' -Fixture {
It "Throws an error for an empty hostname" { It "Throws an error for an empty hostname" {
{ Get-NetboxHostname } | Should -Throw { Get-NetboxHostname } | Should -Throw
} }
It "Sets the hostname" { It "Sets the hostname" {
Set-NetboxHostName -HostName 'netbox.domain.com' | Should -Be 'netbox.domain.com' Set-NetboxHostName -HostName 'netbox.domain.com' | Should -Be 'netbox.domain.com'
} }
It "Gets the hostname from the variable" { It "Gets the hostname from the variable" {
Get-NetboxHostName | Should -Be 'netbox.domain.com' Get-NetboxHostName | Should -Be 'netbox.domain.com'
} }
It "Throws an error for empty credentials" { It "Throws an error for empty credentials" {
{ Get-NetboxCredential } | Should -Throw { Get-NetboxCredential } | Should -Throw
} }
Context "Plain text credentials" { Context "Plain text credentials" {
It "Sets the credentials using plain text" { It "Sets the credentials using plain text" {
Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) | Should -BeOfType [pscredential] Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) | Should -BeOfType [pscredential]
} }
It "Checks the set credentials" { It "Checks the set credentials" {
$Creds = Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) $Creds = Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText)
(Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly "faketoken" (Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly "faketoken"
} }
} }
Context "Credentials object" { Context "Credentials object" {
$Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) $Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
It "Sets the credentials using [pscredential]" { It "Sets the credentials using [pscredential]" {
Set-NetboxCredential -Credential $Creds | Should -BeOfType [pscredential] Set-NetboxCredential -Credential $Creds | Should -BeOfType [pscredential]
} }
It "Checks the set credentials" { It "Checks the set credentials" {
(Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly 'faketoken' (Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly 'faketoken'
} }
} }
<# <#
Context "Connecting to the API" { Context "Connecting to the API" {
Mock Get-NetboxCircuitsChoices { Mock Get-NetboxCircuitsChoices {
return $true return $true
} -ModuleName NetboxPS -Verifiable } -ModuleName NetboxPS -Verifiable
$Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) $Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
It "Connects using supplied hostname and obtained credentials" { It "Connects using supplied hostname and obtained credentials" {
#$null = Set-NetboxCredentials -Credentials $Creds #$null = Set-NetboxCredentials -Credentials $Creds
Connect-NetboxAPI -Hostname "fake.org" | Should -Be $true Connect-NetboxAPI -Hostname "fake.org" | Should -Be $true
} }
It "Connects using supplied hostname and credentials" { It "Connects using supplied hostname and credentials" {
Connect-NetboxAPI -Hostname 'fake.org' -Credentials $Creds | Should -Be $true Connect-NetboxAPI -Hostname 'fake.org' -Credentials $Creds | Should -Be $true
} }
Assert-MockCalled -CommandName Get-NetboxCircuitsChoices -ModuleName NetboxPS Assert-MockCalled -CommandName Get-NetboxCircuitsChoices -ModuleName NetboxPS
} }
#> #>

View file

@ -1,4 +1,4 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
@ -24,7 +24,7 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true return $true
} }
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod # Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{ return [ordered]@{
@ -35,285 +35,285 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
'ContentType' = $ContentType 'ContentType' = $ContentType
'Body' = $Body 'Body' = $Body
} }
} }
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force)) return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
} }
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith { Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com' return 'netbox.domain.com'
} }
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock { InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
$script:NetboxConfig.Choices.Virtualization = (Get-Content "$PSScriptRoot\VirtualizationChoices.json" -ErrorAction Stop | ConvertFrom-Json) $script:NetboxConfig.Choices.Virtualization = (Get-Content "$PSScriptRoot\VirtualizationChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "Get-NetboxVirtualMachine" -Fixture { Context -Name "Get-NetboxVirtualMachine" -Fixture {
It "Should request the default number of VMs" { It "Should request the default number of VMs" {
$Result = Get-NetboxVirtualMachine $Result = Get-NetboxVirtualMachine
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with limit and offset" { It "Should request with limit and offset" {
$Result = Get-NetboxVirtualMachine -Limit 10 -Offset 12 $Result = Get-NetboxVirtualMachine -Limit 10 -Offset 12
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?offset=12&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a query" { It "Should request with a query" {
$Result = Get-NetboxVirtualMachine -Query 'testvm' $Result = Get-NetboxVirtualMachine -Query 'testvm'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=testvm' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=testvm'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with an escaped query" { It "Should request with an escaped query" {
$Result = Get-NetboxVirtualMachine -Query 'test vm' $Result = Get-NetboxVirtualMachine -Query 'test vm'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=test+vm' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=test+vm'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a name" { It "Should request with a name" {
$Result = Get-NetboxVirtualMachine -Name 'testvm' $Result = Get-NetboxVirtualMachine -Name 'testvm'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?name=testvm' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?name=testvm'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a single ID" { It "Should request with a single ID" {
$Result = Get-NetboxVirtualMachine -Id 10 $Result = Get-NetboxVirtualMachine -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with multiple IDs" { It "Should request with multiple IDs" {
$Result = Get-NetboxVirtualMachine -Id 10, 12, 15 $Result = Get-NetboxVirtualMachine -Id 10, 12, 15
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?id__in=10,12,15' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a status" { It "Should request a status" {
$Result = Get-NetboxVirtualMachine -Status 'Active' $Result = Get-NetboxVirtualMachine -Status 'Active'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?status=1' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?status=1'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should throw for an invalid status" { It "Should throw for an invalid status" {
{ Get-NetboxVirtualMachine -Status 'Fake' } | Should -Throw { Get-NetboxVirtualMachine -Status 'Fake' } | Should -Throw
} }
} }
Context -Name "Get-NetboxVirtualMachineInterface" -Fixture { Context -Name "Get-NetboxVirtualMachineInterface" -Fixture {
It "Should request the default number of interfaces" { It "Should request the default number of interfaces" {
$Result = Get-NetboxVirtualMachineInterface $Result = Get-NetboxVirtualMachineInterface
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a limit and offset" { It "Should request with a limit and offset" {
$Result = Get-NetboxVirtualMachineInterface -Limit 10 -Offset 12 $Result = Get-NetboxVirtualMachineInterface -Limit 10 -Offset 12
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?offset=12&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a interface with a specific ID" { It "Should request a interface with a specific ID" {
$Result = Get-NetboxVirtualMachineInterface -Id 10 $Result = Get-NetboxVirtualMachineInterface -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request a name" { It "Should request a name" {
$Result = Get-NetboxVirtualMachineInterface -Name 'Ethernet0' $Result = Get-NetboxVirtualMachineInterface -Name 'Ethernet0'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?name=Ethernet0' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?name=Ethernet0'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a VM ID" { It "Should request with a VM ID" {
$Result = Get-NetboxVirtualMachineInterface -Virtual_Machine_Id 10 $Result = Get-NetboxVirtualMachineInterface -Virtual_Machine_Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?virtual_machine_id=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?virtual_machine_id=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with Enabled" { It "Should request with Enabled" {
$Result = Get-NetboxVirtualMachineInterface -Enabled $true $Result = Get-NetboxVirtualMachineInterface -Enabled $true
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?enabled=true' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?enabled=true'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "Get-NetboxVirtualMachineCluster" -Fixture { Context -Name "Get-NetboxVirtualMachineCluster" -Fixture {
It "Should request the default number of clusters" { It "Should request the default number of clusters" {
$Result = Get-NetboxVirtualizationCluster $Result = Get-NetboxVirtualizationCluster
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with limit and offset" { It "Should request with limit and offset" {
$Result = Get-NetboxVirtualizationCluster -Limit 10 -Offset 12 $Result = Get-NetboxVirtualizationCluster -Limit 10 -Offset 12
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?offset=12&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a query" { It "Should request with a query" {
$Result = Get-NetboxVirtualizationCluster -Query 'testcluster' $Result = Get-NetboxVirtualizationCluster -Query 'testcluster'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=testcluster' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=testcluster'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with an escaped query" { It "Should request with an escaped query" {
$Result = Get-NetboxVirtualizationCluster -Query 'test cluster' $Result = Get-NetboxVirtualizationCluster -Query 'test cluster'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=test+cluster' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=test+cluster'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a name" { It "Should request with a name" {
$Result = Get-NetboxVirtualizationCluster -Name 'testcluster' $Result = Get-NetboxVirtualizationCluster -Name 'testcluster'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?name=testcluster' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?name=testcluster'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a single ID" { It "Should request with a single ID" {
$Result = Get-NetboxVirtualizationCluster -Id 10 $Result = Get-NetboxVirtualizationCluster -Id 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/10/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with multiple IDs" { It "Should request with multiple IDs" {
$Result = Get-NetboxVirtualizationCluster -Id 10, 12, 15 $Result = Get-NetboxVirtualizationCluster -Id 10, 12, 15
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?id__in=10,12,15' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "Get-NetboxVirtualMachineClusterGroup" -Fixture { Context -Name "Get-NetboxVirtualMachineClusterGroup" -Fixture {
It "Should request the default number of cluster groups" { It "Should request the default number of cluster groups" {
$Result = Get-NetboxVirtualizationClusterGroup $Result = Get-NetboxVirtualizationClusterGroup
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with limit and offset" { It "Should request with limit and offset" {
$Result = Get-NetboxVirtualizationClusterGroup -Limit 10 -Offset 12 $Result = Get-NetboxVirtualizationClusterGroup -Limit 10 -Offset 12
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?offset=12&limit=10' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a name" { It "Should request with a name" {
$Result = Get-NetboxVirtualizationClusterGroup -Name 'testclustergroup' $Result = Get-NetboxVirtualizationClusterGroup -Name 'testclustergroup'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?name=testclustergroup' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?name=testclustergroup'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should request with a slug" { It "Should request with a slug" {
$Result = Get-NetboxVirtualizationClusterGroup -Slug 'test-cluster-group' $Result = Get-NetboxVirtualizationClusterGroup -Slug 'test-cluster-group'
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'GET' $Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?slug=test-cluster-group' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?slug=test-cluster-group'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
} }
Context -Name "New-NetboxVirtualMachine" -Fixture { Context -Name "New-NetboxVirtualMachine" -Fixture {
It "Should create a basic VM" { It "Should create a basic VM" {
$Result = New-NetboxVirtualMachine -Name 'testvm' -Cluster 1 $Result = New-NetboxVirtualMachine -Name 'testvm' -Cluster 1
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
@ -321,109 +321,109 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"cluster":1,"name":"testvm","status":1}' $Result.Body | Should -Be '{"cluster":1,"name":"testvm","status":1}'
} }
It "Should create a VM with CPUs, Memory, Disk, tenancy, and comments" { It "Should create a VM with CPUs, Memory, Disk, tenancy, and comments" {
$Result = New-NetboxVirtualMachine -Name 'testvm' -Cluster 1 -Status Active -vCPUs 4 -Memory 4096 -Tenant 11 -Disk 50 -Comments "these are comments" $Result = New-NetboxVirtualMachine -Name 'testvm' -Cluster 1 -Status Active -vCPUs 4 -Memory 4096 -Tenant 11 -Disk 50 -Comments "these are comments"
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"tenant":11,"comments":"these are comments","disk":50,"memory":4096,"name":"testvm","cluster":1,"status":1,"vcpus":4}' $Result.Body | Should -Be '{"tenant":11,"comments":"these are comments","disk":50,"memory":4096,"name":"testvm","cluster":1,"status":1,"vcpus":4}'
} }
It "Should throw because of an invalid status" { It "Should throw because of an invalid status" {
{ New-NetboxVirtualMachine -Name 'testvm' -Status 1123 -Cluster 1 } | Should -Throw { New-NetboxVirtualMachine -Name 'testvm' -Status 1123 -Cluster 1 } | Should -Throw
} }
} }
Context -Name "Add-NetboxVirtualMachineInterface" -Fixture { Context -Name "Add-NetboxVirtualMachineInterface" -Fixture {
It "Should add a basic interface" { It "Should add a basic interface" {
$Result = Add-NetboxVirtualMachineInterface -Name 'Ethernet0' -Virtual_Machine 10 $Result = Add-NetboxVirtualMachineInterface -Name 'Ethernet0' -Virtual_Machine 10
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"virtual_machine":10,"name":"Ethernet0","enabled":true}' $Result.Body | Should -Be '{"virtual_machine":10,"name":"Ethernet0","enabled":true}'
} }
It "Should add an interface with a MAC, MTU, and Description" { It "Should add an interface with a MAC, MTU, and Description" {
$Result = Add-NetboxVirtualMachineInterface -Name 'Ethernet0' -Virtual_Machine 10 -Mac_Address '11:22:33:44:55:66' -MTU 1500 -Description "Test description" $Result = Add-NetboxVirtualMachineInterface -Name 'Ethernet0' -Virtual_Machine 10 -Mac_Address '11:22:33:44:55:66' -MTU 1500 -Description "Test description"
Assert-VerifiableMock Assert-VerifiableMock
$Result.Method | Should -Be 'POST' $Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/' $Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"mtu":1500,"description":"Test description","enabled":true,"virtual_machine":10,"name":"Ethernet0","mac_address":"11:22:33:44:55:66"}' $Result.Body | Should -Be '{"mtu":1500,"description":"Test description","enabled":true,"virtual_machine":10,"name":"Ethernet0","mac_address":"11:22:33:44:55:66"}'
} }
} }
Mock -CommandName "Get-NetboxVirtualMachine" -ModuleName NetboxPS -MockWith { Mock -CommandName "Get-NetboxVirtualMachine" -ModuleName NetboxPS -MockWith {
return [pscustomobject]@{ return [pscustomobject]@{
'Id' = $Id 'Id' = $Id
'Name' = $Name 'Name' = $Name
} }
} }
Context -Name "Set-NetboxVirtualMachine" -Fixture { Context -Name "Set-NetboxVirtualMachine" -Fixture {
It "Should set a VM to a new name" { It "Should set a VM to a new name" {
$Result = Set-NetboxVirtualMachine -Id 1234 -Name 'newtestname' -Force $Result = Set-NetboxVirtualMachine -Id 1234 -Name 'newtestname' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"name":"newtestname"}' $Result.Body | Should -Be '{"name":"newtestname"}'
} }
It "Should set a VM with a new name, cluster, platform, and status" { It "Should set a VM with a new name, cluster, platform, and status" {
$Result = Set-NetboxVirtualMachine -Id 1234 -Name 'newtestname' -Cluster 10 -Platform 15 -Status 'Offline' -Force $Result = Set-NetboxVirtualMachine -Id 1234 -Name 'newtestname' -Cluster 10 -Platform 15 -Status 'Offline' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"cluster":10,"platform":15,"name":"newtestname","status":0}' $Result.Body | Should -Be '{"cluster":10,"platform":15,"name":"newtestname","status":0}'
} }
It "Should throw because of an invalid status" { It "Should throw because of an invalid status" {
{ Set-NetboxVirtualMachine -Id 1234 -Status 'Fake' -Force } | Should -Throw { Set-NetboxVirtualMachine -Id 1234 -Status 'Fake' -Force } | Should -Throw
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 0 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 0 -Exactly -Scope 'It'
} }
} }
Mock -CommandName "Get-NetboxVirtualMachineInterface" -ModuleName NetboxPS -MockWith { Mock -CommandName "Get-NetboxVirtualMachineInterface" -ModuleName NetboxPS -MockWith {
return [pscustomobject]@{ return [pscustomobject]@{
'Id' = $Id 'Id' = $Id
'Name' = $Name 'Name' = $Name
} }
} }
Context -Name "Set-NetboxVirtualMachineInterface" -Fixture { Context -Name "Set-NetboxVirtualMachineInterface" -Fixture {
It "Should set an interface to a new name" { It "Should set an interface to a new name" {
$Result = Set-NetboxVirtualMachineInterface -Id 1234 -Name 'newtestname' -Force $Result = Set-NetboxVirtualMachineInterface -Id 1234 -Name 'newtestname' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"name":"newtestname"}' $Result.Body | Should -Be '{"name":"newtestname"}'
} }
It "Should set an interface to a new name, MTU, MAC address and description" { It "Should set an interface to a new name, MTU, MAC address and description" {
$paramSetNetboxVirtualMachineInterface = @{ $paramSetNetboxVirtualMachineInterface = @{
Id = 1234 Id = 1234
@ -433,30 +433,30 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
Description = "Test description" Description = "Test description"
Force = $true Force = $true
} }
$Result = Set-NetboxVirtualMachineInterface @paramSetNetboxVirtualMachineInterface $Result = Set-NetboxVirtualMachineInterface @paramSetNetboxVirtualMachineInterface
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'PATCH' $Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"mac_address":"11:22:33:44:55:66","mtu":9000,"description":"Test description","name":"newtestname"}' $Result.Body | Should -Be '{"mac_address":"11:22:33:44:55:66","mtu":9000,"description":"Test description","name":"newtestname"}'
} }
It "Should set multiple interfaces to a new name" { It "Should set multiple interfaces to a new name" {
$Result = Set-NetboxVirtualMachineInterface -Id 1234, 4321 -Name 'newtestname' -Force $Result = Set-NetboxVirtualMachineInterface -Id 1234, 4321 -Name 'newtestname' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/', 'https://netbox.domain.com/api/virtualization/interfaces/4321/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/', 'https://netbox.domain.com/api/virtualization/interfaces/4321/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}' $Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}'
} }
It "Should set multiple interfaces to a new name from the pipeline" { It "Should set multiple interfaces to a new name from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -466,51 +466,51 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
'Id' = 4321 'Id' = 4321
} }
) | Set-NetboxVirtualMachineInterface -Name 'newtestname' -Force ) | Set-NetboxVirtualMachineInterface -Name 'newtestname' -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly
$Result.Method | Should -Be 'PATCH', 'PATCH' $Result.Method | Should -Be 'PATCH', 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/4123/', 'https://netbox.domain.com/api/virtualization/interfaces/4321/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/4123/', 'https://netbox.domain.com/api/virtualization/interfaces/4321/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}' $Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}'
} }
} }
Context -Name "Remove-NetboxVirtualMachine" -Fixture { Context -Name "Remove-NetboxVirtualMachine" -Fixture {
It "Should remove a single VM" { It "Should remove a single VM" {
$Result = Remove-NetboxVirtualMachine -Id 4125 -Force $Result = Remove-NetboxVirtualMachine -Id 4125 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove mulitple VMs" { It "Should remove mulitple VMs" {
$Result = Remove-NetboxVirtualMachine -Id 4125, 4132 -Force $Result = Remove-NetboxVirtualMachine -Id 4125, 4132 -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/', 'https://netbox.domain.com/api/virtualization/virtual-machines/4132/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/', 'https://netbox.domain.com/api/virtualization/virtual-machines/4132/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2
} }
It "Should remove a VM from the pipeline" { It "Should remove a VM from the pipeline" {
$Result = Get-NetboxVirtualMachine -Id 4125 | Remove-NetboxVirtualMachine -Force $Result = Get-NetboxVirtualMachine -Id 4125 | Remove-NetboxVirtualMachine -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE' $Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/'
$Result.Headers.Keys.Count | Should -BeExactly 1 $Result.Headers.Keys.Count | Should -BeExactly 1
} }
It "Should remove multiple VMs from the pipeline" { It "Should remove multiple VMs from the pipeline" {
$Result = @( $Result = @(
[pscustomobject]@{ [pscustomobject]@{
@ -520,10 +520,10 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
'Id' = 4132 'Id' = 4132
} }
) | Remove-NetboxVirtualMachine -Force ) | Remove-NetboxVirtualMachine -Force
Assert-VerifiableMock Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It' Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE', 'DELETE' $Result.Method | Should -Be 'DELETE', 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/', 'https://netbox.domain.com/api/virtualization/virtual-machines/4132/' $Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/', 'https://netbox.domain.com/api/virtualization/virtual-machines/4132/'
$Result.Headers.Keys.Count | Should -BeExactly 2 $Result.Headers.Keys.Count | Should -BeExactly 2

View file

@ -1,19 +1,32 @@
<# <#
.SYNOPSIS .SYNOPSIS
A brief description of the Invoke-deploy_ps1 file. Concatenate files into single PSM1 and PSD1 files
.DESCRIPTION .DESCRIPTION
A description of the file. Concatenate all ps1 files in the Functions directory, plus the root PSM1,
into a single PSM1 file in the NetboxPS directory.
By default, this script will increment version by 0.0.1
.PARAMETER SkipVersion .PARAMETER SkipVersion
A description of the SkipVersion parameter. Do not increment the version.
.PARAMETER VersionIncrease .PARAMETER VersionIncrease
A description of the VersionIncrease parameter. Increase the version by a user defined amount
.PARAMETER NewVersion .PARAMETER NewVersion
A description of the NewVersion parameter. Override the new version with this version
.EXAMPLE
Use all defaults and concatenate all files
.\deploy.ps1
.EXAMPLE
Increment the version by 0.2.0. Given version 1.2.0, the resulting version will be 1.4.0
.\deploy.ps1 -VersionIncrease 0.2.0
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174