Device port support (#44)

* Fixing #41

* Correct for OTBS

* Start work on Front and Rear ports

* Revert "Start work on Front and Rear ports"

This reverts commit 257709fe2af5af5fbe4496b2d5b68481d80bf101.

* Fixing #41

* Add-NetboxDCIMRearPort function

* Revert "Revert "Start work on Front and Rear ports""

This reverts commit 4f6625af2d.

* Fix incorrect parameter variable types

* Parameter type adjustments

* Create function to get tag information

* Added Mark_Connected parameter

* Add Set-NetboxDCIMRearPort function

* Added Remove-NetboxDCIMRearPort function

* Added validate pattern for Color parameter

* Added Add-NetboxDCIMFrontPort function

* Fixed param list missing Force parameter

* Added Set-NetboxDCIMFrontPort function

* Added Remove-NetboxDCIMFrontPort function

* Init. functions for cables and cable terminations

* Reformatting using OTBS
Also working on defining tags by slug as an extra parameter, which appears
only in Add-NetboxDCIMRearPort currently

* Remove Tags_Slug parameter
In hindsight implementing would create extra work that could be hard to
maintain. Can be easily achieved outside of the function.
This commit is contained in:
James Beck 2023-03-17 19:27:55 +00:00 committed by GitHub
parent eb4d0eeb3b
commit d441a1ddac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 587 additions and 11 deletions

View file

@ -6,5 +6,6 @@
"powershell.codeFormatting.newLineAfterCloseBrace": false,
"[markdown]": {
"files.trimTrailingWhitespace": false,
}
},
"powershell.codeFormatting.openBraceOnSameLine": true
}

View file

