Restructure files

This commit is contained in:
Ben Claussen 2020-03-23 12:18:01 -04:00
parent 002feadb4a
commit 9f543b8f2d
66 changed files with 8277 additions and 7228 deletions

View file

@ -11,97 +11,4 @@
Circuit object functions Circuit object functions
#> #>
function Get-NetboxCircuitsChoices {
<#
.SYNOPSIS
Gets the choices associated with circuits
.DESCRIPTION
A detailed description of the Get-NetboxCircuitsChoices function.
.EXAMPLE
PS C:\> Get-NetboxCircuitsChoices
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('circuits', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}
function Get-NetboxCircuit {
<#
.SYNOPSIS
Gets one or more circuits
.DESCRIPTION
A detailed description of the Get-NetboxCircuit function.
.PARAMETER CID
Circuit ID
.PARAMETER InstallDate
Date of installation
.PARAMETER CommitRate
Committed rate in Kbps
.PARAMETER Query
A raw search query... As if you were searching the web site
.PARAMETER Provider
The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs
.PARAMETER Type
Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs
.PARAMETER Site
Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs
.PARAMETER Tenant
Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs
.PARAMETER Id
Database ID of circuit. This will query for exactly the IDs provided
.PARAMETER ID__IN
Multiple unique DB IDs to retrieve
.EXAMPLE
PS C:\> Get-NetboxCircuit
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[string]$CID,
[datetime]$InstallDate,
[uint32]$CommitRate,
[string]$Query,
[object]$Provider,
[object]$Type,
[string]$Site,
[string]$Tenant,
[uint16[]]$Id
)
#TODO: Place script here
}

View file

@ -0,0 +1,83 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:15
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuit.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuit {
<#
.SYNOPSIS
Gets one or more circuits
.DESCRIPTION
A detailed description of the Get-NetboxCircuit function.
.PARAMETER CID
Circuit ID
.PARAMETER InstallDate
Date of installation
.PARAMETER CommitRate
Committed rate in Kbps
.PARAMETER Query
A raw search query... As if you were searching the web site
.PARAMETER Provider
The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs
.PARAMETER Type
Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs
.PARAMETER Site
Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs
.PARAMETER Tenant
Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs
.PARAMETER Id
Database ID of circuit. This will query for exactly the IDs provided
.PARAMETER ID__IN
Multiple unique DB IDs to retrieve
.EXAMPLE
PS C:\> Get-NetboxCircuit
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[string]$CID,
[datetime]$InstallDate,
[uint32]$CommitRate,
[string]$Query,
[object]$Provider,
[object]$Type,
[string]$Site,
[string]$Tenant,
[uint16[]]$Id
)
#TODO: Place script here
}

View file

@ -0,0 +1,38 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:15
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuitsChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuitsChoices {
<#
.SYNOPSIS
Gets the choices associated with circuits
.DESCRIPTION
A detailed description of the Get-NetboxCircuitsChoices function.
.EXAMPLE
PS C:\> Get-NetboxCircuitsChoices
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('circuits', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}

View file

@ -1,428 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
Created on: 5/25/2018 2:52 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: DCIM.Devices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
#region GET commands
function Get-NetboxDCIMDevice {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Query,
[string]$Name,
[uint16]$Manufacturer_Id,
[string]$Manufacturer,
[uint16]$Device_Type_Id,
[uint16]$Role_Id,
[string]$Role,
[uint16]$Tenant_Id,
[string]$Tenant,
[uint16]$Platform_Id,
[string]$Platform,
[string]$Asset_Tag,
[uint16]$Site_Id,
[string]$Site,
[uint16]$Rack_Group_Id,
[uint16]$Rack_Id,
[uint16]$Cluster_Id,
[uint16]$Model,
[object]$Status,
[bool]$Is_Full_Depth,
[bool]$Is_Console_Server,
[bool]$Is_PDU,
[bool]$Is_Network_Device,
[string]$MAC_Address,
[bool]$Has_Primary_IP,
[uint16]$Virtual_Chassis_Id,
[uint16]$Position,
[string]$Serial,
[switch]$Raw
)
#endregion Parameters
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
}
function Get-NetboxDCIMDeviceType {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Offset,
[uint16]$Limit,
[uint16[]]$Id,
[string]$Query,
[string]$Slug,
[string]$Manufacturer,
[uint16]$Manufacturer_Id,
[string]$Model,
[string]$Part_Number,
[uint16]$U_Height,
[bool]$Is_Full_Depth,
[bool]$Is_Console_Server,
[bool]$Is_PDU,
[bool]$Is_Network_Device,
[uint16]$Subdevice_Role,
[switch]$Raw
)
#endregion Parameters
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
function Get-NetboxDCIMDeviceRole {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
[string]$Name,
[string]$Slug,
[string]$Color,
[bool]$VM_Role,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($DRId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles', $DRId))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
break
}
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}
#endregion GET commands
#region NEW commands
function New-NetboxDCIMDevice {
[CmdletBinding()]
[OutputType([pscustomobject])]
#region Parameters
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[object]$Device_Role,
[Parameter(Mandatory = $true)]
[object]$Device_Type,
[Parameter(Mandatory = $true)]
[uint16]$Site,
[object]$Status = 'Active',
[uint16]$Platform,
[uint16]$Tenant,
[uint16]$Cluster,
[uint16]$Rack,
[uint16]$Position,
[object]$Face,
[string]$Serial,
[string]$Asset_Tag,
[uint16]$Virtual_Chassis,
[uint16]$VC_Priority,
[uint16]$VC_Position,
[uint16]$Primary_IP4,
[uint16]$Primary_IP6,
[string]$Comments,
[hashtable]$Custom_Fields
)
#endregion Parameters
if ($null -ne $Device_Role) {
# Validate device role?
}
if ($null -ne $Device_Type) {
# Validate device type?
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
if ($null -ne $Face) {
$PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
#endregion NEW commands
#region SET commands
function Set-NetboxDCIMDevice {
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Name,
[object]$Device_Role,
[object]$Device_Type,
[uint16]$Site,
[object]$Status,
[uint16]$Platform,
[uint16]$Tenant,
[uint16]$Cluster,
[uint16]$Rack,
[uint16]$Position,
[object]$Face,
[string]$Serial,
[string]$Asset_Tag,
[uint16]$Virtual_Chassis,
[uint16]$VC_Priority,
[uint16]$VC_Position,
[uint16]$Primary_IP4,
[uint16]$Primary_IP6,
[string]$Comments,
[hashtable]$Custom_Fields,
[switch]$Force
)
begin {
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
if ($null -ne $Face) {
$PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
}
}
process {
foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}
#endregion SET commands
#region REMOVE commands
function Remove-NetboxDCIMDevice {
<#
.SYNOPSIS
Delete a device
.DESCRIPTION
Deletes a device from Netbox by ID
.PARAMETER Id
Database ID of the device
.PARAMETER Force
Force deletion without any prompts
.EXAMPLE
PS C:\> Remove-NetboxDCIMDevice -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentDevice.Name) | ID: $($CurrentDevice.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}
#endregion REMOVE commands

View file

@ -1,495 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
Created on: 5/25/2018 2:57 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: DCIM.Interfaces.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
#region GET Commands
function Get-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16]$Id,
[uint16]$Name,
[object]$Form_Factor,
[bool]$Enabled,
[uint16]$MTU,
[bool]$MGMT_Only,
[string]$Device,
[uint16]$Device_Id,
[uint16]$Type,
[uint16]$LAG_Id,
[string]$MAC_Address,
[switch]$Raw
)
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
}
function Get-NetboxDCIMInterfaceConnection {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
[uint16]$Offset,
[uint16]$Id,
[object]$Connection_Status,
[uint16]$Site,
[uint16]$Device,
[switch]$Raw
)
if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
#endregion GET Commands
#region ADD/NEW commands
function Add-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[uint16]$Device,
[Parameter(Mandatory = $true)]
[string]$Name,
[bool]$Enabled,
[object]$Form_Factor,
[uint16]$MTU,
[string]$MAC_Address,
[bool]$MGMT_Only,
[uint16]$LAG,
[string]$Description,
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode,
[ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN,
[ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs
)
if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {
'Access' {
100
break
}
'Tagged' {
200
break
}
'Tagged All' {
300
break
}
default {
$_
}
}
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
function Add-NetboxDCIMInterfaceConnection {
<#
.SYNOPSIS
Create a new connection between two interfaces
.DESCRIPTION
Create a new connection between two interfaces
.PARAMETER Connection_Status
Is it connected or planned?
.PARAMETER Interface_A
Database ID of interface A
.PARAMETER Interface_B
Database ID of interface B
.EXAMPLE
PS C:\> Add-NetboxDCIMInterfaceConnection -Interface_A $value1 -Interface_B $value2
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[object]$Connection_Status,
[Parameter(Mandatory = $true)]
[uint16]$Interface_A,
[Parameter(Mandatory = $true)]
[uint16]$Interface_B
)
if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
}
# Verify if both Interfaces exist
$I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop
$I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
#endregion ADD/NEW commands
#region SET Commands
function Set-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[uint16]$Device,
[string]$Name,
[bool]$Enabled,
[object]$Form_Factor,
[uint16]$MTU,
[string]$MAC_Address,
[bool]$MGMT_Only,
[uint16]$LAG,
[string]$Description,
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode,
[ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN,
[ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs
)
begin {
if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {
'Access' {
100
break
}
'Tagged' {
200
break
}
'Tagged All' {
300
break
}
default {
$_
}
}
}
}
process {
foreach ($InterfaceId in $Id) {
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
end {
}
}
function Set-NetboxDCIMInterfaceConnection {
<#
.SYNOPSIS
Update an interface connection
.DESCRIPTION
Update an interface connection
.PARAMETER Id
A description of the Id parameter.
.PARAMETER Connection_Status
A description of the Connection_Status parameter.
.PARAMETER Interface_A
A description of the Interface_A parameter.
.PARAMETER Interface_B
A description of the Interface_B parameter.
.PARAMETER Force
A description of the Force parameter.
.EXAMPLE
PS C:\> Set-NetboxDCIMInterfaceConnection -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[object]$Connection_Status,
[uint16]$Interface_A,
[uint16]$Interface_B,
[switch]$Force
)
begin {
if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
}
if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) {
throw "Cannot set multiple connections to the same interface"
}
}
process {
foreach ($ConnectionID in $Id) {
$CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id))
if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($CurrentConnection.Id)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}
#endregion SET Commands
#region REMOVE commands
function Remove-NetboxDCIMInterface {
<#
.SYNOPSIS
Removes an interface
.DESCRIPTION
Removes an interface by ID from a device
.PARAMETER Id
A description of the Id parameter.
.PARAMETER Force
A description of the Force parameter.
.EXAMPLE
PS C:\> Remove-NetboxDCIMInterface -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($InterfaceId in $Id) {
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentInterface.Name) | ID: $($CurrentInterface.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}
function Remove-NetboxDCIMInterfaceConnection {
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
[OutputType([void])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($ConnectionID in $Id) {
$CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($ConnectionID.Id)", "REMOVE")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}
#endregion REMOVE commands

View file

@ -0,0 +1,99 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:06
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMDevice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMDevice {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Query,
[string]$Name,
[uint16]$Manufacturer_Id,
[string]$Manufacturer,
[uint16]$Device_Type_Id,
[uint16]$Role_Id,
[string]$Role,
[uint16]$Tenant_Id,
[string]$Tenant,
[uint16]$Platform_Id,
[string]$Platform,
[string]$Asset_Tag,
[uint16]$Site_Id,
[string]$Site,
[uint16]$Rack_Group_Id,
[uint16]$Rack_Id,
[uint16]$Cluster_Id,
[uint16]$Model,
[object]$Status,
[bool]$Is_Full_Depth,
[bool]$Is_Console_Server,
[bool]$Is_PDU,
[bool]$Is_Network_Device,
[string]$MAC_Address,
[bool]$Has_Primary_IP,
[uint16]$Virtual_Chassis_Id,
[uint16]$Position,
[string]$Serial,
[switch]$Raw
)
#endregion Parameters
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
}

View file

@ -0,0 +1,62 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:07
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMDeviceRole.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMDeviceRole {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
[string]$Name,
[string]$Slug,
[string]$Color,
[bool]$VM_Role,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($DRId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles', $DRId))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
break
}
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}

View file

@ -0,0 +1,61 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:07
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMDeviceType.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMDeviceType {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Offset,
[uint16]$Limit,
[uint16[]]$Id,
[string]$Query,
[string]$Slug,
[string]$Manufacturer,
[uint16]$Manufacturer_Id,
[string]$Model,
[string]$Part_Number,
[uint16]$U_Height,
[bool]$Is_Full_Depth,
[bool]$Is_Console_Server,
[bool]$Is_PDU,
[bool]$Is_Network_Device,
[uint16]$Subdevice_Role,
[switch]$Raw
)
#endregion Parameters
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}

View file

@ -0,0 +1,90 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:08
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxDCIMDevice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function New-NetboxDCIMDevice {
[CmdletBinding()]
[OutputType([pscustomobject])]
#region Parameters
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[object]$Device_Role,
[Parameter(Mandatory = $true)]
[object]$Device_Type,
[Parameter(Mandatory = $true)]
[uint16]$Site,
[object]$Status = 'Active',
[uint16]$Platform,
[uint16]$Tenant,
[uint16]$Cluster,
[uint16]$Rack,
[uint16]$Position,
[object]$Face,
[string]$Serial,
[string]$Asset_Tag,
[uint16]$Virtual_Chassis,
[uint16]$VC_Priority,
[uint16]$VC_Position,
[uint16]$Primary_IP4,
[uint16]$Primary_IP6,
[string]$Comments,
[hashtable]$Custom_Fields
)
#endregion Parameters
if ($null -ne $Device_Role) {
# Validate device role?
}
if ($null -ne $Device_Type) {
# Validate device type?
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
if ($null -ne $Face) {
$PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}

View file

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

View file

@ -0,0 +1,95 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:08
Created by: Claussen
Organization: NEOnet
Filename: Set-NetboxDCIMDevice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Set-NetboxDCIMDevice {
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Name,
[object]$Device_Role,
[object]$Device_Type,
[uint16]$Site,
[object]$Status,
[uint16]$Platform,
[uint16]$Tenant,
[uint16]$Cluster,
[uint16]$Rack,
[uint16]$Position,
[object]$Face,
[string]$Serial,
[string]$Asset_Tag,
[uint16]$Virtual_Chassis,
[uint16]$VC_Priority,
[uint16]$VC_Position,
[uint16]$Primary_IP4,
[uint16]$Primary_IP6,
[string]$Comments,
[hashtable]$Custom_Fields,
[switch]$Force
)
begin {
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
if ($null -ne $Face) {
$PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
}
}
process {
foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}

View file

@ -0,0 +1,25 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:13
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('dcim', '_choices'))
$uri = BuildNewURI -Segments $uriSegments -Parameters $Parameters
InvokeNetboxRequest -URI $uri
}

View file

@ -1,30 +1,16 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 5/22/2018 4:47 PM Created on: 3/23/2020 12:13
Created by: Ben Claussen Created by: Claussen
Organization: NEOnet Organization: NEOnet
Filename: DCIM.ps1 Filename: Get-NetboxDCIMPlatform.ps1
=========================================================================== ===========================================================================
.DESCRIPTION .DESCRIPTION
A description of the file. A description of the file.
#> #>
function Get-NetboxDCIMChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('dcim', '_choices'))
$uri = BuildNewURI -Segments $uriSegments -Parameters $Parameters
InvokeNetboxRequest -URI $uri
}
#region GET commands
function Get-NetboxDCIMPlatform { function Get-NetboxDCIMPlatform {
[CmdletBinding()] [CmdletBinding()]
@ -74,33 +60,4 @@ function Get-NetboxDCIMPlatform {
InvokeNetboxRequest -URI $URI -Raw:$Raw InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
} }
} }
#endregion GET commands
#region NEW/ADD commands
#endregion NEW/ADD commands
#region SET commands
#endregion SET commands
#region REMOVE commands
#endregion REMOVE commands

View file

@ -0,0 +1,84 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:10
Created by: Claussen
Organization: NEOnet
Filename: Add-NetboxDCIMInterface.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Add-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[uint16]$Device,
[Parameter(Mandatory = $true)]
[string]$Name,
[bool]$Enabled,
[object]$Form_Factor,
[uint16]$MTU,
[string]$MAC_Address,
[bool]$MGMT_Only,
[uint16]$LAG,
[string]$Description,
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode,
[ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN,
[ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs
)
if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {
'Access' {
100
break
}
'Tagged' {
200
break
}
'Tagged All' {
300
break
}
default {
$_
}
}
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}

View file

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

View file

@ -0,0 +1,61 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:09
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMInterface.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16]$Id,
[uint16]$Name,
[object]$Form_Factor,
[bool]$Enabled,
[uint16]$MTU,
[bool]$MGMT_Only,
[string]$Device,
[uint16]$Device_Id,
[uint16]$Type,
[uint16]$LAG_Id,
[string]$MAC_Address,
[switch]$Raw
)
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
}

View file

@ -0,0 +1,46 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:10
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMInterfaceConnection.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMInterfaceConnection {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
[uint16]$Offset,
[uint16]$Id,
[object]$Connection_Status,
[uint16]$Site,
[uint16]$Device,
[switch]$Raw
)
if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
}
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}

View file

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

View file

