diff --git a/Functions/Circuits/Get-NetboxCircuitsChoices.ps1 b/Functions/Circuits/Get-NetboxCircuitsChoices.ps1 deleted file mode 100644 index 67fbbdf..0000000 --- a/Functions/Circuits/Get-NetboxCircuitsChoices.ps1 +++ /dev/null @@ -1,38 +0,0 @@ -<# - .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 -} diff --git a/Functions/DCIM/Get-NetboxDCIMChoices.ps1 b/Functions/DCIM/Get-NetboxDCIMChoices.ps1 deleted file mode 100644 index 55104dd..0000000 --- a/Functions/DCIM/Get-NetboxDCIMChoices.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -<# - .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 -} \ No newline at end of file diff --git a/Functions/DCIM/ValidateDCIMChoice.ps1 b/Functions/DCIM/ValidateDCIMChoice.ps1 deleted file mode 100644 index 25b3130..0000000 --- a/Functions/DCIM/ValidateDCIMChoice.ps1 +++ /dev/null @@ -1,102 +0,0 @@ -function ValidateDCIMChoice { -<# - .SYNOPSIS - Internal function to validate provided values for static choices - - .DESCRIPTION - When users connect to the API, choices for each major object are cached to the config variable. - These values are then utilized to validate if the provided value from a user is valid. - - .PARAMETER ProvidedValue - The value to validate against static choices - - .PARAMETER PowerConnectionStatus - Validate against power connection status values - - .PARAMETER InterfaceTemplateFormFactor - Validate against interface template form factor values - - .PARAMETER InterfaceConnectionStatus - Validate against interface connection status values - - .PARAMETER InterfaceFormFactor - Validate against interface form factor values - - .PARAMETER ConsolePortConnectionStatus - Validate against console port connection status values - - .PARAMETER DeviceStatus - Validate against device status values - - .PARAMETER DeviceFace - Validate against device face values - - .PARAMETER RackType - Validate against rack type values - - .PARAMETER RackWidth - Validate against rack width values. - - .EXAMPLE - PS C:\> ValidateDCIMChoice -ProvidedValue 'rear' -DeviceFace - - .EXAMPLE - PS C:\> ValidateDCIMChoice -ProvidedValue 'middle' -DeviceFace - >> Invalid value middle for device:face. Must be one of: 0, 1, Front, Rear - - .OUTPUTS - This function returns the integer value if valid. Otherwise, it will throw an error. - - .NOTES - Additional information about the function. - - .FUNCTIONALITY - This cmdlet is intended to be used internally and not exposed to the user -#> - - [CmdletBinding()] - [OutputType([uint16])] - param - ( - [Parameter(Mandatory = $true)] - [object]$ProvidedValue, - - [Parameter(ParameterSetName = 'power-port:connection_status', - Mandatory = $true)] - [switch]$PowerConnectionStatus, - - [Parameter(ParameterSetName = 'interface-template:form_factor', - Mandatory = $true)] - [switch]$InterfaceTemplateFormFactor, - - [Parameter(ParameterSetName = 'interface-connection:connection_status', - Mandatory = $true)] - [switch]$InterfaceConnectionStatus, - - [Parameter(ParameterSetName = 'interface:form_factor', - Mandatory = $true)] - [switch]$InterfaceFormFactor, - - [Parameter(ParameterSetName = 'console-port:connection_status', - Mandatory = $true)] - [switch]$ConsolePortConnectionStatus, - - [Parameter(ParameterSetName = 'device:status', - Mandatory = $true)] - [switch]$DeviceStatus, - - [Parameter(ParameterSetName = 'device:face', - Mandatory = $true)] - [switch]$DeviceFace, - - [Parameter(ParameterSetName = 'rack:type', - Mandatory = $true)] - [switch]$RackType, - - [Parameter(ParameterSetName = 'rack:width', - Mandatory = $true)] - [switch]$RackWidth - ) - - ValidateChoice -MajorObject 'DCIM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue -} \ No newline at end of file diff --git a/Functions/Extras/Get-NetboxExtrasChoices.ps1 b/Functions/Extras/Get-NetboxExtrasChoices.ps1 deleted file mode 100644 index 78118e0..0000000 --- a/Functions/Extras/Get-NetboxExtrasChoices.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -function Get-NetboxExtrasChoices { - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")] - param () - - $uriSegments = [System.Collections.ArrayList]::new(@('extras', '_choices')) - - $uri = BuildNewURI -Segments $uriSegments - - InvokeNetboxRequest -URI $uri -} diff --git a/Functions/Helpers/GetChoiceValidValues.ps1 b/Functions/Helpers/GetChoiceValidValues.ps1 deleted file mode 100644 index 7579416..0000000 --- a/Functions/Helpers/GetChoiceValidValues.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: GetChoiceValidValues.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - -function GetChoiceValidValues { - [CmdletBinding()] - [OutputType([System.Collections.ArrayList])] - param - ( - [Parameter(Mandatory = $true)] - [string]$MajorObject, - - [Parameter(Mandatory = $true)] - [object]$Choice - ) - - $ValidValues = New-Object System.Collections.ArrayList - - if (-not $script:NetboxConfig.Choices.$MajorObject.$Choice) { - throw "Missing choices for $Choice" - } - - [void]$ValidValues.AddRange($script:NetboxConfig.Choices.$MajorObject.$Choice.value) - [void]$ValidValues.AddRange($script:NetboxConfig.Choices.$MajorObject.$Choice.label) - - if ($ValidValues.Count -eq 0) { - throw "Missing valid values for $MajorObject.$Choice" - } - - return [System.Collections.ArrayList]$ValidValues -} \ No newline at end of file diff --git a/Functions/Helpers/ValidateChoice.ps1 b/Functions/Helpers/ValidateChoice.ps1 deleted file mode 100644 index bb99844..0000000 --- a/Functions/Helpers/ValidateChoice.ps1 +++ /dev/null @@ -1,76 +0,0 @@ -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: ValidateChoice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - -function ValidateChoice { - [CmdletBinding()] - [OutputType([uint16], [string], [bool])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateSet('Circuits', 'DCIM', 'Extras', 'IPAM', 'Virtualization', IgnoreCase = $true)] - [string]$MajorObject, - - [Parameter(Mandatory = $true)] - [string]$ChoiceName, - - [Parameter(Mandatory = $true)] - [object]$ProvidedValue - ) - - $ValidValues = GetChoiceValidValues -MajorObject $MajorObject -Choice $ChoiceName - - Write-Verbose "Validating $ChoiceName" - Write-Verbose "Checking '$ProvidedValue' against [$($ValidValues -join ', ')]" - - # Coercing everything to strings for matching... - # some values are integers, some are strings, some are booleans - # Join the valid values with a pipe as a delimeter, because some values have spaces - if (([string]($ValidValues -join '|') -split '\|') -inotcontains [string]$ProvidedValue) { - throw "Invalid value '$ProvidedValue' for '$ChoiceName'. Must be one of: $($ValidValues -join ', ')" - } - - switch -wildcard ("$MajorObject/$ChoiceName") { - "Circuits" { - # This has things that are not integers - } - - "DCIM/*connection_status" { - # This has true/false values instead of integers - try { - $val = [bool]::Parse($ProvidedValue) - } catch { - # It must not be a true/false value - $val = $script:NetboxConfig.Choices.$MajorObject.$ChoiceName.Where({ - $_.Label -eq $ProvidedValue - }).Value - } - - return $val - } - - default { - # Convert the ProvidedValue to the integer value - try { - $intVal = [uint16]"$ProvidedValue" - } catch { - # It must not be a number, get the value from the label - $intVal = [uint16]$script:NetboxConfig.Choices.$MajorObject.$ChoiceName.Where({ - $_.Label -eq $ProvidedValue - }).Value - } - - return $intVal - } - } -} \ No newline at end of file diff --git a/Functions/IPAM/Get-NetboxIPAMChoices.ps1 b/Functions/IPAM/Get-NetboxIPAMChoices.ps1 deleted file mode 100644 index 13d1c99..0000000 --- a/Functions/IPAM/Get-NetboxIPAMChoices.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -<# - .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 -} \ No newline at end of file diff --git a/Functions/IPAM/ValidateIPAMChoice.ps1 b/Functions/IPAM/ValidateIPAMChoice.ps1 deleted file mode 100644 index 6b46427..0000000 --- a/Functions/IPAM/ValidateIPAMChoice.ps1 +++ /dev/null @@ -1,109 +0,0 @@ -<# - .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 - Internal function to verify provided values for static choices - - .DESCRIPTION - When users connect to the API, choices for each major object are cached to the config variable. - These values are then utilized to verify if the provided value from a user is valid. - - .PARAMETER ProvidedValue - The value to validate against static choices - - .PARAMETER AggregateFamily - Verify against aggregate family values - - .PARAMETER PrefixFamily - Verify against prefix family values - - .PARAMETER PrefixStatus - Verify against prefix status values - - .PARAMETER IPAddressFamily - Verify against ip-address family values - - .PARAMETER IPAddressStatus - Verify against ip-address status values - - .PARAMETER IPAddressRole - Verify against ip-address role values - - .PARAMETER VLANStatus - Verify against VLAN status values - - .PARAMETER ServiceProtocol - Verify against service protocol values - - .EXAMPLE - PS C:\> ValidateIPAMChoice -ProvidedValue 'loopback' -IPAddressRole - - .EXAMPLE - PS C:\> ValidateIPAMChoice -ProvidedValue 'Loopback' -IPAddressFamily - >> Invalid value Loopback for ip-address:family. Must be one of: 4, 6, IPv4, IPv6 - - .OUTPUTS - This function returns the integer value if valid. Otherwise, it will throw an error. - - .NOTES - Additional information about the function. - - .FUNCTIONALITY - This cmdlet is intended to be used internally and not exposed to the user -#> - - [CmdletBinding(DefaultParameterSetName = 'service:protocol')] - [OutputType([uint16])] - param - ( - [Parameter(Mandatory = $true)] - [object]$ProvidedValue, - - [Parameter(ParameterSetName = 'aggregate:family', - Mandatory = $true)] - [switch]$AggregateFamily, - - [Parameter(ParameterSetName = 'prefix:family', - Mandatory = $true)] - [switch]$PrefixFamily, - - [Parameter(ParameterSetName = 'prefix:status', - Mandatory = $true)] - [switch]$PrefixStatus, - - [Parameter(ParameterSetName = 'ip-address:family', - Mandatory = $true)] - [switch]$IPAddressFamily, - - [Parameter(ParameterSetName = 'ip-address:status', - Mandatory = $true)] - [switch]$IPAddressStatus, - - [Parameter(ParameterSetName = 'ip-address:role', - Mandatory = $true)] - [switch]$IPAddressRole, - - [Parameter(ParameterSetName = 'vlan:status', - Mandatory = $true)] - [switch]$VLANStatus, - - [Parameter(ParameterSetName = 'service:protocol', - Mandatory = $true)] - [switch]$ServiceProtocol - ) - - ValidateChoice -MajorObject 'IPAM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue -} \ No newline at end of file diff --git a/Functions/Tenancy/Get-NetboxTenancyChoices.ps1 b/Functions/Tenancy/Get-NetboxTenancyChoices.ps1 deleted file mode 100644 index 1017a91..0000000 --- a/Functions/Tenancy/Get-NetboxTenancyChoices.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -<# - .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 -} \ No newline at end of file diff --git a/Functions/Virtualization/Get-NetboxVirtualizationChoices.ps1 b/Functions/Virtualization/Get-NetboxVirtualizationChoices.ps1 deleted file mode 100644 index 1e12a9d..0000000 --- a/Functions/Virtualization/Get-NetboxVirtualizationChoices.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -<# - .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 -} \ No newline at end of file diff --git a/Functions/Virtualization/ValidateVirtualizationChoice.ps1 b/Functions/Virtualization/ValidateVirtualizationChoice.ps1 deleted file mode 100644 index 76ccf6b..0000000 --- a/Functions/Virtualization/ValidateVirtualizationChoice.ps1 +++ /dev/null @@ -1,76 +0,0 @@ -<# - .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 - Internal function to verify provided values for static choices - - .DESCRIPTION - When users connect to the API, choices for each major object are cached to the config variable. - These values are then utilized to verify if the provided value from a user is valid. - - .PARAMETER ProvidedValue - The value to validate against static choices - - .PARAMETER AggregateFamily - Verify against aggregate family values - - .PARAMETER PrefixFamily - Verify against prefix family values - - .PARAMETER PrefixStatus - Verify against prefix status values - - .PARAMETER IPAddressFamily - Verify against ip-address family values - - .PARAMETER IPAddressStatus - Verify against ip-address status values - - .PARAMETER IPAddressRole - Verify against ip-address role values - - .PARAMETER VLANStatus - Verify against VLAN status values - - .PARAMETER ServiceProtocol - Verify against service protocol values - - .EXAMPLE - PS C:\> VerifyIPAMChoices -ProvidedValue 'loopback' -IPAddressRole - - .EXAMPLE - PS C:\> VerifyIPAMChoices -ProvidedValue 'Loopback' -IPAddressFamily - >> Invalid value Loopback for ip-address:family. Must be one of: 4, 6, IPv4, IPv6 - - .FUNCTIONALITY - This cmdlet is intended to be used internally and not exposed to the user - - .OUTPUT - This function returns nothing if the value is valid. Otherwise, it will throw an error. -#> - - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [object]$ProvidedValue, - - [Parameter(ParameterSetName = 'virtual-machine:status', - Mandatory = $true)] - [switch]$VirtualMachineStatus - ) - - ValidateChoice -MajorObject 'Virtualization' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue -} \ No newline at end of file diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 244e33d..787786b 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.2.1' +ModuleVersion = '1.2.2' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS.psproj b/NetboxPS.psproj index 8551fec..c1ba101 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -5,7 +5,6 @@ Functions Functions\DCIM - Functions\Extras Functions\Circuits Functions\Virtualization Functions\IPAM @@ -47,8 +46,6 @@ Functions\Helpers\CheckNetboxIsConnected.ps1 Functions\Helpers\BuildNewURI.ps1 Functions\Helpers\BuildURIComponents.ps1 - Functions\Helpers\GetChoiceValidValues.ps1 - Functions\Helpers\ValidateChoice.ps1 Functions\Helpers\GetNetboxAPIErrorBody.ps1 Functions\Helpers\InvokeNetboxRequest.ps1 Functions\Helpers\ThrowNetboxRESTError.ps1 @@ -61,8 +58,6 @@ Functions\Setup\Set-NetboxCredential.ps1 Functions\Setup\Get-NetboxCredential.ps1 Functions\Setup\Connect-NetboxAPI.ps1 - Functions\Extras\Get-NetboxExtrasChoices.ps1 - Functions\DCIM\ValidateDCIMChoice.ps1 Functions\IPAM\VLAN\Get-NetboxIPAMVLAN.ps1 Functions\IPAM\VLAN\New-NetboxIPAMVLAN.ps1 Functions\IPAM\Role\Get-NetboxIPAMRole.ps1 @@ -74,10 +69,7 @@ Functions\IPAM\Prefix\New-NetboxIPAMPrefix.ps1 Functions\IPAM\Address\Remove-NetboxIPAMAddress.ps1 Functions\IPAM\Address\Set-NetboxIPAMAddress.ps1 - Functions\IPAM\ValidateIPAMChoice.ps1 - Functions\IPAM\Get-NetboxIPAMChoices.ps1 Functions\Tenancy\Get-NetboxTenant.ps1 - Functions\Tenancy\Get-NetboxTenancyChoices.ps1 Functions\Virtualization\VirtualMachine\Get-NetboxVirtualMachine.ps1 Functions\Virtualization\VirtualMachine\New-NetboxVirtualMachine.ps1 Functions\Virtualization\VirtualMachine\Set-NetboxVirtualMachine.ps1 @@ -85,10 +77,8 @@ Functions\Virtualization\VirtualMachineInterface\Add-NetboxVirtualMachineInterface.ps1 Functions\Virtualization\VirtualMachineInterface\Get-NetboxVirtualMachineInterface.ps1 Functions\Virtualization\VirtualMachineInterface\Set-NetboxVirtualMachineInterface.ps1 - Functions\Virtualization\Get-NetboxVirtualizationChoices.ps1 Functions\Virtualization\VirtualizationCluster\Get-NetboxVirtualizationCluster.ps1 Functions\Virtualization\VirtualizationCluster\Get-NetboxVirtualizationClusterGroup.ps1 - Functions\Virtualization\ValidateVirtualizationChoice.ps1 Functions\DCIM\Devices\Get-NetboxDCIMDevice.ps1 Functions\DCIM\Devices\Get-NetboxDCIMDeviceType.ps1 Functions\DCIM\Devices\Get-NetboxDCIMDeviceRole.ps1 @@ -104,8 +94,6 @@ Functions\DCIM\Interfaces\Remove-NetboxDCIMInterface.ps1 Functions\DCIM\Interfaces\Remove-NetboxDCIMInterfaceConnection.ps1 Functions\DCIM\Get-NetboxDCIMPlatform.ps1 - Functions\DCIM\Get-NetboxDCIMChoices.ps1 - Functions\Circuits\Get-NetboxCircuitsChoices.ps1 Functions\Circuits\Circuits\Get-NetboxCircuit.ps1 deploy.ps1 Functions\Setup\Support\Get-NetboxAPIDefinition.ps1 diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 244e33d..787786b 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'NetboxPS.psm1' # Version number of this module. -ModuleVersion = '1.2.1' +ModuleVersion = '1.2.2' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index adad955..1ba04dd 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -611,52 +611,6 @@ public enum $EnumName #endregion -#region File GetChoiceValidValues.ps1 - -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: GetChoiceValidValues.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - -function GetChoiceValidValues { - [CmdletBinding()] - [OutputType([System.Collections.ArrayList])] - param - ( - [Parameter(Mandatory = $true)] - [string]$MajorObject, - - [Parameter(Mandatory = $true)] - [object]$Choice - ) - - $ValidValues = New-Object System.Collections.ArrayList - - if (-not $script:NetboxConfig.Choices.$MajorObject.$Choice) { - throw "Missing choices for $Choice" - } - - [void]$ValidValues.AddRange($script:NetboxConfig.Choices.$MajorObject.$Choice.value) - [void]$ValidValues.AddRange($script:NetboxConfig.Choices.$MajorObject.$Choice.label) - - if ($ValidValues.Count -eq 0) { - throw "Missing valid values for $MajorObject.$Choice" - } - - return [System.Collections.ArrayList]$ValidValues -} - -#endregion - #region File Get-ModelDefinition.ps1 <# @@ -1007,49 +961,6 @@ function Get-NetboxCircuitProvider { #endregion -#region File Get-NetboxCircuitsChoices.ps1 - -<# - .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 -} - -#endregion - #region File Get-NetboxCircuitTermination.ps1 <# @@ -1227,36 +1138,6 @@ function Get-NetboxCredential { #endregion -#region File Get-NetboxDCIMChoices.ps1 - -<# - .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 -} - -#endregion - #region File Get-NetboxDCIMDevice.ps1 <# @@ -1790,22 +1671,6 @@ function Get-NetboxDCIMSite { } -#endregion - -#region File Get-NetboxExtrasChoices.ps1 - -function Get-NetboxExtrasChoices { - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")] - param () - - $uriSegments = [System.Collections.ArrayList]::new(@('extras', '_choices')) - - $uri = BuildNewURI -Segments $uriSegments - - InvokeNetboxRequest -URI $uri -} - #endregion #region File Get-NetboxHostname.ps1 @@ -2075,36 +1940,6 @@ function Get-NetboxIPAMAvailableIP { #endregion -#region File Get-NetboxIPAMChoices.ps1 - -<# - .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 -} - -#endregion - #region File Get-NetboxIPAMPrefix.ps1 <# @@ -2532,36 +2367,6 @@ function Get-NetboxIPAMVLAN { -#endregion - -#region File Get-NetboxTenancyChoices.ps1 - -<# - .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 -} - #endregion #region File Get-NetboxTenant.ps1 @@ -2690,36 +2495,6 @@ function Get-NetboxTenant { #endregion -#region File Get-NetboxVirtualizationChoices.ps1 - -<# - .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 -} - -#endregion - #region File Get-NetboxVirtualizationCluster.ps1 <# @@ -4791,389 +4566,6 @@ function ThrowNetboxRESTError { #endregion -#region File ValidateChoice.ps1 - -<# - .NOTES - =========================================================================== - Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 - Created on: 3/26/2020 14:23 - Created by: Claussen - Organization: NEOnet - Filename: ValidateChoice.ps1 - =========================================================================== - .DESCRIPTION - A description of the file. -#> - - -function ValidateChoice { - [CmdletBinding()] - [OutputType([uint16], [string], [bool])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateSet('Circuits', 'DCIM', 'Extras', 'IPAM', 'Virtualization', IgnoreCase = $true)] - [string]$MajorObject, - - [Parameter(Mandatory = $true)] - [string]$ChoiceName, - - [Parameter(Mandatory = $true)] - [object]$ProvidedValue - ) - - $ValidValues = GetChoiceValidValues -MajorObject $MajorObject -Choice $ChoiceName - - Write-Verbose "Validating $ChoiceName" - Write-Verbose "Checking '$ProvidedValue' against [$($ValidValues -join ', ')]" - - # Coercing everything to strings for matching... - # some values are integers, some are strings, some are booleans - # Join the valid values with a pipe as a delimeter, because some values have spaces - if (([string]($ValidValues -join '|') -split '\|') -inotcontains [string]$ProvidedValue) { - throw "Invalid value '$ProvidedValue' for '$ChoiceName'. Must be one of: $($ValidValues -join ', ')" - } - - switch -wildcard ("$MajorObject/$ChoiceName") { - "Circuits" { - # This has things that are not integers - } - - "DCIM/*connection_status" { - # This has true/false values instead of integers - try { - $val = [bool]::Parse($ProvidedValue) - } catch { - # It must not be a true/false value - $val = $script:NetboxConfig.Choices.$MajorObject.$ChoiceName.Where({ - $_.Label -eq $ProvidedValue - }).Value - } - - return $val - } - - default { - # Convert the ProvidedValue to the integer value - try { - $intVal = [uint16]"$ProvidedValue" - } catch { - # It must not be a number, get the value from the label - $intVal = [uint16]$script:NetboxConfig.Choices.$MajorObject.$ChoiceName.Where({ - $_.Label -eq $ProvidedValue - }).Value - } - - return $intVal - } - } -} - -#endregion - -#region File ValidateDCIMChoice.ps1 - -function ValidateDCIMChoice { -<# - .SYNOPSIS - Internal function to validate provided values for static choices - - .DESCRIPTION - When users connect to the API, choices for each major object are cached to the config variable. - These values are then utilized to validate if the provided value from a user is valid. - - .PARAMETER ProvidedValue - The value to validate against static choices - - .PARAMETER PowerConnectionStatus - Validate against power connection status values - - .PARAMETER InterfaceTemplateFormFactor - Validate against interface template form factor values - - .PARAMETER InterfaceConnectionStatus - Validate against interface connection status values - - .PARAMETER InterfaceFormFactor - Validate against interface form factor values - - .PARAMETER ConsolePortConnectionStatus - Validate against console port connection status values - - .PARAMETER DeviceStatus - Validate against device status values - - .PARAMETER DeviceFace - Validate against device face values - - .PARAMETER RackType - Validate against rack type values - - .PARAMETER RackWidth - Validate against rack width values. - - .EXAMPLE - PS C:\> ValidateDCIMChoice -ProvidedValue 'rear' -DeviceFace - - .EXAMPLE - PS C:\> ValidateDCIMChoice -ProvidedValue 'middle' -DeviceFace - >> Invalid value middle for device:face. Must be one of: 0, 1, Front, Rear - - .OUTPUTS - This function returns the integer value if valid. Otherwise, it will throw an error. - - .NOTES - Additional information about the function. - - .FUNCTIONALITY - This cmdlet is intended to be used internally and not exposed to the user -#> - - [CmdletBinding()] - [OutputType([uint16])] - param - ( - [Parameter(Mandatory = $true)] - [object]$ProvidedValue, - - [Parameter(ParameterSetName = 'power-port:connection_status', - Mandatory = $true)] - [switch]$PowerConnectionStatus, - - [Parameter(ParameterSetName = 'interface-template:form_factor', - Mandatory = $true)] - [switch]$InterfaceTemplateFormFactor, - - [Parameter(ParameterSetName = 'interface-connection:connection_status', - Mandatory = $true)] - [switch]$InterfaceConnectionStatus, - - [Parameter(ParameterSetName = 'interface:form_factor', - Mandatory = $true)] - [switch]$InterfaceFormFactor, - - [Parameter(ParameterSetName = 'console-port:connection_status', - Mandatory = $true)] - [switch]$ConsolePortConnectionStatus, - - [Parameter(ParameterSetName = 'device:status', - Mandatory = $true)] - [switch]$DeviceStatus, - - [Parameter(ParameterSetName = 'device:face', - Mandatory = $true)] - [switch]$DeviceFace, - - [Parameter(ParameterSetName = 'rack:type', - Mandatory = $true)] - [switch]$RackType, - - [Parameter(ParameterSetName = 'rack:width', - Mandatory = $true)] - [switch]$RackWidth - ) - - ValidateChoice -MajorObject 'DCIM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue -} - -#endregion - -#region File ValidateIPAMChoice.ps1 - -<# - .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 - Internal function to verify provided values for static choices - - .DESCRIPTION - When users connect to the API, choices for each major object are cached to the config variable. - These values are then utilized to verify if the provided value from a user is valid. - - .PARAMETER ProvidedValue - The value to validate against static choices - - .PARAMETER AggregateFamily - Verify against aggregate family values - - .PARAMETER PrefixFamily - Verify against prefix family values - - .PARAMETER PrefixStatus - Verify against prefix status values - - .PARAMETER IPAddressFamily - Verify against ip-address family values - - .PARAMETER IPAddressStatus - Verify against ip-address status values - - .PARAMETER IPAddressRole - Verify against ip-address role values - - .PARAMETER VLANStatus - Verify against VLAN status values - - .PARAMETER ServiceProtocol - Verify against service protocol values - - .EXAMPLE - PS C:\> ValidateIPAMChoice -ProvidedValue 'loopback' -IPAddressRole - - .EXAMPLE - PS C:\> ValidateIPAMChoice -ProvidedValue 'Loopback' -IPAddressFamily - >> Invalid value Loopback for ip-address:family. Must be one of: 4, 6, IPv4, IPv6 - - .OUTPUTS - This function returns the integer value if valid. Otherwise, it will throw an error. - - .NOTES - Additional information about the function. - - .FUNCTIONALITY - This cmdlet is intended to be used internally and not exposed to the user -#> - - [CmdletBinding(DefaultParameterSetName = 'service:protocol')] - [OutputType([uint16])] - param - ( - [Parameter(Mandatory = $true)] - [object]$ProvidedValue, - - [Parameter(ParameterSetName = 'aggregate:family', - Mandatory = $true)] - [switch]$AggregateFamily, - - [Parameter(ParameterSetName = 'prefix:family', - Mandatory = $true)] - [switch]$PrefixFamily, - - [Parameter(ParameterSetName = 'prefix:status', - Mandatory = $true)] - [switch]$PrefixStatus, - - [Parameter(ParameterSetName = 'ip-address:family', - Mandatory = $true)] - [switch]$IPAddressFamily, - - [Parameter(ParameterSetName = 'ip-address:status', - Mandatory = $true)] - [switch]$IPAddressStatus, - - [Parameter(ParameterSetName = 'ip-address:role', - Mandatory = $true)] - [switch]$IPAddressRole, - - [Parameter(ParameterSetName = 'vlan:status', - Mandatory = $true)] - [switch]$VLANStatus, - - [Parameter(ParameterSetName = 'service:protocol', - Mandatory = $true)] - [switch]$ServiceProtocol - ) - - ValidateChoice -MajorObject 'IPAM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue -} - -#endregion - -#region File ValidateVirtualizationChoice.ps1 - -<# - .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 - Internal function to verify provided values for static choices - - .DESCRIPTION - When users connect to the API, choices for each major object are cached to the config variable. - These values are then utilized to verify if the provided value from a user is valid. - - .PARAMETER ProvidedValue - The value to validate against static choices - - .PARAMETER AggregateFamily - Verify against aggregate family values - - .PARAMETER PrefixFamily - Verify against prefix family values - - .PARAMETER PrefixStatus - Verify against prefix status values - - .PARAMETER IPAddressFamily - Verify against ip-address family values - - .PARAMETER IPAddressStatus - Verify against ip-address status values - - .PARAMETER IPAddressRole - Verify against ip-address role values - - .PARAMETER VLANStatus - Verify against VLAN status values - - .PARAMETER ServiceProtocol - Verify against service protocol values - - .EXAMPLE - PS C:\> VerifyIPAMChoices -ProvidedValue 'loopback' -IPAddressRole - - .EXAMPLE - PS C:\> VerifyIPAMChoices -ProvidedValue 'Loopback' -IPAddressFamily - >> Invalid value Loopback for ip-address:family. Must be one of: 4, 6, IPv4, IPv6 - - .FUNCTIONALITY - This cmdlet is intended to be used internally and not exposed to the user - - .OUTPUT - This function returns nothing if the value is valid. Otherwise, it will throw an error. -#> - - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [object]$ProvidedValue, - - [Parameter(ParameterSetName = 'virtual-machine:status', - Mandatory = $true)] - [switch]$VirtualMachineStatus - ) - - ValidateChoice -MajorObject 'Virtualization' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue -} - -#endregion - #region File VerifyAPIConnectivity.ps1 function VerifyAPIConnectivity {