@ -0,0 +1,35 @@
function Get-NetboxDCIMCableTermination {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[uint16]$Cable,
[string]$Cable_End,
[string]$Termination_Type,
[uint16]$Termination_ID,
[switch]$Raw
)
#endregion Parameters
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'cable-terminations'))
$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,55 @@
function Get-NetboxDCIMCable {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Label,
[string]$Termination_A_Type,
[uint16]$Termination_A_ID,
[string]$Termination_B_Type,
[UInt16]$Termination_B_ID,
[string]$Type,
[string]$Status,
[string]$Color,
[UInt16]$Device_ID,
[string]$Device,
[uint16]$Rack_Id,
[string]$Rack,
[uint16]$Location_ID,
[string]$Location,
[switch]$Raw
)
#endregion Parameters
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'cables'))
$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,42 @@
function Add-NetboxDCIMFrontPort {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[uint16]$Device,
[uint16]$Module,
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$Label,
[Parameter(Mandatory = $true)]
[string]$Type,
[ValidatePattern('^[0-9a-f]{6}$')]
[string]$Color,
[Parameter(Mandatory = $true)]
[uint16]$Rear_Port,
[uint16]$Rear_Port_Position,
[string]$Description,
[bool]$Mark_Connected,
[uint16[]]$Tags
)
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports'))
$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,34 @@
function Get-NetboxDCIMFrontPort {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16]$Id,
[string]$Name,
[string]$Device,
[uint16]$Device_Id,
[string]$Type,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports'))
$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,35 @@
function Remove-NetboxDCIMFrontPort {
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($FrontPortID in $Id) {
$CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}

View file

@ -0,0 +1,60 @@
function Set-NetboxDCIMFrontPort {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[uint16]$Device,
[uint16]$Module,
[string]$Name,
[string]$Label,
[string]$Type,
[ValidatePattern('^[0-9a-f]{6}$')]
[string]$Color,
[uint16]$Rear_Port,
[uint16]$Rear_Port_Position,
[string]$Description,
[bool]$Mark_Connected,
[uint16[]]$Tags,
[switch]$Force
)
begin {
}
process {
foreach ($FrontPortID in $Id) {
$CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$URI = BuildNewURI -Segments $Segments
if ($Force -or $pscmdlet.ShouldProcess("Front Port ID $($CurrentPort.Id)", "Set")) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end {
}
}

View file

@ -1,5 +1,4 @@

function Get-NetboxDCIMInterface {
function Get-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param

View file

@ -1,5 +1,4 @@

function Remove-NetboxDCIMInterface {
function Remove-NetboxDCIMInterface {
<#
.SYNOPSIS
Removes an interface

View file

@ -1,5 +1,4 @@

function Set-NetboxDCIMInterface {
function Set-NetboxDCIMInterface {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
@ -37,7 +36,9 @@ function Set-NetboxDCIMInterface {
[uint16]$Untagged_VLAN,
[ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs
[uint16[]]$Tagged_VLANs,
[switch]$Force
)
begin {

View file

@ -0,0 +1,48 @@
function Add-NetboxDCIMRearPort {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[uint16]$Device,
[uint16]$Module,
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$Label,
[Parameter(Mandatory = $true)]
[string]$Type,
[ValidatePattern('^[0-9a-f]{6}$')]
[string]$Color,
[uint16]$Positions = 1,
[string]$Description,
[bool]$Mark_Connected,
[uint16[]]$Tags
)
begin {
}
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
end {
}
}

View file

@ -0,0 +1,34 @@
function Get-NetboxDCIMRearPort {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16]$Id,
[string]$Name,
[string]$Device,
[uint16]$Device_Id,
[string]$Type,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports'))
$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,35 @@
function Remove-NetboxDCIMRearPort {
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($RearPortID in $Id) {
$CurrentPort = Get-NetboxDCIMRearPort -Id $RearPortID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports', $CurrentPort.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}

View file

@ -0,0 +1,65 @@

function Set-NetboxDCIMRearPort
{
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[uint16]$Device,
[uint16]$Module,
[string]$Name,
[string]$Label,
[string]$Type,
[ValidatePattern('^[0-9a-f]{6}$')]
[string]$Color,
[uint16]$Positions,
[string]$Description,
[bool]$Mark_Connected,
[uint16[]]$Tags,
[switch]$Force
)
begin
{
}
process
{
foreach ($RearPortID in $Id)
{
$CurrentPort = Get-NetboxDCIMRearPort -Id $RearPortID -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports', $CurrentPort.Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$URI = BuildNewURI -Segments $Segments
if ($Force -or $pscmdlet.ShouldProcess("Rear Port ID $($CurrentPort.Id)", "Set"))
{
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
end
{
}
}

View file

@ -0,0 +1,31 @@

function Get-NetboxTag {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16]$Id,
[string]$Name,
[string]$Slug,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('extras', 'tags'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}

View file

@ -953,6 +953,50 @@
},
"response": []
},
{
"name": "Get Device Rear Ports",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/dcim/rear-ports/",
"protocol": "{{SCHEME}}",
"host": [
"{{HOSTNAME}}"
],
"port": "{{PORT}}",
"path": [
"api",
"dcim",
"rear-ports",
""
]
}
},
"response": []
},
{
"name": "Get Device Front Ports",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/dcim/front-ports/",
"protocol": "{{SCHEME}}",
"host": [
"{{HOSTNAME}}"
],
"port": "{{PORT}}",
"path": [
"api",
"dcim",
"rear-ports",
""
]
}
},
"response": []
},
{
"name": "Add Interface",
"request": {
@ -983,6 +1027,64 @@
}
},
"response": []
},
{
"name": "Add Rear Port",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"device\": 62,\r\n \"name\": \"RearPort1\",\r\n \"type\": 110-punch\r\n}"
},
"url": {
"raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/dcim/rear-ports/",
"protocol": "{{SCHEME}}",
"host": [
"{{HOSTNAME}}"
],
"port": "{{PORT}}",
"path": [
"api",
"dcim",
"rear-ports",
""
]
}
},
"response": []
}
]
},
{
"name": "Extras",
"item": [
{
"name": "Get Tags",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/extras/tags/",
"protocol": "{{SCHEME}}",
"host": [
"{{HOSTNAME}}"
],
"port": "{{PORT}}",
"path": [
"api",
"extras",
"tags",
""
]
}
},
"response": []
}
]
},