@ -0,0 +1,51 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:12
Created by: Claussen
Organization: NEOnet
Filename: Remove-NetboxDCIMInterfaceConnection.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Remove-NetboxDCIMInterfaceConnection {
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
[OutputType([void])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($ConnectionID in $Id) {
$CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($ConnectionID.Id)", "REMOVE")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}

View file

@ -0,0 +1,98 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:11
Created by: Claussen
Organization: NEOnet
Filename: Set-NetboxDCIMInterface.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Set-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[uint16]$Device,
[string]$Name,
[bool]$Enabled,
[object]$Form_Factor,
[uint16]$MTU,
[string]$MAC_Address,
[bool]$MGMT_Only,
[uint16]$LAG,
[string]$Description,
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode,
[ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN,
[ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs
)
begin {
if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {
'Access' {
100
break
}
'Tagged' {
200
break
}
'Tagged All' {
300
break
}
default {
$_
}
}
}
}
process {
foreach ($InterfaceId in $Id) {
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
end {
}
}

View file

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

View file

@ -233,7 +233,7 @@ function GetChoiceValidValues {
function ValidateChoice { function ValidateChoice {
[CmdletBinding()] [CmdletBinding()]
[OutputType([uint16],[string], [bool])] [OutputType([uint16], [string], [bool])]
param param
( (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]

View file

@ -0,0 +1,63 @@
function Get-NetboxIPAMAddress {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[object]$Family,
[uint16[]]$Id,
[string]$Query,
[uint16]$Parent,
[byte]$Mask_Length,
[string]$VRF,
[uint16]$VRF_Id,
[string]$Tenant,
[uint16]$Tenant_Id,
[string]$Device,
[uint16]$Device_ID,
[string]$Virtual_Machine,
[uint16]$Virtual_Machine_Id,
[uint16]$Interface_Id,
[object]$Status,
[object]$Role,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -IPAddressFamily
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
}
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -0,0 +1,64 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:50
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxIPAMAvailableIP.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxIPAMAvailableIP {
<#
.SYNOPSIS
A convenience method for returning available IP addresses within a prefix
.DESCRIPTION
By default, the number of IPs returned will be equivalent to PAGINATE_COUNT. An arbitrary limit
(up to MAX_PAGE_SIZE, if set) may be passed, however results will not be paginated
.PARAMETER Prefix_ID
A description of the Prefix_ID parameter.
.PARAMETER Limit
A description of the Limit parameter.
.PARAMETER Raw
A description of the Raw parameter.
.PARAMETER NumberOfIPs
A description of the NumberOfIPs parameter.
.EXAMPLE
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias('Id')]
[uint16]$Prefix_ID,
[Alias('NumberOfIPs')]
[uint16]$Limit,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID, 'available-ips'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'prefix_id'
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -0,0 +1,99 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:51
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxIPAMAddress.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function New-NetboxIPAMAddress {
<#
.SYNOPSIS
Create a new IP address to Netbox
.DESCRIPTION
Create a new IP address to Netbox with a status of Active by default.
.PARAMETER Address
IP address in CIDR notation: 192.168.1.1/24
.PARAMETER Status
Status of the IP. Defaults to Active
.PARAMETER Tenant
Tenant ID
.PARAMETER VRF
VRF ID
.PARAMETER Role
Role such as anycast, loopback, etc... Defaults to nothing
.PARAMETER NAT_Inside
ID of IP for NAT
.PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service
.PARAMETER Interface
ID of interface to apply IP
.PARAMETER Description
Description of IP address
.PARAMETER Raw
Return raw results from API service
.EXAMPLE
PS C:\> Create-NetboxIPAMAddress
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Address,
[object]$Status = 'Active',
[uint16]$Tenant,
[uint16]$VRF,
[object]$Role,
[uint16]$NAT_Inside,
[hashtable]$Custom_Fields,
[uint16]$Interface,
[string]$Description,
[switch]$Raw
)
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
$segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}

View file

@ -0,0 +1,65 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:52
Created by: Claussen
Organization: NEOnet
Filename: Remove-NetboxIPAMAddress.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Remove-NetboxIPAMAddress {
<#
.SYNOPSIS
Remove an IP address from Netbox
.DESCRIPTION
Removes/deletes an IP address from Netbox by ID and optional other filters
.PARAMETER Id
Database ID of the IP address object.
.PARAMETER Force
Do not confirm.
.EXAMPLE
PS C:\> Remove-NetboxIPAMAddress -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($IPId in $Id) {
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
if ($Force -or $pscmdlet.ShouldProcess($CurrentIP.Address, "Delete")) {
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}

View file

@ -0,0 +1,74 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:53
Created by: Claussen
Organization: NEOnet
Filename: Set-NetboxIPAMAddress.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Set-NetboxIPAMAddress {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Address,
[object]$Status,
[uint16]$Tenant,
[uint16]$VRF,
[object]$Role,
[uint16]$NAT_Inside,
[hashtable]$Custom_Fields,
[uint16]$Interface,
[string]$Description,
[switch]$Force
)
begin {
if ($Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
}
if ($Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
}
process {
foreach ($IPId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
Write-Verbose "Obtaining IPs from ID $IPId"
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentIP.Address, 'Set')) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}

View file

@ -0,0 +1,49 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:49
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxIPAMAggregate.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxIPAMAggregate {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[object]$Family,
[datetime]$Date_Added,
[uint16[]]$Id,
[string]$Query,
[uint16]$RIR_Id,
[string]$RIR,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -0,0 +1,25 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:54
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxIPAMChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxIPAMChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', '_choices'))
$uri = BuildNewURI -Segments $uriSegments -Parameters $Parameters
InvokeNetboxRequest -URI $uri
}

View file

@ -1,597 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
Created on: 5/10/2018 3:41 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: IPAM.ps1
===========================================================================
.DESCRIPTION
IPAM Object functions
#>
function Get-NetboxIPAMChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', '_choices'))
$uri = BuildNewURI -Segments $uriSegments -Parameters $Parameters
InvokeNetboxRequest -URI $uri
}
#region GET commands
function Get-NetboxIPAMAggregate {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[object]$Family,
[datetime]$Date_Added,
[uint16[]]$Id,
[string]$Query,
[uint16]$RIR_Id,
[string]$RIR,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
function Get-NetboxIPAMAddress {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[object]$Family,
[uint16[]]$Id,
[string]$Query,
[uint16]$Parent,
[byte]$Mask_Length,
[string]$VRF,
[uint16]$VRF_Id,
[string]$Tenant,
[uint16]$Tenant_Id,
[string]$Device,
[uint16]$Device_ID,
[string]$Virtual_Machine,
[uint16]$Virtual_Machine_Id,
[uint16]$Interface_Id,
[object]$Status,
[object]$Role,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -IPAddressFamily
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
}
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
function Get-NetboxIPAMAvailableIP {
<#
.SYNOPSIS
A convenience method for returning available IP addresses within a prefix
.DESCRIPTION
By default, the number of IPs returned will be equivalent to PAGINATE_COUNT. An arbitrary limit
(up to MAX_PAGE_SIZE, if set) may be passed, however results will not be paginated
.PARAMETER Prefix_ID
A description of the Prefix_ID parameter.
.PARAMETER Limit
A description of the Limit parameter.
.PARAMETER Raw
A description of the Raw parameter.
.PARAMETER NumberOfIPs
A description of the NumberOfIPs parameter.
.EXAMPLE
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias('Id')]
[uint16]$Prefix_ID,
[Alias('NumberOfIPs')]
[uint16]$Limit,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID, 'available-ips'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'prefix_id'
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
function Get-NetboxIPAMPrefix {
<#
.SYNOPSIS
A brief description of the Get-NetboxIPAMPrefix function.
.DESCRIPTION
A detailed description of the Get-NetboxIPAMPrefix function.
.PARAMETER Limit
A description of the Limit parameter.
.PARAMETER Offset
A description of the Offset parameter.
.PARAMETER Family
A description of the Family parameter.
.PARAMETER Is_Pool
A description of the Is_Pool parameter.
.PARAMETER Id
A description of the Id parameter.
.PARAMETER Query
A description of the Query parameter.
.PARAMETER Within
Should be a CIDR notation prefix such as '10.0.0.0/16'
.PARAMETER Within_Include
Should be a CIDR notation prefix such as '10.0.0.0/16'
.PARAMETER Contains
A description of the Contains parameter.
.PARAMETER Mask_Length
CIDR mask length value
.PARAMETER VRF
A description of the VRF parameter.
.PARAMETER VRF_Id
A description of the VRF_Id parameter.
.PARAMETER Tenant
A description of the Tenant parameter.
.PARAMETER Tenant_Id
A description of the Tenant_Id parameter.
.PARAMETER Site
A description of the Site parameter.
.PARAMETER Site_Id
A description of the Site_Id parameter.
.PARAMETER Vlan_VId
A description of the Vlan_VId parameter.
.PARAMETER Vlan_Id
A description of the Vlan_Id parameter.
.PARAMETER Status
A description of the Status parameter.
.PARAMETER Role
A description of the Role parameter.
.PARAMETER Role_Id
A description of the Role_Id parameter.
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxIPAMPrefix
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[object]$Family,
[boolean]$Is_Pool,
[uint16[]]$Id,
[string]$Query,
[string]$Within,
[string]$Within_Include,
[string]$Contains,
[ValidateRange(0, 127)]
[byte]$Mask_Length,
[string]$VRF,
[uint16]$VRF_Id,
[string]$Tenant,
[uint16]$Tenant_Id,
[string]$Site,
[uint16]$Site_Id,
[string]$Vlan_VId,
[uint16]$Vlan_Id,
[object]$Status,
[string]$Role,
[uint16]$Role_Id,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
#endregion GET commands
#region NEW commands
function New-NetboxIPAMAddress {
<#
.SYNOPSIS
Create a new IP address to Netbox
.DESCRIPTION
Create a new IP address to Netbox with a status of Active by default.
.PARAMETER Address
IP address in CIDR notation: 192.168.1.1/24
.PARAMETER Status
Status of the IP. Defaults to Active
.PARAMETER Tenant
Tenant ID
.PARAMETER VRF
VRF ID
.PARAMETER Role
Role such as anycast, loopback, etc... Defaults to nothing
.PARAMETER NAT_Inside
ID of IP for NAT
.PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service
.PARAMETER Interface
ID of interface to apply IP
.PARAMETER Description
Description of IP address
.PARAMETER Raw
Return raw results from API service
.EXAMPLE
PS C:\> Create-NetboxIPAMAddress
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Address,
[object]$Status = 'Active',
[uint16]$Tenant,
[uint16]$VRF,
[object]$Role,
[uint16]$NAT_Inside,
[hashtable]$Custom_Fields,
[uint16]$Interface,
[string]$Description,
[switch]$Raw
)
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
$segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}
function New-NetboxIPAMPrefix {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Prefix,
[object]$Status = 'Active',
[uint16]$Tenant,
[object]$Role,
[bool]$IsPool,
[string]$Description,
[uint16]$Site,
[uint16]$VRF,
[uint16]$VLAN,
[hashtable]$Custom_Fields,
[switch]$Raw
)
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
<#
# As of 2018/10/18, this does not appear to be a validated IPAM choice
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -PrefixRole
}
#>
$segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}
#endregion ADD commands
#region REMOVE commands
function Remove-NetboxIPAMAddress {
<#
.SYNOPSIS
Remove an IP address from Netbox
.DESCRIPTION
Removes/deletes an IP address from Netbox by ID and optional other filters
.PARAMETER Id
Database ID of the IP address object.
.PARAMETER Force
Do not confirm.
.EXAMPLE
PS C:\> Remove-NetboxIPAMAddress -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($IPId in $Id) {
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
if ($Force -or $pscmdlet.ShouldProcess($CurrentIP.Address, "Delete")) {
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}
#endregion REMOVE commands
#region SET commands
function Set-NetboxIPAMAddress {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Address,
[object]$Status,
[uint16]$Tenant,
[uint16]$VRF,
[object]$Role,
[uint16]$NAT_Inside,
[hashtable]$Custom_Fields,
[uint16]$Interface,
[string]$Description,
[switch]$Force
)
begin {
if ($Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
}
if ($Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
}
process{
foreach ($IPId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
Write-Verbose "Obtaining IPs from ID $IPId"
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentIP.Address, 'Set')) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end{
}
}
#endregion SET commands

View file

@ -0,0 +1,160 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:51
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxIPAMPrefix.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxIPAMPrefix {
<#
.SYNOPSIS
A brief description of the Get-NetboxIPAMPrefix function.
.DESCRIPTION
A detailed description of the Get-NetboxIPAMPrefix function.
.PARAMETER Limit
A description of the Limit parameter.
.PARAMETER Offset
A description of the Offset parameter.
.PARAMETER Family
A description of the Family parameter.
.PARAMETER Is_Pool
A description of the Is_Pool parameter.
.PARAMETER Id
A description of the Id parameter.
.PARAMETER Query
A description of the Query parameter.
.PARAMETER Within
Should be a CIDR notation prefix such as '10.0.0.0/16'
.PARAMETER Within_Include
Should be a CIDR notation prefix such as '10.0.0.0/16'
.PARAMETER Contains
A description of the Contains parameter.
.PARAMETER Mask_Length
CIDR mask length value
.PARAMETER VRF
A description of the VRF parameter.
.PARAMETER VRF_Id
A description of the VRF_Id parameter.
.PARAMETER Tenant
A description of the Tenant parameter.
.PARAMETER Tenant_Id
A description of the Tenant_Id parameter.
.PARAMETER Site
A description of the Site parameter.
.PARAMETER Site_Id
A description of the Site_Id parameter.
.PARAMETER Vlan_VId
A description of the Vlan_VId parameter.
.PARAMETER Vlan_Id
A description of the Vlan_Id parameter.
.PARAMETER Status
A description of the Status parameter.
.PARAMETER Role
A description of the Role parameter.
.PARAMETER Role_Id
A description of the Role_Id parameter.
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxIPAMPrefix
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[object]$Family,
[boolean]$Is_Pool,
[uint16[]]$Id,
[string]$Query,
[string]$Within,
[string]$Within_Include,
[string]$Contains,
[ValidateRange(0, 127)]
[byte]$Mask_Length,
[string]$VRF,
[uint16]$VRF_Id,
[string]$Tenant,
[uint16]$Tenant_Id,
[string]$Site,
[uint16]$Site_Id,
[string]$Vlan_VId,
[uint16]$Vlan_Id,
[object]$Status,
[string]$Role,
[uint16]$Role_Id,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -0,0 +1,59 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:52
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxIPAMPrefix.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function New-NetboxIPAMPrefix {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Prefix,
[object]$Status = 'Active',
[uint16]$Tenant,
[object]$Role,
[bool]$IsPool,
[string]$Description,
[uint16]$Site,
[uint16]$VRF,
[uint16]$VLAN,
[hashtable]$Custom_Fields,
[switch]$Raw
)
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
<#
# As of 2018/10/18, this does not appear to be a validated IPAM choice
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -PrefixRole
}
#>
$segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}

View file

@ -0,0 +1,68 @@

function Get-NetboxIPAMRole {
<#
.SYNOPSIS
Get IPAM Prefix/VLAN roles
.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).
.PARAMETER Id
Unique ID
.PARAMETER Query
Search query
.PARAMETER Name
Role name
.PARAMETER Slug
Role URL slug
.PARAMETER Brief
Brief format
.PARAMETER Limit
Result limit
.PARAMETER Offset
Result offset
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxIPAMRole
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16[]]$Id,
[string]$Query,
[string]$Name,
[string]$Slug,
[switch]$Brief,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -0,0 +1,73 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/16/2020 16:34
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxIPAMVLAN.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxIPAMVLAN {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[uint16]$VID,
[uint16[]]$Id,
[string]$Query,
[string]$Name,
[string]$Tenant,
[uint16]$Tenant_Id,
[string]$TenantGroup,
[uint16]$TenantGroup_Id,
[object]$Status,
[string]$Region,
[string]$Site,
[uint16]$Site_Id,
[string]$Group,
[uint16]$Group_Id,
[string]$Role,
[uint16]$Role_Id,
[switch]$Raw
)
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

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

View file

@ -1,4 +1,18 @@
function ValidateIPAMChoice { <#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:54
Created by: Claussen
Organization: NEOnet
Filename: ValidateIPAMChoice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function ValidateIPAMChoice {
<# <#
.SYNOPSIS .SYNOPSIS
Internal function to verify provided values for static choices Internal function to verify provided values for static choices
@ -92,4 +106,4 @@
) )
ValidateChoice -MajorObject 'IPAM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue ValidateChoice -MajorObject 'IPAM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue
} }

View file

@ -0,0 +1,25 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:56
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxTenancyChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxTenancyChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('tenancy', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}

View file

@ -0,0 +1,45 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:56
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxTenant.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxTenant {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[string]$Name,
[uint16[]]$Id,
[string]$Query,
[string]$Group,
[uint16]$GroupID,
[hashtable]$CustomFields,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -11,52 +11,12 @@
A description of the file. A description of the file.
#> #>
function Get-NetboxTenancyChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('tenancy', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}
#region GET commands #region GET commands
function Get-NetboxTenant {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[string]$Name,
[uint16[]]$Id,
[string]$Query,
[string]$Group,
[uint16]$GroupID,
[hashtable]$CustomFields,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
#endregion GET commands #endregion GET commands

View file

@ -0,0 +1,25 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 14:10
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxVirtualizationChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxVirtualizationChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}

View file

@ -1,4 +1,17 @@
function ValidateVirtualizationChoice { <#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 14:12
Created by: Claussen
Organization: NEOnet
Filename: ValidateVirtualizationChoice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function ValidateVirtualizationChoice {
<# <#
.SYNOPSIS .SYNOPSIS
Internal function to verify provided values for static choices Internal function to verify provided values for static choices

View file

@ -0,0 +1,155 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 12:44
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxVirtualMachine.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxVirtualMachine {
<#
.SYNOPSIS
Obtains virtual machines from Netbox.
.DESCRIPTION
Obtains one or more virtual machines based on provided filters.
.PARAMETER Limit
Number of results to return per page
.PARAMETER Offset
The initial index from which to return the results
.PARAMETER Query
A general query used to search for a VM
.PARAMETER Name
Name of the VM
.PARAMETER Id
Database ID of the VM
.PARAMETER Status
Status of the VM
.PARAMETER Tenant
String value of tenant
.PARAMETER Tenant_ID
Database ID of the tenant.
.PARAMETER Platform
String value of the platform
.PARAMETER Platform_ID
Database ID of the platform
.PARAMETER Cluster_Group
String value of the cluster group.
.PARAMETER Cluster_Group_Id
Database ID of the cluster group.
.PARAMETER Cluster_Type
String value of the Cluster type.
.PARAMETER Cluster_Type_Id
Database ID of the cluster type.
.PARAMETER Cluster_Id
Database ID of the cluster.
.PARAMETER Site
String value of the site.
.PARAMETER Site_Id
Database ID of the site.
.PARAMETER Role
String value of the role.
.PARAMETER Role_Id
Database ID of the role.
.PARAMETER Raw
A description of the Raw parameter.
.PARAMETER TenantID
Database ID of tenant
.PARAMETER PlatformID
Database ID of the platform
.PARAMETER id__in
Database IDs of VMs
.EXAMPLE
PS C:\> Get-NetboxVirtualMachine
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Alias('q')]
[string]$Query,
[string]$Name,
[uint16[]]$Id,
[object]$Status,
[string]$Tenant,
[uint16]$Tenant_ID,
[string]$Platform,
[uint16]$Platform_ID,
[string]$Cluster_Group,
[uint16]$Cluster_Group_Id,
[string]$Cluster_Type,
[uint16]$Cluster_Type_Id,
[uint16]$Cluster_Id,
[string]$Site,
[uint16]$Site_Id,
[string]$Role,
[uint16]$Role_Id,
[switch]$Raw
)
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
}

View file

@ -0,0 +1,58 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 12:44
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxVirtualMachine.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function New-NetboxVirtualMachine {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[uint16]$Cluster,
[uint16]$Tenant,
[object]$Status = 'Active',
[uint16]$Role,
[uint16]$Platform,
[uint16]$vCPUs,
[uint16]$Memory,
[uint16]$Disk,
[uint16]$Primary_IP4,
[uint16]$Primary_IP6,
[hashtable]$Custom_Fields,
[string]$Comments
)
$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
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
}

View file

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

View file

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

View file

@ -0,0 +1,45 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 12:46
Created by: Claussen
Organization: NEOnet
Filename: Add-NetboxVirtualMachineInterface.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Add-NetboxVirtualMachineInterface {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[uint16]$Virtual_Machine,
[boolean]$Enabled = $true,
[string]$MAC_Address,
[uint16]$MTU,
[string]$Description,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$PSBoundParameters.Enabled = $Enabled
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters
}

View file

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

View file

@ -0,0 +1,65 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 12:47
Created by: Claussen
Organization: NEOnet
Filename: Set-NetboxVirtualMachineInterface.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Set-NetboxVirtualMachineInterface {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Name,
[string]$MAC_Address,
[uint16]$MTU,
[string]$Description,
[boolean]$Enabled,
[uint16]$Virtual_Machine,
[switch]$Force
)
begin {
}
process {
foreach ($VMI_ID in $Id) {
Write-Verbose "Obtaining VM Interface..."
$CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop
Write-Verbose "Finished obtaining VM Interface"
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id))
if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}

View file

@ -1,677 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
Created on: 5/8/2018 3:59 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: Virtualization.ps1
===========================================================================
.DESCRIPTION
Virtualization object functions
#>
#region GET commands
function Get-NetboxVirtualizationChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}
function Get-NetboxVirtualMachine {
<#
.SYNOPSIS
Obtains virtual machines from Netbox.
.DESCRIPTION
Obtains one or more virtual machines based on provided filters.
.PARAMETER Limit
Number of results to return per page
.PARAMETER Offset
The initial index from which to return the results
.PARAMETER Query
A general query used to search for a VM
.PARAMETER Name
Name of the VM
.PARAMETER Id
Database ID of the VM
.PARAMETER Status
Status of the VM
.PARAMETER Tenant
String value of tenant
.PARAMETER Tenant_ID
Database ID of the tenant.
.PARAMETER Platform
String value of the platform
.PARAMETER Platform_ID
Database ID of the platform
.PARAMETER Cluster_Group
String value of the cluster group.
.PARAMETER Cluster_Group_Id
Database ID of the cluster group.
.PARAMETER Cluster_Type
String value of the Cluster type.
.PARAMETER Cluster_Type_Id
Database ID of the cluster type.
.PARAMETER Cluster_Id
Database ID of the cluster.
.PARAMETER Site
String value of the site.
.PARAMETER Site_Id
Database ID of the site.
.PARAMETER Role
String value of the role.
.PARAMETER Role_Id
Database ID of the role.
.PARAMETER Raw
A description of the Raw parameter.
.PARAMETER TenantID
Database ID of tenant
.PARAMETER PlatformID
Database ID of the platform
.PARAMETER id__in
Database IDs of VMs
.EXAMPLE
PS C:\> Get-NetboxVirtualMachine
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Alias('q')]
[string]$Query,
[string]$Name,
[uint16[]]$Id,
[object]$Status,
[string]$Tenant,
[uint16]$Tenant_ID,
[string]$Platform,
[uint16]$Platform_ID,
[string]$Cluster_Group,
[uint16]$Cluster_Group_Id,
[string]$Cluster_Type,
[uint16]$Cluster_Type_Id,
[uint16]$Cluster_Id,
[string]$Site,
[uint16]$Site_Id,
[string]$Role,
[uint16]$Role_Id,
[switch]$Raw
)
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
}
function Get-NetboxVirtualMachineInterface {
<#
.SYNOPSIS
Gets VM interfaces
.DESCRIPTION
Obtains the interface objects for one or more VMs
.PARAMETER Limit
Number of results to return per page.
.PARAMETER Offset
The initial index from which to return the results.
.PARAMETER Id
Database ID of the interface
.PARAMETER Name
Name of the interface
.PARAMETER Enabled
True/False if the interface is enabled
.PARAMETER MTU
Maximum Transmission Unit size. Generally 1500 or 9000
.PARAMETER Virtual_Machine_Id
ID of the virtual machine to which the interface(s) are assigned.
.PARAMETER Virtual_Machine
Name of the virtual machine to get interfaces
.PARAMETER MAC_Address
MAC address assigned to the interface
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxVirtualMachineInterface
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipeline = $true)]
[uint16]$Id,
[string]$Name,
[boolean]$Enabled,
[uint16]$MTU,
[uint16]$Virtual_Machine_Id,
[string]$Virtual_Machine,
[string]$MAC_Address,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
function Get-NetboxVirtualizationCluster {
<#
.SYNOPSIS
Obtains virtualization clusters from Netbox.
.DESCRIPTION
Obtains one or more virtualization clusters based on provided filters.
.PARAMETER Limit
Number of results to return per page
.PARAMETER Offset
The initial index from which to return the results
.PARAMETER Query
A general query used to search for a cluster
.PARAMETER Name
Name of the cluster
.PARAMETER Id
Database ID(s) of the cluster
.PARAMETER Group
String value of the cluster group.
.PARAMETER Group_Id
Database ID of the cluster group.
.PARAMETER Type
String value of the Cluster type.
.PARAMETER Type_Id
Database ID of the cluster type.
.PARAMETER Site
String value of the site.
.PARAMETER Site_Id
Database ID of the site.
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxVirtualizationCluster
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Alias('q')]
[string]$Query,
[string]$Name,
[Alias('id__in')]
[uint16[]]$Id,
[string]$Group,
[uint16]$Group_Id,
[string]$Type,
[uint16]$Type_Id,
[string]$Site,
[uint16]$Site_Id,
[switch]$Raw
)
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters'))
$URIParameters = @{
}
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
if ($CmdletParameterName -eq 'Id') {
# Check if there is one or more values for Id and build a URI or query as appropriate
if (@($PSBoundParameters[$CmdletParameterName]).Count -gt 1) {
$URIParameters['id__in'] = $Id -join ','
} else {
[void]$uriSegments.Add($PSBoundParameters[$CmdletParameterName])
}
} elseif ($CmdletParameterName -eq 'Query') {
$URIParameters['q'] = $PSBoundParameters[$CmdletParameterName]
} else {
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
function Get-NetboxVirtualizationClusterGroup {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[string]$Name,
[string]$Slug,
[switch]$Raw
)
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups'))
$URIParameters = @{}
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
#endregion GET commands
#region ADD/NEW commands
function New-NetboxVirtualMachine {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[uint16]$Cluster,
[uint16]$Tenant,
[object]$Status = 'Active',
[uint16]$Role,
[uint16]$Platform,
[uint16]$vCPUs,
[uint16]$Memory,
[uint16]$Disk,
[uint16]$Primary_IP4,
[uint16]$Primary_IP6,
[hashtable]$Custom_Fields,
[string]$Comments
)
$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
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
}
function Add-NetboxVirtualMachineInterface {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[uint16]$Virtual_Machine,
[boolean]$Enabled = $true,
[string]$MAC_Address,
[uint16]$MTU,
[string]$Description,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$PSBoundParameters.Enabled = $Enabled
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters
}
#endregion ADD commands
#region SET commands
function Set-NetboxVirtualMachine {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16]$Id,
[string]$Name,
[uint16]$Role,
[uint16]$Cluster,
[object]$Status,
[uint16]$Platform,
[uint16]$Primary_IP4,
[uint16]$Primary_IP6,
[byte]$VCPUs,
[uint16]$Memory,
[uint16]$Disk,
[uint16]$Tenant,
[string]$Comments,
[hashtable]$Custom_Fields,
[switch]$Force
)
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
}
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
Write-Verbose "Obtaining VM from ID $Id"
$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop
Write-Verbose "Finished obtaining VM"
if ($Force -or $pscmdlet.ShouldProcess($CurrentVM.Name, "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
function Set-NetboxVirtualMachineInterface {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Name,
[string]$MAC_Address,
[uint16]$MTU,
[string]$Description,
[boolean]$Enabled,
[uint16]$Virtual_Machine,
[switch]$Force
)
begin {
}
process {
foreach ($VMI_ID in $Id) {
Write-Verbose "Obtaining VM Interface..."
$CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop
Write-Verbose "Finished obtaining VM Interface"
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id))
if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}
#endregion SET commands
#region REMOVE commands
function Remove-NetboxVirtualMachine {
<#
.SYNOPSIS
Delete a virtual machine
.DESCRIPTION
Deletes a virtual machine from Netbox by ID
.PARAMETER Id
Database ID of the virtual machine
.PARAMETER Force
Force deletion without any prompts
.EXAMPLE
PS C:\> Remove-NetboxVirtualMachine -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($VMId in $Id) {
$CurrentVM = Get-NetboxVirtualMachine -Id $VMId -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentVM.Name)/$($CurrentVM.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $CurrentVM.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}
#endregion REMOVE commands

View file

@ -0,0 +1,125 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 14:10
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxVirtualizationCluster.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxVirtualizationCluster {
<#
.SYNOPSIS
Obtains virtualization clusters from Netbox.
.DESCRIPTION
Obtains one or more virtualization clusters based on provided filters.
.PARAMETER Limit
Number of results to return per page
.PARAMETER Offset
The initial index from which to return the results
.PARAMETER Query
A general query used to search for a cluster
.PARAMETER Name
Name of the cluster
.PARAMETER Id
Database ID(s) of the cluster
.PARAMETER Group
String value of the cluster group.
.PARAMETER Group_Id
Database ID of the cluster group.
.PARAMETER Type
String value of the Cluster type.
.PARAMETER Type_Id
Database ID of the cluster type.
.PARAMETER Site
String value of the site.
.PARAMETER Site_Id
Database ID of the site.
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> Get-NetboxVirtualizationCluster
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Alias('q')]
[string]$Query,
[string]$Name,
[Alias('id__in')]
[uint16[]]$Id,
[string]$Group,
[uint16]$Group_Id,
[string]$Type,
[uint16]$Type_Id,
[string]$Site,
[uint16]$Site_Id,
[switch]$Raw
)
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters'))
$URIParameters = @{
}
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
if ($CmdletParameterName -eq 'Id') {
# Check if there is one or more values for Id and build a URI or query as appropriate
if (@($PSBoundParameters[$CmdletParameterName]).Count -gt 1) {
$URIParameters['id__in'] = $Id -join ','
} else {
[void]$uriSegments.Add($PSBoundParameters[$CmdletParameterName])
}
} elseif ($CmdletParameterName -eq 'Query') {
$URIParameters['q'] = $PSBoundParameters[$CmdletParameterName]
} else {
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -0,0 +1,48 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 14:11
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxVirtualizationClusterGroup.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxVirtualizationClusterGroup {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[string]$Name,
[string]$Slug,
[switch]$Raw
)
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups'))
$URIParameters = @{
}
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -19,7 +19,7 @@
ModuleToProcess = 'NetboxPS.psm1' ModuleToProcess = 'NetboxPS.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '1.0.2' ModuleVersion = '1.0.3'
# ID used to uniquely identify this module # ID used to uniquely identify this module
GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896' GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896'

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,16 @@
<Folder>Functions\Virtualization</Folder> <Folder>Functions\Virtualization</Folder>
<Folder>Functions\IPAM</Folder> <Folder>Functions\IPAM</Folder>
<Folder>Functions\Tenancy</Folder> <Folder>Functions\Tenancy</Folder>
<Folder>Functions\IPAM\VLAN</Folder>
<Folder>Functions\IPAM\Role</Folder>
<Folder>Functions\IPAM\Aggregate</Folder>
<Folder>Functions\IPAM\Address</Folder>
<Folder>Functions\IPAM\Prefix</Folder>
<Folder>Functions\Virtualization\VirtualMachine</Folder>
<Folder>Functions\Virtualization\VirtualMachineInterface</Folder>
<Folder>Functions\Virtualization\VirtualizationCluster</Folder>
<Folder>Functions\DCIM\Devices</Folder>
<Folder>Functions\DCIM\Interfaces</Folder>
</Folders> </Folders>
<Files> <Files>
<File Build="2">NetboxPS.psd1</File> <File Build="2">NetboxPS.psd1</File>
@ -20,26 +30,61 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-Helpers_ps1" ExportFunctions="False">Functions\Helpers.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Helpers_ps1" ExportFunctions="False">Functions\Helpers.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Setup_ps1" ExportFunctions="False">Functions\Setup.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Setup_ps1" ExportFunctions="False">Functions\Setup.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Extras_ps1" ExportFunctions="True">Functions\Extras\Extras.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Extras_ps1" ExportFunctions="True">Functions\Extras\Extras.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Circuits_ps1" ExportFunctions="True">Functions\Circuits\Circuits.ps1</File>
<File Build="1" Shared="False" ReferenceFunction="Invoke-Setup_Tests_ps1" ExportFunctions="False">Tests\Setup.Tests.ps1</File> <File Build="1" Shared="False" ReferenceFunction="Invoke-Setup_Tests_ps1" ExportFunctions="False">Tests\Setup.Tests.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-Helpers_Tests_ps1" ExportFunctions="False">Tests\Helpers.Tests.ps1</File> <File Build="2" Shared="True" ReferenceFunction="Invoke-Helpers_Tests_ps1" ExportFunctions="False">Tests\Helpers.Tests.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Virtualization_ps1" ExportFunctions="True">Functions\Virtualization\Virtualization.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-Virtualization_Tests_ps1" ExportFunctions="False">Tests\Virtualization.Tests.ps1</File> <File Build="2" Shared="True" ReferenceFunction="Invoke-Virtualization_Tests_ps1" ExportFunctions="False">Tests\Virtualization.Tests.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-IPAM_Tests_ps1" ExportFunctions="False">Tests\IPAM.Tests.ps1</File> <File Build="2" Shared="True" ReferenceFunction="Invoke-IPAM_Tests_ps1" ExportFunctions="False">Tests\IPAM.Tests.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-IPAM_ps1" ExportFunctions="True">Functions\IPAM\IPAM.ps1</File>
<File Build="2">Tests\IPAMChoices.json</File> <File Build="2">Tests\IPAMChoices.json</File>
<File Build="2">Tests\VirtualizationChoices.json</File> <File Build="2">Tests\VirtualizationChoices.json</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-DCIM_ps1" ExportFunctions="True">Functions\DCIM\DCIM.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-DCIM_Devices_Tests_ps1" ExportFunctions="False">Tests\DCIM.Devices.Tests.ps1</File> <File Build="2" Shared="True" ReferenceFunction="Invoke-DCIM_Devices_Tests_ps1" ExportFunctions="False">Tests\DCIM.Devices.Tests.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-DCIM_Interfaces_Tests_ps1" ExportFunctions="False">Tests\DCIM.Interfaces.Tests.ps1</File> <File Build="2" Shared="True" ReferenceFunction="Invoke-DCIM_Interfaces_Tests_ps1" ExportFunctions="False">Tests\DCIM.Interfaces.Tests.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-DCIM_Platforms_Tests_ps1" ExportFunctions="False">Tests\DCIM.Platforms.Tests.ps1</File> <File Build="2" Shared="True" ReferenceFunction="Invoke-DCIM_Platforms_Tests_ps1" ExportFunctions="False">Tests\DCIM.Platforms.Tests.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-DCIM_Devices_ps1" ExportFunctions="True">Functions\DCIM\DCIM.Devices.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-ValidateDCIMChoice_ps1" ExportFunctions="False">Functions\DCIM\ValidateDCIMChoice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-DCIM_Interfaces_ps1" ExportFunctions="True">Functions\DCIM\DCIM.Interfaces.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Tenancy_ps1" ExportFunctions="True">Functions\Tenancy\Tenancy.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-DCIM_Support_ps1" ExportFunctions="False">Functions\DCIM\DCIM.Support.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-IPAM_Support_ps1" ExportFunctions="False">Functions\IPAM\IPAM.Support.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Virtualization_Support_ps1" ExportFunctions="False">Functions\Virtualization\Virtualization.Support.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Setup_Support_ps1" ExportFunctions="False">Functions\Setup.Support.ps1</File> <File Build="0" Shared="True" ReferenceFunction="Invoke-Setup_Support_ps1" ExportFunctions="False">Functions\Setup.Support.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMVLAN_ps1" ExportFunctions="True">Functions\IPAM\VLAN\Get-NetboxIPAMVLAN.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxIPAMVLAN_ps1" ExportFunctions="True">Functions\IPAM\VLAN\New-NetboxIPAMVLAN.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMRole_ps1" ExportFunctions="True">Functions\IPAM\Role\Get-NetboxIPAMRole.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMAggregate_ps1" ExportFunctions="True">Functions\IPAM\Aggregate\Get-NetboxIPAMAggregate.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMAddress_ps1" ExportFunctions="True">Functions\IPAM\Address\Get-NetboxIPAMAddress.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMAvailableIP_ps1" ExportFunctions="False">Functions\IPAM\Address\Get-NetboxIPAMAvailableIP.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMPrefix_ps1" ExportFunctions="False">Functions\IPAM\Prefix\Get-NetboxIPAMPrefix.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxIPAMAddress_ps1" ExportFunctions="True">Functions\IPAM\Address\New-NetboxIPAMAddress.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxIPAMPrefix_ps1" ExportFunctions="True">Functions\IPAM\Prefix\New-NetboxIPAMPrefix.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxIPAMAddress_ps1" ExportFunctions="True">Functions\IPAM\Address\Remove-NetboxIPAMAddress.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxIPAMAddress_ps1" ExportFunctions="True">Functions\IPAM\Address\Set-NetboxIPAMAddress.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-ValidateIPAMChoice_ps1" ExportFunctions="False">Functions\IPAM\ValidateIPAMChoice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMChoices_ps1" ExportFunctions="True">Functions\IPAM\Get-NetboxIPAMChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxTenant_ps1" ExportFunctions="True">Functions\Tenancy\Get-NetboxTenant.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxTenancyChoices_ps1" ExportFunctions="True">Functions\Tenancy\Get-NetboxTenancyChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualMachine_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachine\Get-NetboxVirtualMachine.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxVirtualMachine_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachine\New-NetboxVirtualMachine.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxVirtualMachine_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachine\Set-NetboxVirtualMachine.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-Remove-NetboxVirtualMachine_ps1" ExportFunctions="False">Functions\Virtualization\VirtualMachine\Remove-NetboxVirtualMachine.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Add-NetboxVirtualMachineInterface_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachineInterface\Add-NetboxVirtualMachineInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualMachineInterface_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachineInterface\Get-NetboxVirtualMachineInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxVirtualMachineInterface_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachineInterface\Set-NetboxVirtualMachineInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualizationChoices_ps1" ExportFunctions="True">Functions\Virtualization\Get-NetboxVirtualizationChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualizationCluster_ps1" ExportFunctions="True">Functions\Virtualization\VirtualizationCluster\Get-NetboxVirtualizationCluster.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualizationClusterGroup_ps1" ExportFunctions="False">Functions\Virtualization\VirtualizationCluster\Get-NetboxVirtualizationClusterGroup.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-ValidateVirtualizationChoice_ps1" ExportFunctions="True">Functions\Virtualization\ValidateVirtualizationChoice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMDevice_ps1" ExportFunctions="True">Functions\DCIM\Devices\Get-NetboxDCIMDevice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMDeviceType_ps1" ExportFunctions="True">Functions\DCIM\Devices\Get-NetboxDCIMDeviceType.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMDeviceRole_ps1" ExportFunctions="True">Functions\DCIM\Devices\Get-NetboxDCIMDeviceRole.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxDCIMDevice_ps1" ExportFunctions="True">Functions\DCIM\Devices\New-NetboxDCIMDevice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxDCIMDevice_ps1" ExportFunctions="True">Functions\DCIM\Devices\Set-NetboxDCIMDevice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxDCIMDevice_ps1" ExportFunctions="True">Functions\DCIM\Devices\Remove-NetboxDCIMDevice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMInterface_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Get-NetboxDCIMInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMInterfaceConnection_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Get-NetboxDCIMInterfaceConnection.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Add-NetboxDCIMInterface_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Add-NetboxDCIMInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Add-NetboxDCIMInterfaceConnection_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Add-NetboxDCIMInterfaceConnection.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxDCIMInterface_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Set-NetboxDCIMInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxDCIMInterfaceConnection_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Set-NetboxDCIMInterfaceConnection.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxDCIMInterface_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Remove-NetboxDCIMInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxDCIMInterfaceConnection_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Remove-NetboxDCIMInterfaceConnection.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMPlatform_ps1" ExportFunctions="True">Functions\DCIM\Get-NetboxDCIMPlatform.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMChoices_ps1" ExportFunctions="True">Functions\DCIM\Get-NetboxDCIMChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuitsChoices_ps1" ExportFunctions="True">Functions\Circuits\Get-NetboxCircuitsChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuit_ps1" ExportFunctions="True">Functions\Circuits\Get-NetboxCircuit.ps1</File>
</Files> </Files>
<StartupScript>R:\Netbox\NetboxPS\Test-Module.ps1</StartupScript> <StartupScript>R:\Netbox\NetboxPS\Test-Module.ps1</StartupScript>
</Project> </Project>

2
dist/NetboxPS.psd1 vendored
View file

@ -19,7 +19,7 @@
ModuleToProcess = 'NetboxPS.psm1' ModuleToProcess = 'NetboxPS.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '1.0.2' ModuleVersion = '1.0.3'
# ID used to uniquely identify this module # ID used to uniquely identify this module
GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896' GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896'

3169
dist/NetboxPS.psm1 vendored

File diff suppressed because it is too large Load diff

View file

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

View file

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

View file

@ -1,121 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
Created on: 5/25/2018 1:03 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: DCIM.Platforms.Tests.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
Import-Module Pester
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
$ModulePath = "$PSScriptRoot\..\dist\NetboxPS.psd1"
if (Test-Path $ModulePath) {
Import-Module $ModulePath -ErrorAction Stop
}
Describe -Name "DCIM Platforms Tests" -Tag 'DCIM', 'platforms' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true
}
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{
'Method' = $Method
'Uri' = $Uri
'Headers' = $Headers
'Timeout' = $Timeout
'ContentType' = $ContentType
'Body' = $Body
}
}
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
}
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com'
}
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
Context -Name "Get-NetboxDCIMPlatform" -Fixture {
It "Should request the default number of platforms" {
$Result = Get-NetboxDCIMPlatform
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMPlatform -Limit 10 -Offset 100
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a platform name" {
$Result = Get-NetboxDCIMPlatform -Name "Windows Server 2016"
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/platforms/?name=Windows+Server+2016'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request a platform by manufacturer" {
$Result = Get-NetboxDCIMPlatform -Manufacturer 'Cisco'
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/?manufacturer=Cisco'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request a platform by ID" {
$Result = Get-NetboxDCIMPlatform -Id 10
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/platforms/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request multiple platforms by ID" {
$Result = Get-NetboxDCIMPlatform -Id 10, 20
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Invoke-RestMethod' -Times 2 -Scope 'It' -Exactly
$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.Headers.Keys.Count | Should -BeExactly 2
}
}
}
}

View file

@ -1,315 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
Created on: 5/22/2018 4:48 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: DCIM.Tests.ps1
===========================================================================
.DESCRIPTION
DCIM tests.
#>
Import-Module Pester
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
$ModulePath = "$PSScriptRoot\..\dist\NetboxPS.psd1"
if (Test-Path $ModulePath) {
Import-Module $ModulePath -ErrorAction Stop
}
Describe -Name "DCIM Tests" -Tag 'DCIM' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true
}
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{
'Method' = $Method
'Uri' = $Uri
'Headers' = $Headers
'Timeout' = $Timeout
'ContentType' = $ContentType
'Body' = $Body
}
}
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
}
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com'
}
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
$script:NetboxConfig.Choices.DCIM = (Get-Content "$PSScriptRoot\DCIMChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "Get-NetboxDCIMDevice" -Fixture {
It "Should request the default number of devices" {
$Result = Get-NetboxDCIMDevice
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMDevice -Limit 10 -Offset 100
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a query" {
$Result = Get-NetboxDCIMDevice -Query 'testdevice'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with an escaped query" {
$Result = Get-NetboxDCIMDevice -Query 'test device'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?q=test+device'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a name" {
$Result = Get-NetboxDCIMDevice -Name 'testdevice'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?name=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a single ID" {
$Result = Get-NetboxDCIMDevice -Id 10
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with multiple IDs" {
$Result = Get-NetboxDCIMDevice -Id 10, 12, 15
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request a status" {
$Result = Get-NetboxDCIMDevice -Status 'Active'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/devices/?status=1'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should throw for an invalid status" {
{
Get-NetboxDCIMDevice -Status 'Fake'
} | Should -Throw
}
It "Should request devices that are a PDU" {
$Result = Get-NetboxDCIMDevice -Is_PDU $True
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -BeExactly 'https://netbox.domain.com/api/dcim/devices/?is_pdu=True'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
}
Context -Name "Get-NetboxDCIMDeviceType" -Fixture {
It "Should request the default number of devices types" {
$Result = Get-NetboxDCIMDeviceType
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMDeviceType -Limit 10 -Offset 100
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a query" {
$Result = Get-NetboxDCIMDeviceType -Query 'testdevice'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with an escaped query" {
$Result = Get-NetboxDCIMDeviceType -Query 'test device'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?q=test+device'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a slug" {
$Result = Get-NetboxDCIMDeviceType -Slug 'testdevice'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?slug=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a single ID" {
$Result = Get-NetboxDCIMDeviceType -Id 10
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with multiple IDs" {
$Result = Get-NetboxDCIMDeviceType -Id 10, 12, 15
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request a device type that is PDU" {
$Result = Get-NetboxDCIMDeviceType -Is_PDU $true
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-types/?is_pdu=True'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
}
Context -Name "Get-NetboxDCIMDeviceRole" -Fixture {
It "Should request the default number of devices types" {
$Result = Get-NetboxDCIMDeviceRole
Assert-VerifiableMock
Assert-MockCalled -CommandName "Invoke-RestMethod" -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a limit and offset" {
$Result = Get-NetboxDCIMDeviceRole -Limit 10 -Offset 100
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?offset=100&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a slug" {
$Result = Get-NetboxDCIMDeviceRole -Slug 'testdevice'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?slug=testdevice'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a name" {
$Result = Get-NetboxDCIMDeviceRole -Name 'TestRole'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?name=TestRole'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request those that are VM role" {
$Result = Get-NetboxDCIMDeviceRole -VM_Role $true
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/dcim/device-roles/?vm_role=True'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
}
}
}

View file

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

View file

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

View file

@ -1 +0,0 @@
{"aggregate:family":[{"label":"IPv4","value":4},{"label":"IPv6","value":6}],"prefix:family":[{"label":"IPv4","value":4},{"label":"IPv6","value":6}],"prefix:status":[{"label":"Container","value":0},{"label":"Active","value":1},{"label":"Reserved","value":2},{"label":"Deprecated","value":3}],"ip-address:family":[{"label":"IPv4","value":4},{"label":"IPv6","value":6}],"ip-address:status":[{"label":"Active","value":1},{"label":"Reserved","value":2},{"label":"Deprecated","value":3},{"label":"DHCP","value":5}],"ip-address:role":[{"label":"Loopback","value":10},{"label":"Secondary","value":20},{"label":"Anycast","value":30},{"label":"VIP","value":40},{"label":"VRRP","value":41},{"label":"HSRP","value":42},{"label":"GLBP","value":43},{"label":"CARP","value":44}],"vlan:status":[{"label":"Active","value":1},{"label":"Reserved","value":2},{"label":"Deprecated","value":3}],"service:protocol":[{"label":"TCP","value":6},{"label":"UDP","value":17}]}

View file

@ -1,543 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
Created on: 5/8/2018 4:01 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: Virtualization.Tests.ps1
===========================================================================
.DESCRIPTION
Virtualization Pester tests
#>
Import-Module Pester
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
$ModulePath = "$PSScriptRoot\..\dist\NetboxPS.psd1"
if (Test-Path $ModulePath) {
Import-Module $ModulePath -ErrorAction Stop
}
Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
Mock -CommandName 'CheckNetboxIsConnected' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return $true
}
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
return [ordered]@{
'Method' = $Method
'Uri' = $Uri
'Headers' = $Headers
'Timeout' = $Timeout
'ContentType' = $ContentType
'Body' = $Body
}
}
Mock -CommandName 'Get-NetboxCredential' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
}
Mock -CommandName 'Get-NetboxHostname' -Verifiable -ModuleName 'NetboxPS' -MockWith {
return 'netbox.domain.com'
}
InModuleScope -ModuleName 'NetboxPS' -ScriptBlock {
$script:NetboxConfig.Choices.Virtualization = (Get-Content "$PSScriptRoot\VirtualizationChoices.json" -ErrorAction Stop | ConvertFrom-Json)
Context -Name "Get-NetboxVirtualMachine" -Fixture {
It "Should request the default number of VMs" {
$Result = Get-NetboxVirtualMachine
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with limit and offset" {
$Result = Get-NetboxVirtualMachine -Limit 10 -Offset 12
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a query" {
$Result = Get-NetboxVirtualMachine -Query 'testvm'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=testvm'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with an escaped query" {
$Result = Get-NetboxVirtualMachine -Query 'test vm'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?q=test+vm'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a name" {
$Result = Get-NetboxVirtualMachine -Name 'testvm'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?name=testvm'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a single ID" {
$Result = Get-NetboxVirtualMachine -Id 10
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with multiple IDs" {
$Result = Get-NetboxVirtualMachine -Id 10, 12, 15
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request a status" {
$Result = Get-NetboxVirtualMachine -Status 'Active'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/?status=1'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should throw for an invalid status" {
{ Get-NetboxVirtualMachine -Status 'Fake' } | Should -Throw
}
}
Context -Name "Get-NetboxVirtualMachineInterface" -Fixture {
It "Should request the default number of interfaces" {
$Result = Get-NetboxVirtualMachineInterface
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a limit and offset" {
$Result = Get-NetboxVirtualMachineInterface -Limit 10 -Offset 12
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request a interface with a specific ID" {
$Result = Get-NetboxVirtualMachineInterface -Id 10
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request a name" {
$Result = Get-NetboxVirtualMachineInterface -Name 'Ethernet0'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?name=Ethernet0'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a VM ID" {
$Result = Get-NetboxVirtualMachineInterface -Virtual_Machine_Id 10
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?virtual_machine_id=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with Enabled" {
$Result = Get-NetboxVirtualMachineInterface -Enabled $true
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/?enabled=true'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
}
Context -Name "Get-NetboxVirtualMachineCluster" -Fixture {
It "Should request the default number of clusters" {
$Result = Get-NetboxVirtualizationCluster
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with limit and offset" {
$Result = Get-NetboxVirtualizationCluster -Limit 10 -Offset 12
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a query" {
$Result = Get-NetboxVirtualizationCluster -Query 'testcluster'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=testcluster'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with an escaped query" {
$Result = Get-NetboxVirtualizationCluster -Query 'test cluster'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?q=test+cluster'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a name" {
$Result = Get-NetboxVirtualizationCluster -Name 'testcluster'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?name=testcluster'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a single ID" {
$Result = Get-NetboxVirtualizationCluster -Id 10
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/10/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with multiple IDs" {
$Result = Get-NetboxVirtualizationCluster -Id 10, 12, 15
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/clusters/?id__in=10,12,15'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
}
Context -Name "Get-NetboxVirtualMachineClusterGroup" -Fixture {
It "Should request the default number of cluster groups" {
$Result = Get-NetboxVirtualizationClusterGroup
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with limit and offset" {
$Result = Get-NetboxVirtualizationClusterGroup -Limit 10 -Offset 12
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?offset=12&limit=10'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a name" {
$Result = Get-NetboxVirtualizationClusterGroup -Name 'testclustergroup'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?name=testclustergroup'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should request with a slug" {
$Result = Get-NetboxVirtualizationClusterGroup -Slug 'test-cluster-group'
Assert-VerifiableMock
$Result.Method | Should -Be 'GET'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/cluster-groups/?slug=test-cluster-group'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
}
Context -Name "New-NetboxVirtualMachine" -Fixture {
It "Should create a basic VM" {
$Result = New-NetboxVirtualMachine -Name 'testvm' -Cluster 1
Assert-VerifiableMock
$Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/'
$Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"cluster":1,"name":"testvm","status":1}'
}
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"
Assert-VerifiableMock
$Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/'
$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}'
}
It "Should throw because of an invalid status" {
{ New-NetboxVirtualMachine -Name 'testvm' -Status 1123 -Cluster 1 } | Should -Throw
}
}
Context -Name "Add-NetboxVirtualMachineInterface" -Fixture {
It "Should add a basic interface" {
$Result = Add-NetboxVirtualMachineInterface -Name 'Ethernet0' -Virtual_Machine 10
Assert-VerifiableMock
$Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/'
$Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"virtual_machine":10,"name":"Ethernet0","enabled":true}'
}
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"
Assert-VerifiableMock
$Result.Method | Should -Be 'POST'
$Result.Uri | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/'
$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"}'
}
}
Mock -CommandName "Get-NetboxVirtualMachine" -ModuleName NetboxPS -MockWith {
return [pscustomobject]@{
'Id' = $Id
'Name' = $Name
}
}
Context -Name "Set-NetboxVirtualMachine" -Fixture {
It "Should set a VM to a new name" {
$Result = Set-NetboxVirtualMachine -Id 1234 -Name 'newtestname' -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"name":"newtestname"}'
}
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
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"cluster":10,"platform":15,"name":"newtestname","status":0}'
}
It "Should throw because of an invalid status" {
{ Set-NetboxVirtualMachine -Id 1234 -Status 'Fake' -Force } | Should -Throw
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 0 -Exactly -Scope 'It'
}
}
Mock -CommandName "Get-NetboxVirtualMachineInterface" -ModuleName NetboxPS -MockWith {
return [pscustomobject]@{
'Id' = $Id
'Name' = $Name
}
}
Context -Name "Set-NetboxVirtualMachineInterface" -Fixture {
It "Should set an interface to a new name" {
$Result = Set-NetboxVirtualMachineInterface -Id 1234 -Name 'newtestname' -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/'
$Result.Headers.Keys.Count | Should -BeExactly 1
$Result.Body | Should -Be '{"name":"newtestname"}'
}
It "Should set an interface to a new name, MTU, MAC address and description" {
$paramSetNetboxVirtualMachineInterface = @{
Id = 1234
Name = 'newtestname'
MAC_Address = '11:22:33:44:55:66'
MTU = 9000
Description = "Test description"
Force = $true
}
$Result = Set-NetboxVirtualMachineInterface @paramSetNetboxVirtualMachineInterface
Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 1 -Scope 'It' -Exactly
$Result.Method | Should -Be 'PATCH'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/interfaces/1234/'
$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"}'
}
It "Should set multiple interfaces to a new name" {
$Result = Set-NetboxVirtualMachineInterface -Id 1234, 4321 -Name 'newtestname' -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly
$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.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}'
}
It "Should set multiple interfaces to a new name from the pipeline" {
$Result = @(
[pscustomobject]@{
'Id' = 4123
},
[pscustomobject]@{
'Id' = 4321
}
) | Set-NetboxVirtualMachineInterface -Name 'newtestname' -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName Get-NetboxVirtualMachineInterface -Times 2 -Scope 'It' -Exactly
$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.Headers.Keys.Count | Should -BeExactly 2
$Result.Body | Should -Be '{"name":"newtestname"}', '{"name":"newtestname"}'
}
}
Context -Name "Remove-NetboxVirtualMachine" -Fixture {
It "Should remove a single VM" {
$Result = Remove-NetboxVirtualMachine -Id 4125 -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 1 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should remove mulitple VMs" {
$Result = Remove-NetboxVirtualMachine -Id 4125, 4132 -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It'
$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.Headers.Keys.Count | Should -BeExactly 2
}
It "Should remove a VM from the pipeline" {
$Result = Get-NetboxVirtualMachine -Id 4125 | Remove-NetboxVirtualMachine -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It'
$Result.Method | Should -Be 'DELETE'
$Result.URI | Should -Be 'https://netbox.domain.com/api/virtualization/virtual-machines/4125/'
$Result.Headers.Keys.Count | Should -BeExactly 1
}
It "Should remove multiple VMs from the pipeline" {
$Result = @(
[pscustomobject]@{
'Id' = 4125
},
[pscustomobject]@{
'Id' = 4132
}
) | Remove-NetboxVirtualMachine -Force
Assert-VerifiableMock
Assert-MockCalled -CommandName 'Get-NetboxVirtualMachine' -Times 2 -Exactly -Scope 'It'
$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.Headers.Keys.Count | Should -BeExactly 2
}
}
}
}

View file

@ -1 +0,0 @@
{"virtual-machine:status":[{"label":"Active","value":1},{"label":"Offline","value":0},{"label":"Staged","value":3}]}