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
This commit is contained in:
Alexis La Goutte 2021-07-23 22:03:07 +02:00 committed by GitHub
parent 11ae767a6c
commit ddf1d22e18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,14 +1,14 @@
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172 Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:51 Created on: 3/19/2020 11:51
Created by: Claussen Created by: Claussen
Organization: NEOnet Organization: NEOnet
Filename: New-NetboxIPAMAddress.ps1 Filename: New-NetboxIPAMAddress.ps1
=========================================================================== ===========================================================================
.DESCRIPTION .DESCRIPTION
A description of the file. A description of the 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
} }
} }