mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-13 18:02:29 +00:00
Update New-NetboxContactAssignment Content_Type parameter values and validation
This commit is contained in:
parent
40c7aac059
commit
b441e02e2b
1 changed files with 8 additions and 57 deletions
|
|
@ -1,22 +1,4 @@
|
||||||
#enum NetboxContactAssignmentContentType {
|
|
||||||
# Circuit = 10
|
|
||||||
# CircuitProvider = 7
|
|
||||||
# CircuitProviderAccount = 132
|
|
||||||
# Device = 19
|
|
||||||
# Location = 25
|
|
||||||
# Manufacturer = 29
|
|
||||||
# PowerPanel = 77
|
|
||||||
# Rack = 20
|
|
||||||
# Region = 30
|
|
||||||
# Site = 18
|
|
||||||
# SiteGroup = 92
|
|
||||||
# Tenant = 58
|
|
||||||
# VirtualizationCluster = 63
|
|
||||||
# VirtualizationClusterGroup = 64
|
|
||||||
# VirtualMachine = 61
|
|
||||||
#}
|
|
||||||
|
|
||||||
|
|
||||||
function New-NetboxContactAssignment {
|
function New-NetboxContactAssignment {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
|
|
@ -44,10 +26,10 @@ function New-NetboxContactAssignment {
|
||||||
Return the unparsed data from the HTTP request
|
Return the unparsed data from the HTTP request
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> New-NetboxContactAssignment -Content_Type Location -Object_id 10 -Contact 15 -Role 10 -Priority Primary
|
PS C:\> New-NetboxContactAssignment -Content_Type 'dcim.location' -Object_id 10 -Contact 15 -Role 10 -Priority 'Primary'
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
Additional information about the function.
|
Valid content types: https://docs.netbox.dev/en/stable/features/contacts/#contacts_1
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(ConfirmImpact = 'Low',
|
[CmdletBinding(ConfirmImpact = 'Low',
|
||||||
|
|
@ -57,8 +39,8 @@ function New-NetboxContactAssignment {
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $true,
|
[Parameter(Mandatory = $true,
|
||||||
ValueFromPipelineByPropertyName = $true)]
|
ValueFromPipelineByPropertyName = $true)]
|
||||||
[object]$Content_Type,
|
[ValidateSet('circuits.circuit', 'circuits.provider', 'circuits.provideraccount', 'dcim.device', 'dcim.location', 'dcim.manufacturer', 'dcim.powerpanel', 'dcim.rack', 'dcim.region', 'dcim.site', 'dcim.sitegroup', 'tenancy.tenant', 'virtualization.cluster', 'virtualization.clustergroup', 'virtualization.virtualmachine', IgnoreCase = $true)]
|
||||||
#[NetboxContactAssignmentContentType]$Content_Type,
|
[string]$Content_Type,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[uint64]$Object_Id,
|
[uint64]$Object_Id,
|
||||||
|
|
@ -76,48 +58,17 @@ function New-NetboxContactAssignment {
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
# https://docs.netbox.dev/en/stable/features/contacts/
|
$Method = 'POST'
|
||||||
$AllowedContentTypes = @{
|
|
||||||
10 = "circuits.circuit"
|
|
||||||
7 = "circuits.provider"
|
|
||||||
132 = "circuits.provideraccount"
|
|
||||||
19 = "dcim.device"
|
|
||||||
25 = "dcim.location"
|
|
||||||
29 = "dcim.manufacturer"
|
|
||||||
77 = "dcim.powerpanel"
|
|
||||||
20 = "dcim.rack"
|
|
||||||
30 = "dcim.region"
|
|
||||||
18 = "dcim.site"
|
|
||||||
92 = "dcim.sitegroup"
|
|
||||||
58 = "tenancy.tenant"
|
|
||||||
63 = "virtualization.cluster"
|
|
||||||
64 = "virtualization.clustergroup"
|
|
||||||
61 = "virtualization.virtualmachine"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignment'))
|
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments'))
|
||||||
$Method = 'POST'
|
|
||||||
|
|
||||||
if ($Content_Type -is [string]) {
|
|
||||||
# Need to convert this to an integer
|
|
||||||
$Content_Type = ($AllowedContentTypes.GetEnumerator() | Where-Object {
|
|
||||||
$_.Value -eq $Content_Type
|
|
||||||
}).Key
|
|
||||||
} elseif ($Content_Type -is [int]) {
|
|
||||||
if ($Content_Type -notin $($AllowedContentTypes).Keys) {
|
|
||||||
throw "Invalid content type defined"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw "Invalid content type defined"
|
|
||||||
}
|
|
||||||
|
|
||||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||||
|
|
||||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||||
|
|
||||||
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact assignment')) {
|
if ($PSCmdlet.ShouldProcess($Content_Type, 'Create new contact assignment')) {
|
||||||
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
|
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue