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

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

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

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

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

From PowerAruba/FortiPower Module :)

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

From PowerAruba/FortiPwoer Module :)

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

Like -SkipCertificate, Timeout...

* InvokeNetboxRequest: Add to Splat NetboxInvokeParams

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

Also enable TLS 1.1 and 1.2 for PS5

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

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

* Update psproj

* Correct typo

* Correct brace formatting

* Add Get/Set timeout functions

* Add Get/Set timeout functions

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

* Trim whitespaces

* Add Get-NetboxVersion function

* Remove API Definition caching and replace with Netbox version check

* Increment version to 1.4

* Fix Typo and Enhance AvailableIP Example (#18)

* AvailableIP(IPAM/Address): Fix typo

* AvailableIP(IAPM/Address): Enhance Example

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

* Update deployment files

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

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

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

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

Fix #17

* IPAMAddress(New): add Parameter example

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

Can be only dcim.interface or virtualization.vminterface

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

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

it is the standard with ShouldProcess

* Fix PSSA Warning (#20)

* Fix trailing white space

using Invoke-ScriptAnalyzer -Fix -Path . -Recurse

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

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

* PSSA: Fix PSUseDeclaredVarsMoreThanAssignments

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

* PSSA: Fix PSUseShouldProcessForStateChangingFunctions

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

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

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

* Update deploy.ps1 docs

* Update readme

* Remove unused files

* Increment version to 1.5.0

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

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

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

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

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

View file

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

View file

@ -105,6 +105,7 @@ function Get-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
process {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($i in $ID) { foreach ($i in $ID) {
@ -129,3 +130,4 @@ function Get-NetboxCircuit {
} }
} }
} }
}

View file

@ -54,6 +54,7 @@ function New-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
process {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$Method = 'POST' $Method = 'POST'
@ -65,3 +66,4 @@ function New-NetboxCircuit {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }
}

View file

@ -85,6 +85,7 @@ function Get-NetboxDCIMDevice {
#endregion Parameters #endregion Parameters
process {
if ($null -ne $Status) { if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
} }
@ -97,3 +98,4 @@ function Get-NetboxDCIMDevice {
InvokeNetboxRequest -URI $URI -Raw:$Raw InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
}

View file

@ -13,7 +13,8 @@
function New-NetboxDCIMDevice { function New-NetboxDCIMDevice {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
#region Parameters #region Parameters
param param
@ -67,15 +68,15 @@ function New-NetboxDCIMDevice {
# if ($null -ne $Device_Role) { # if ($null -ne $Device_Role) {
# # Validate device role? # # Validate device role?
# } # }
#
# if ($null -ne $Device_Type) { # if ($null -ne $Device_Type) {
# # Validate device type? # # Validate device type?
# } # }
#
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
@ -86,5 +87,7 @@ function New-NetboxDCIMDevice {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
} }
}

View file

@ -67,7 +67,7 @@ function Set-NetboxDCIMDevice {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }

View file

@ -54,8 +54,8 @@ function Add-NetboxDCIMInterfaceConnection {
} }
# Verify if both Interfaces exist # Verify if both Interfaces exist
$I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null
$I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))

View file

@ -47,6 +47,7 @@ function Get-NetboxDCIMInterface {
[switch]$Raw [switch]$Raw
) )
process {
if ($null -ne $Form_Factor) { if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
} }
@ -59,3 +60,4 @@ function Get-NetboxDCIMInterface {
InvokeNetboxRequest -URI $URI -Raw:$Raw InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
}

View file

@ -13,7 +13,8 @@
function Set-NetboxDCIMInterface { function Set-NetboxDCIMInterface {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -88,9 +89,11 @@ function Set-NetboxDCIMInterface {
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
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

@ -81,6 +81,7 @@ function Get-NetboxDCIMSite {
[switch]$Raw [switch]$Raw
) )
process {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($Site_ID in $ID) { foreach ($Site_ID in $ID) {
@ -105,4 +106,5 @@ function Get-NetboxDCIMSite {
} }
} }
} }
}

