mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-15 02:35:46 +00:00
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:
parent
115b28a48d
commit
ec1eb869b3
15 changed files with 82 additions and 124 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -6,5 +6,6 @@
|
|||
"powershell.codeFormatting.newLineAfterCloseBrace": false,
|
||||
"[markdown]": {
|
||||
"files.trimTrailingWhitespace": false,
|
||||
}
|
||||
},
|
||||
"powershell.codeFormatting.openBraceOnSameLine": true
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Get-NetboxDCIMCableTermination
|
||||
{
|
||||
function Get-NetboxDCIMCableTermination {
|
||||
[CmdletBinding()]
|
||||
#region Parameters
|
||||
param
|
||||
|
|
@ -25,8 +23,7 @@ function Get-NetboxDCIMCableTermination
|
|||
|
||||
#endregion Parameters
|
||||
|
||||
process
|
||||
{
|
||||
process {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'cable-terminations'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Get-NetboxDCIMCable
|
||||
{
|
||||
function Get-NetboxDCIMCable {
|
||||
[CmdletBinding()]
|
||||
#region Parameters
|
||||
param
|
||||
|
|
@ -45,8 +43,7 @@ function Get-NetboxDCIMCable
|
|||
|
||||
#endregion Parameters
|
||||
|
||||
process
|
||||
{
|
||||
process {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'cables'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Add-NetboxDCIMFrontPort
|
||||
{
|
||||
function Add-NetboxDCIMFrontPort {
|
||||
[CmdletBinding()]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Get-NetboxDCIMFrontPort
|
||||
{
|
||||
function Get-NetboxDCIMFrontPort {
|
||||
[CmdletBinding()]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
|
|
@ -23,8 +21,7 @@ function Get-NetboxDCIMFrontPort
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process
|
||||
{
|
||||
process {
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports'))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Remove-NetboxDCIMFrontPort
|
||||
{
|
||||
function Remove-NetboxDCIMFrontPort {
|
||||
|
||||
[CmdletBinding(ConfirmImpact = 'High',
|
||||
SupportsShouldProcess = $true)]
|
||||
|
|
@ -13,19 +11,15 @@ function Remove-NetboxDCIMFrontPort
|
|||
[switch]$Force
|
||||
)
|
||||
|
||||
begin
|
||||
{
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process
|
||||
{
|
||||
foreach ($FrontPortID in $Id)
|
||||
{
|
||||
process {
|
||||
foreach ($FrontPortID in $Id) {
|
||||
$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))
|
||||
|
||||
$URI = BuildNewURI -Segments $Segments
|
||||
|
|
@ -35,8 +29,7 @@ function Remove-NetboxDCIMFrontPort
|
|||
}
|
||||
}
|
||||
|
||||
end
|
||||
{
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Set-NetboxDCIMFrontPort
|
||||
{
|
||||
function Set-NetboxDCIMFrontPort {
|
||||
[CmdletBinding(ConfirmImpact = 'Medium',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([pscustomobject])]
|
||||
|
|
@ -36,15 +34,12 @@ function Set-NetboxDCIMFrontPort
|
|||
[switch]$Force
|
||||
)
|
||||
|
||||
begin
|
||||
{
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process
|
||||
{
|
||||
foreach ($FrontPortID in $Id)
|
||||
{
|
||||
process {
|
||||
foreach ($FrontPortID in $Id) {
|
||||
$CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id))
|
||||
|
|
@ -53,15 +48,13 @@ function Set-NetboxDCIMFrontPort
|
|||
|
||||
$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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end
|
||||
{
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
function Add-NetboxDCIMInterface
|
||||
{
|
||||
function Add-NetboxDCIMInterface {
|
||||
[CmdletBinding()]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
|
|
@ -38,30 +37,24 @@ function Add-NetboxDCIMInterface
|
|||
[uint16[]]$Tagged_VLANs
|
||||
)
|
||||
|
||||
if (-not [System.String]::IsNullOrWhiteSpace($Mode))
|
||||
{
|
||||
$PSBoundParameters.Mode = switch ($Mode)
|
||||
{
|
||||
'Access'
|
||||
{
|
||||
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
|
||||
$PSBoundParameters.Mode = switch ($Mode) {
|
||||
'Access' {
|
||||
100
|
||||
break
|
||||
}
|
||||
|
||||
'Tagged'
|
||||
{
|
||||
'Tagged' {
|
||||
200
|
||||
break
|
||||
}
|
||||
|
||||
'Tagged All'
|
||||
{
|
||||
'Tagged All' {
|
||||
300
|
||||
break
|
||||
}
|
||||
|
||||
default
|
||||
{
|
||||
default {
|
||||
$_
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Get-NetboxDCIMInterface
|
||||
{
|
||||
function Get-NetboxDCIMInterface {
|
||||
[CmdletBinding()]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
|
|
@ -36,8 +34,7 @@ function Get-NetboxDCIMInterface
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process
|
||||
{
|
||||
process {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
function Remove-NetboxDCIMInterface {
|
||||
<#
|
||||
function Remove-NetboxDCIMInterface {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes an interface
|
||||
|
||||
|
|
@ -21,11 +20,11 @@ function Remove-NetboxDCIMInterface {
|
|||
#>
|
||||
|
||||
[CmdletBinding(ConfirmImpact = 'High',
|
||||
SupportsShouldProcess = $true)]
|
||||
SupportsShouldProcess = $true)]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true,
|
||||
ValueFromPipelineByPropertyName = $true)]
|
||||
ValueFromPipelineByPropertyName = $true)]
|
||||
[uint16[]]$Id,
|
||||
|
||||
[switch]$Force
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Set-NetboxDCIMInterface
|
||||
{
|
||||
function Set-NetboxDCIMInterface {
|
||||
[CmdletBinding(ConfirmImpact = 'Medium',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([pscustomobject])]
|
||||
|
|
@ -43,42 +41,33 @@ function Set-NetboxDCIMInterface
|
|||
[switch]$Force
|
||||
)
|
||||
|
||||
begin
|
||||
{
|
||||
if (-not [System.String]::IsNullOrWhiteSpace($Mode))
|
||||
{
|
||||
$PSBoundParameters.Mode = switch ($Mode)
|
||||
{
|
||||
'Access'
|
||||
{
|
||||
begin {
|
||||
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
|
||||
$PSBoundParameters.Mode = switch ($Mode) {
|
||||
'Access' {
|
||||
100
|
||||
break
|
||||
}
|
||||
|
||||
'Tagged'
|
||||
{
|
||||
'Tagged' {
|
||||
200
|
||||
break
|
||||
}
|
||||
|
||||
'Tagged All'
|
||||
{
|
||||
'Tagged All' {
|
||||
300
|
||||
break
|
||||
}
|
||||
|
||||
default
|
||||
{
|
||||
default {
|
||||
$_
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process
|
||||
{
|
||||
foreach ($InterfaceId in $Id)
|
||||
{
|
||||
process {
|
||||
foreach ($InterfaceId in $Id) {
|
||||
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
|
||||
|
|
@ -87,15 +76,13 @@ function Set-NetboxDCIMInterface
|
|||
|
||||
$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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end
|
||||
{
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Add-NetboxDCIMRearPort
|
||||
{
|
||||
function Add-NetboxDCIMRearPort {
|
||||
[CmdletBinding()]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
|
|
@ -27,15 +25,35 @@ function Add-NetboxDCIMRearPort
|
|||
|
||||
[bool]$Mark_Connected,
|
||||
|
||||
[uint16[]]$Tags
|
||||
[uint16[]]$Tags,
|
||||
|
||||
[string[]]$Tags_Slug
|
||||
|
||||
)
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports'))
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
|
||||
process {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports'))
|
||||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Tags_Slug'
|
||||
|
||||
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
|
||||
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Get-NetboxDCIMRearPort
|
||||
{
|
||||
function Get-NetboxDCIMRearPort {
|
||||
[CmdletBinding()]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
|
|
@ -23,8 +21,7 @@ function Get-NetboxDCIMRearPort
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process
|
||||
{
|
||||
process {
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports'))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
function Remove-NetboxDCIMRearPort
|
||||
{
|
||||
function Remove-NetboxDCIMRearPort {
|
||||
|
||||
[CmdletBinding(ConfirmImpact = 'High',
|
||||
SupportsShouldProcess = $true)]
|
||||
|
|
@ -13,19 +11,15 @@ function Remove-NetboxDCIMRearPort
|
|||
[switch]$Force
|
||||
)
|
||||
|
||||
begin
|
||||
{
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process
|
||||
{
|
||||
foreach ($RearPortID in $Id)
|
||||
{
|
||||
process {
|
||||
foreach ($RearPortID in $Id) {
|
||||
$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))
|
||||
|
||||
$URI = BuildNewURI -Segments $Segments
|
||||
|
|
@ -35,8 +29,7 @@ function Remove-NetboxDCIMRearPort
|
|||
}
|
||||
}
|
||||
|
||||
end
|
||||
{
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
function Get-NetboxTag
|
||||
{
|
||||
function Get-NetboxTag {
|
||||
[CmdletBinding()]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
|
|
@ -19,8 +18,7 @@ function Get-NetboxTag
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process
|
||||
{
|
||||
process {
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('extras', 'tags'))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue