Reformatting using OTBS

Also working on defining tags by slug as an extra parameter, which appears
only in Add-NetboxDCIMRearPort currently
This commit is contained in:
sheffsix 2023-03-15 13:55:41 +00:00
parent 115b28a48d
commit ec1eb869b3
15 changed files with 82 additions and 124 deletions

View file

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

View file

@ -1,6 +1,4 @@
 function Get-NetboxDCIMCableTermination {
function Get-NetboxDCIMCableTermination
{
[CmdletBinding()] [CmdletBinding()]
#region Parameters #region Parameters
param param
@ -25,8 +23,7 @@ function Get-NetboxDCIMCableTermination
#endregion Parameters #endregion Parameters
process process {
{
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'cable-terminations')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'cable-terminations'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'

View file

@ -1,6 +1,4 @@
 function Get-NetboxDCIMCable {
function Get-NetboxDCIMCable
{
[CmdletBinding()] [CmdletBinding()]
#region Parameters #region Parameters
param param
@ -45,8 +43,7 @@ function Get-NetboxDCIMCable
#endregion Parameters #endregion Parameters
process process {
{
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'cables')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'cables'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'

View file

@ -1,6 +1,4 @@
 function Add-NetboxDCIMFrontPort {
function Add-NetboxDCIMFrontPort
{
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param

View file

@ -1,6 +1,4 @@
 function Get-NetboxDCIMFrontPort {
function Get-NetboxDCIMFrontPort
{
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
@ -23,8 +21,7 @@ function Get-NetboxDCIMFrontPort
[switch]$Raw [switch]$Raw
) )
process process {
{
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports'))

View file

@ -1,6 +1,4 @@
 function Remove-NetboxDCIMFrontPort {
function Remove-NetboxDCIMFrontPort
{
[CmdletBinding(ConfirmImpact = 'High', [CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
@ -13,19 +11,15 @@ function Remove-NetboxDCIMFrontPort
[switch]$Force [switch]$Force
) )
begin begin {
{
} }
process process {
{ foreach ($FrontPortID in $Id) {
foreach ($FrontPortID in $Id)
{
$CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop $CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) {
{
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id))
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
@ -35,8 +29,7 @@ function Remove-NetboxDCIMFrontPort
} }
} }
end end {
{
} }
} }

View file

@ -1,6 +1,4 @@
 function Set-NetboxDCIMFrontPort {
function Set-NetboxDCIMFrontPort
{
[CmdletBinding(ConfirmImpact = 'Medium', [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
@ -36,15 +34,12 @@ function Set-NetboxDCIMFrontPort
[switch]$Force [switch]$Force
) )
begin begin {
{
} }
process process {
{ foreach ($FrontPortID in $Id) {
foreach ($FrontPortID in $Id)
{
$CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop $CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id))
@ -53,15 +48,13 @@ function Set-NetboxDCIMFrontPort
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
if ($Force -or $pscmdlet.ShouldProcess("Front Port ID $($CurrentPort.Id)", "Set")) if ($Force -or $pscmdlet.ShouldProcess("Front Port ID $($CurrentPort.Id)", "Set")) {
{
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
} }
end end {
{
} }
} }

View file

@ -1,6 +1,5 @@
 
function Add-NetboxDCIMInterface function Add-NetboxDCIMInterface {
{
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
@ -38,30 +37,24 @@ function Add-NetboxDCIMInterface
[uint16[]]$Tagged_VLANs [uint16[]]$Tagged_VLANs
) )
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
{ $PSBoundParameters.Mode = switch ($Mode) {
$PSBoundParameters.Mode = switch ($Mode) 'Access' {
{
'Access'
{
100 100
break break
} }
'Tagged' 'Tagged' {
{
200 200
break break
} }
'Tagged All' 'Tagged All' {
{
300 300
break break
} }
default default {
{
$_ $_
} }
} }

View file

@ -1,6 +1,4 @@
 function Get-NetboxDCIMInterface {
function Get-NetboxDCIMInterface
{
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
@ -36,8 +34,7 @@ function Get-NetboxDCIMInterface
[switch]$Raw [switch]$Raw
) )
process process {
{
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters

View file

@ -1,6 +1,5 @@
 function Remove-NetboxDCIMInterface {
function Remove-NetboxDCIMInterface { <#
<#
.SYNOPSIS .SYNOPSIS
Removes an interface Removes an interface

View file

@ -1,6 +1,4 @@
 function Set-NetboxDCIMInterface {
function Set-NetboxDCIMInterface
{
[CmdletBinding(ConfirmImpact = 'Medium', [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
@ -43,42 +41,33 @@ function Set-NetboxDCIMInterface
[switch]$Force [switch]$Force
) )
begin begin {
{ if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) $PSBoundParameters.Mode = switch ($Mode) {
{ 'Access' {
$PSBoundParameters.Mode = switch ($Mode)
{
'Access'
{
100 100
break break
} }
'Tagged' 'Tagged' {
{
200 200
break break
} }
'Tagged All' 'Tagged All' {
{
300 300
break break
} }
default default {
{
$_ $_
} }
} }
} }
} }
process process {
{ foreach ($InterfaceId in $Id) {
foreach ($InterfaceId in $Id)
{
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop $CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
@ -87,15 +76,13 @@ function Set-NetboxDCIMInterface
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) {
{
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
} }
end end {
{
} }
} }

View file

@ -1,6 +1,4 @@
 function Add-NetboxDCIMRearPort {
function Add-NetboxDCIMRearPort
{
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
@ -27,15 +25,35 @@ function Add-NetboxDCIMRearPort
[bool]$Mark_Connected, [bool]$Mark_Connected,
[uint16[]]$Tags [uint16[]]$Tags,
[string[]]$Tags_Slug
) )
begin {
if (-not [System.String]::IsNullOrWhiteSpace($Tags_Slug)) {
if ([System.String]::IsNullOrWhiteSpace($Tags)) {
$PSBoundParameters.Tags = @()
}
foreach ($CurrentTagSlug in $Tags_Slug) {
$CurrentTagID = (Get-NetboxTag -slug $CurrentTagSlug -ErrorAction Stop).Id
$PSBoundParameters.Tags += $CurrentTagID
}
}
}
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Tags_Slug'
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
end {
}
} }

View file

@ -1,6 +1,4 @@
 function Get-NetboxDCIMRearPort {
function Get-NetboxDCIMRearPort
{
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
@ -23,8 +21,7 @@ function Get-NetboxDCIMRearPort
[switch]$Raw [switch]$Raw
) )
process process {
{
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports'))

View file

@ -1,6 +1,4 @@
 function Remove-NetboxDCIMRearPort {
function Remove-NetboxDCIMRearPort
{
[CmdletBinding(ConfirmImpact = 'High', [CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)] SupportsShouldProcess = $true)]
@ -13,19 +11,15 @@ function Remove-NetboxDCIMRearPort
[switch]$Force [switch]$Force
) )
begin begin {
{
} }
process process {
{ foreach ($RearPortID in $Id) {
foreach ($RearPortID in $Id)
{
$CurrentPort = Get-NetboxDCIMRearPort -Id $RearPortID -ErrorAction Stop $CurrentPort = Get-NetboxDCIMRearPort -Id $RearPortID -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) {
{
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports', $CurrentPort.Id)) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports', $CurrentPort.Id))
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
@ -35,8 +29,7 @@ function Remove-NetboxDCIMRearPort
} }
} }
end end {
{
} }
} }

View file

@ -1,6 +1,5 @@
 
function Get-NetboxTag function Get-NetboxTag {
{
[CmdletBinding()] [CmdletBinding()]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
@ -19,8 +18,7 @@ function Get-NetboxTag
[switch]$Raw [switch]$Raw
) )
process process {
{
$Segments = [System.Collections.ArrayList]::new(@('extras', 'tags')) $Segments = [System.Collections.ArrayList]::new(@('extras', 'tags'))