View file

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

View file

@ -50,14 +50,19 @@ function New-NetboxIPAMAddress {
.PARAMETER Dns_name .PARAMETER Dns_name
DNS Name of IP address (example : netbox.example.com) DNS Name of IP address (example : netbox.example.com)
.PARAMETER Force .PARAMETER Assigned_Object_Type
Do not prompt for confirmation to create IP. Assigned Object Type dcim.interface or virtualization.vminterface
.PARAMETER Assigned_Object_Id
Assigned Object ID
.PARAMETER Raw .PARAMETER Raw
Return raw results from API service Return raw results from API service
.EXAMPLE .EXAMPLE
PS C:\> Create-NetboxIPAMAddress New-NetboxIPAMAddress -Address 192.0.2.1/32
Add new IP Address 192.0.2.1/32 with status active
.NOTES .NOTES
Additional information about the function. Additional information about the function.
@ -90,7 +95,10 @@ function New-NetboxIPAMAddress {
[string]$Dns_name, [string]$Dns_name,
[switch]$Force, [ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
[int]$Assigned_Object_Id,
[switch]$Raw [switch]$Raw
) )
@ -99,22 +107,11 @@ function New-NetboxIPAMAddress {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses')) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST' $Method = 'POST'
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
# foreach ($Property in $EnumProperties.Keys) {
# if ($PSBoundParameters.ContainsKey($Property)) {
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
# }
# }
#
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) { if ($PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }

View file

@ -13,6 +13,8 @@
function New-NetboxIPAMPrefix { function New-NetboxIPAMPrefix {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[CmdletBinding()] [CmdletBinding()]
param param
( (
@ -55,5 +57,7 @@ function New-NetboxIPAMPrefix {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}

View file

@ -40,7 +40,8 @@
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -64,7 +65,7 @@
) )
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
#
# if ($null -ne $Role) { # if ($null -ne $Role) {
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
# } # }
@ -75,5 +76,7 @@
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}

View file

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

View file

@ -141,6 +141,7 @@ function Get-NetboxVirtualMachine {
[switch]$Raw [switch]$Raw
) )
process {
if ($null -ne $Status) { if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
} }
@ -153,3 +154,4 @@ function Get-NetboxVirtualMachine {
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }
}

View file

@ -13,7 +13,8 @@
function New-NetboxVirtualMachine { function New-NetboxVirtualMachine {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -47,12 +48,12 @@ function New-NetboxVirtualMachine {
) )
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
#
# # Validate the status against the APIDefinition # # Validate the status against the APIDefinition
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) { # if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
# } # }
#
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
@ -61,8 +62,10 @@ function New-NetboxVirtualMachine {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
} }
}

View file

@ -53,7 +53,8 @@ function Set-NetboxVirtualMachine {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# } # }
#
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
Write-Verbose "Obtaining VM from ID $Id" Write-Verbose "Obtaining VM from ID $Id"
@ -70,3 +71,4 @@ function Set-NetboxVirtualMachine {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
}

View file

@ -84,6 +84,7 @@ function Get-NetboxVirtualMachineInterface {
[switch]$Raw [switch]$Raw
) )
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
@ -92,3 +93,4 @@ function Get-NetboxVirtualMachineInterface {
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }
}

View file

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

View file

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

View file

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

View file

@ -147,8 +147,8 @@ function Add-NetboxDCIMInterfaceConnection {
} }
# Verify if both Interfaces exist # Verify if both Interfaces exist
$I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null
$I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
@ -428,25 +428,6 @@ function CheckNetboxIsConnected {
} }
} }
#endregion
#region File Circuits.ps1
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
Created on: 2/28/2018 4:06 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: Circuits.ps1
===========================================================================
.DESCRIPTION
Circuit object functions
#>
#endregion #endregion
#region File Clear-NetboxCredential.ps1 #region File Clear-NetboxCredential.ps1
@ -921,6 +902,7 @@ function Get-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
process {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($i in $ID) { foreach ($i in $ID) {
@ -945,6 +927,7 @@ function Get-NetboxCircuit {
} }
} }
} }
}
#endregion #endregion
@ -1291,6 +1274,7 @@ function Get-NetboxDCIMDevice {
#endregion Parameters #endregion Parameters
process {
if ($null -ne $Status) { if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
} }
@ -1303,6 +1287,7 @@ function Get-NetboxDCIMDevice {
InvokeNetboxRequest -URI $URI -Raw:$Raw InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
}
#endregion #endregion
@ -1490,6 +1475,7 @@ function Get-NetboxDCIMInterface {
[switch]$Raw [switch]$Raw
) )
process {
if ($null -ne $Form_Factor) { if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
} }
@ -1502,6 +1488,7 @@ function Get-NetboxDCIMInterface {
InvokeNetboxRequest -URI $URI -Raw:$Raw InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
}
#endregion #endregion
@ -1709,6 +1696,7 @@ function Get-NetboxDCIMSite {
[switch]$Raw [switch]$Raw
) )
process {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($Site_ID in $ID) { foreach ($Site_ID in $ID) {
@ -1733,6 +1721,7 @@ function Get-NetboxDCIMSite {
} }
} }
} }
}
#endregion #endregion
@ -2021,7 +2010,14 @@ function Get-NetboxIPAMAvailableIP {
A description of the NumberOfIPs parameter. A description of the NumberOfIPs parameter.
.EXAMPLE .EXAMPLE
PS C:\> Get-NetboxIPAMAvaiableIP -Prefix_ID $value1 Get-NetboxIPAMAvailableIP -Prefix_ID (Get-NetboxIPAMPrefix -Prefix 192.0.2.0/24).id
Get (Next) Available IP on the Prefix 192.0.2.0/24
.EXAMPLE
Get-NetboxIPAMAvailableIP -Prefix_ID 2 -NumberOfIPs 3
Get 3 (Next) Available IP on the Prefix 192.0.2.0/24
.NOTES .NOTES
Additional information about the function. Additional information about the function.
@ -2947,6 +2943,7 @@ function Get-NetboxVirtualMachine {
[switch]$Raw [switch]$Raw
) )
process {
if ($null -ne $Status) { if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
} }
@ -2959,6 +2956,7 @@ function Get-NetboxVirtualMachine {
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }
}
#endregion #endregion
@ -3050,6 +3048,7 @@ function Get-NetboxVirtualMachineInterface {
[switch]$Raw [switch]$Raw
) )
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
@ -3058,6 +3057,7 @@ function Get-NetboxVirtualMachineInterface {
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }
}
#endregion #endregion
@ -3231,6 +3231,7 @@ function New-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
process {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$Method = 'POST' $Method = 'POST'
@ -3242,6 +3243,7 @@ function New-NetboxCircuit {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }
}
#endregion #endregion
@ -3262,7 +3264,8 @@ function New-NetboxCircuit {
function New-NetboxDCIMDevice { function New-NetboxDCIMDevice {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
#region Parameters #region Parameters
param param
@ -3316,15 +3319,15 @@ function New-NetboxDCIMDevice {
# if ($null -ne $Device_Role) { # if ($null -ne $Device_Role) {
# # Validate device role? # # Validate device role?
# } # }
#
# if ($null -ne $Device_Type) { # if ($null -ne $Device_Type) {
# # Validate device type? # # Validate device type?
# } # }
#
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
@ -3335,8 +3338,10 @@ function New-NetboxDCIMDevice {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
} }
}
#endregion #endregion
@ -3394,14 +3399,19 @@ function New-NetboxIPAMAddress {
.PARAMETER Dns_name .PARAMETER Dns_name
DNS Name of IP address (example : netbox.example.com) DNS Name of IP address (example : netbox.example.com)
.PARAMETER Force .PARAMETER Assigned_Object_Type
Do not prompt for confirmation to create IP. Assigned Object Type dcim.interface or virtualization.vminterface
.PARAMETER Assigned_Object_Id
Assigned Object ID
.PARAMETER Raw .PARAMETER Raw
Return raw results from API service Return raw results from API service
.EXAMPLE .EXAMPLE
PS C:\> Create-NetboxIPAMAddress New-NetboxIPAMAddress -Address 192.0.2.1/32
Add new IP Address 192.0.2.1/32 with status active
.NOTES .NOTES
Additional information about the function. Additional information about the function.
@ -3434,7 +3444,10 @@ function New-NetboxIPAMAddress {
[string]$Dns_name, [string]$Dns_name,
[switch]$Force, [ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
[int]$Assigned_Object_Id,
[switch]$Raw [switch]$Raw
) )
@ -3443,22 +3456,11 @@ function New-NetboxIPAMAddress {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses')) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST' $Method = 'POST'
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
# foreach ($Property in $EnumProperties.Keys) {
# if ($PSBoundParameters.ContainsKey($Property)) {
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
# }
# }
#
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) { if ($PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }
@ -3488,6 +3490,8 @@ function New-NetboxIPAMAddress {
function New-NetboxIPAMPrefix { function New-NetboxIPAMPrefix {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[CmdletBinding()] [CmdletBinding()]
param param
( (
@ -3530,8 +3534,10 @@ function New-NetboxIPAMPrefix {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}
#endregion #endregion
@ -3579,7 +3585,8 @@ function New-NetboxIPAMVLAN {
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -3603,7 +3610,7 @@ function New-NetboxIPAMVLAN {
) )
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
#
# if ($null -ne $Role) { # if ($null -ne $Role) {
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
# } # }
@ -3614,8 +3621,10 @@ function New-NetboxIPAMVLAN {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}
#endregion #endregion
@ -3636,7 +3645,8 @@ function New-NetboxIPAMVLAN {
function New-NetboxVirtualMachine { function New-NetboxVirtualMachine {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -3670,12 +3680,12 @@ function New-NetboxVirtualMachine {
) )
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
#
# # Validate the status against the APIDefinition # # Validate the status against the APIDefinition
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) { # if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
# } # }
#
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
@ -3684,8 +3694,10 @@ function New-NetboxVirtualMachine {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
} }
}
@ -4153,7 +4165,7 @@ function Set-NetboxDCIMDevice {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
@ -4199,7 +4211,8 @@ function Set-NetboxDCIMDevice {
function Set-NetboxDCIMInterface { function Set-NetboxDCIMInterface {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -4274,9 +4287,11 @@ function Set-NetboxDCIMInterface {
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
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 {
@ -4767,7 +4782,8 @@ function Set-NetboxVirtualMachine {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# } # }
#
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
Write-Verbose "Obtaining VM from ID $Id" Write-Verbose "Obtaining VM from ID $Id"
@ -4784,6 +4800,7 @@ function Set-NetboxVirtualMachine {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
}
#endregion #endregion
@ -4882,47 +4899,6 @@ function SetupNetboxConfigVariable {
#endregion #endregion
#region File Tenancy.ps1
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
Created on: 5/29/2018 1:45 PM
Created by: Ben Claussen
Organization: NEOnet
Filename: Tenancy.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
#region GET commands
#endregion GET commands
#region SET commands
#endregion SET commands
#region ADD/NEW commands
#endregion ADD/NEW commands
#region REMOVE commands
#endregion REMOVE commands
#endregion
#region File ThrowNetboxRESTError.ps1 #region File ThrowNetboxRESTError.ps1
<# <#
@ -4979,7 +4955,7 @@ function VerifyAPIConnectivity {
Script generated by PowerShell Studio 2020 Script generated by PowerShell Studio 2020
#> #>
# Build a list of common paramters so we can omit them to build URI parameters # Build a list of common parameters so we can omit them to build URI parameters
$script:CommonParameterNames = New-Object System.Collections.ArrayList $script:CommonParameterNames = New-Object System.Collections.ArrayList
[void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters)) [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters))
[void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::OptionalCommonParameters)) [void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::OptionalCommonParameters))

View file

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

View file

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