Remove parameter validation as workaround for CHOICES API endpoint until further testing

This commit is contained in:
Ben Claussen 2020-05-04 12:36:46 -04:00
parent c9077abd51
commit 657a8405bc
25 changed files with 294 additions and 190 deletions

View file

@ -64,21 +64,21 @@ function New-NetboxDCIMDevice {
) )
#endregion Parameters #endregion Parameters
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
} # }
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))

View file

@ -64,13 +64,13 @@ function Set-NetboxDCIMDevice {
) )
begin { begin {
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
} # }
} }
process { process {

View file

@ -47,9 +47,9 @@ function Add-NetboxDCIMInterface {
[uint16[]]$Tagged_VLANs [uint16[]]$Tagged_VLANs
) )
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
} # }
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) { $PSBoundParameters.Mode = switch ($Mode) {

View file

@ -50,9 +50,9 @@ function Set-NetboxDCIMInterface {
) )
begin { begin {
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
} # }
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) { if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) { $PSBoundParameters.Mode = switch ($Mode) {

View file

@ -60,9 +60,9 @@ function Set-NetboxDCIMInterfaceConnection {
) )
begin { begin {
if ($null -ne $Connection_Status) { # if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus # $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
} # }
if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) { if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) {
throw "Cannot set multiple connections to the same interface" throw "Cannot set multiple connections to the same interface"

View file

@ -1,65 +1,92 @@
function Get-NetboxIPAMAddress { function Get-NetboxIPAMAddress {
[CmdletBinding()] [CmdletBinding(DefaultParameterSetName = 'Query')]
param param
( (
[Parameter(ParameterSetName = 'Query')]
[string]$Address, [string]$Address,
[Parameter(ParameterSetName = 'ByID')]
[uint16[]]$Id, [uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'Query')]
[object]$Family, [object]$Family,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Parent, [uint16]$Parent,
[Parameter(ParameterSetName = 'Query')]
[byte]$Mask_Length, [byte]$Mask_Length,
[Parameter(ParameterSetName = 'Query')]
[string]$VRF, [string]$VRF,
[Parameter(ParameterSetName = 'Query')]
[uint16]$VRF_Id, [uint16]$VRF_Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant, [string]$Tenant,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Tenant_Id, [uint16]$Tenant_Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Device, [string]$Device,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Device_ID, [uint16]$Device_ID,
[Parameter(ParameterSetName = 'Query')]
[string]$Virtual_Machine, [string]$Virtual_Machine,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Virtual_Machine_Id, [uint16]$Virtual_Machine_Id,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Interface_Id, [uint16]$Interface_Id,
[Parameter(ParameterSetName = 'Query')]
[object]$Status, [object]$Status,
[Parameter(ParameterSetName = 'Query')]
[object]$Role, [object]$Role,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit, [uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset, [uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
if ($null -ne $Family) { switch ($PSCmdlet.ParameterSetName) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -IPAddressFamily 'ById' {
foreach ($IP_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IP_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
break
}
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
} }
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
}
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
} }

View file

@ -47,6 +47,9 @@ function New-NetboxIPAMAddress {
.PARAMETER Description .PARAMETER Description
Description of IP address Description of IP address
.PARAMETER Force
A description of the Force parameter.
.PARAMETER Raw .PARAMETER Raw
Return raw results from API service Return raw results from API service
@ -57,7 +60,8 @@ function New-NetboxIPAMAddress {
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -80,20 +84,35 @@ function New-NetboxIPAMAddress {
[string]$Description, [string]$Description,
[switch]$Force,
[switch]$Raw [switch]$Raw
) )
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST'
if ($null -ne $Role) { # # Value validation
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
} # $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
$segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses')) # foreach ($Property in $EnumProperties.Keys) {
# if ($PSBoundParameters.ContainsKey($Property)) {
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters # 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
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
} InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}

View file

@ -43,9 +43,6 @@ function Remove-NetboxIPAMAddress {
[switch]$Force [switch]$Force
) )
begin {
}
process { process {
foreach ($IPId in $Id) { foreach ($IPId in $Id) {
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop $CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
@ -59,7 +56,4 @@ function Remove-NetboxIPAMAddress {
} }
} }
} }
end {
}
} }

View file

@ -43,20 +43,31 @@ function Set-NetboxIPAMAddress {
) )
begin { begin {
if ($Status) { # Write-Verbose "Validating enum properties"
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus # $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0))
} $Method = 'PATCH'
#
if ($Role) { # # Value validation
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # $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
# } else {
# Write-Verbose "User did not provide a value for [$Property]"
# }
# }
#
# Write-Verbose "Finished enum validation"
} }
process { process {
foreach ($IPId in $Id) { foreach ($IPId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId)) $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
Write-Verbose "Obtaining IPs from ID $IPId" Write-Verbose "Obtaining IP from ID $IPId"
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop $CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentIP.Address, 'Set')) { if ($Force -or $PSCmdlet.ShouldProcess($CurrentIP.Address, 'Set')) {
@ -64,11 +75,8 @@ function Set-NetboxIPAMAddress {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
} }
} }
} }
end {
}
} }

View file

@ -13,37 +13,67 @@
function Get-NetboxIPAMAggregate { function Get-NetboxIPAMAggregate {
[CmdletBinding()] [CmdletBinding(DefaultParameterSetName = 'Query')]
param param
( (
[uint16]$Limit, [Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[object]$Family,
[datetime]$Date_Added,
[uint16[]]$Id,
[string]$Query, [string]$Query,
[Parameter(ParameterSetName = 'ByID')]
[uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Prefix,
[Parameter(ParameterSetName = 'Query')]
[object]$Family,
[Parameter(ParameterSetName = 'Query')]
[uint16]$RIR_Id, [uint16]$RIR_Id,
[Parameter(ParameterSetName = 'Query')]
[string]$RIR, [string]$RIR,
[Parameter(ParameterSetName = 'Query')]
[datetime]$Date_Added,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
if ($null -ne $Family) { # if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily # $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily
# }
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($IP_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates', $IP_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
break
}
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
} }
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
} }

View file

@ -93,7 +93,7 @@ function Get-NetboxIPAMPrefix {
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding(DefaultParameterSetName = 'Query')]
param param
( (
[string]$Prefix, [string]$Prefix,

View file

@ -40,7 +40,7 @@ function New-NetboxIPAMPrefix {
[switch]$Raw [switch]$Raw
) )
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
<# <#
# As of 2018/10/18, this does not appear to be a validated IPAM choice # As of 2018/10/18, this does not appear to be a validated IPAM choice

View file

@ -41,11 +41,11 @@ function Get-NetboxIPAMRole {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[uint16[]]$Id, [string]$Name,
[string]$Query, [string]$Query,
[string]$Name, [uint16[]]$Id,
[string]$Slug, [string]$Slug,

View file

@ -16,10 +16,6 @@ function Get-NetboxIPAMVLAN {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[uint16]$Limit,
[uint16]$Offset,
[uint16]$VID, [uint16]$VID,
[uint16[]]$Id, [uint16[]]$Id,
@ -52,6 +48,10 @@ function Get-NetboxIPAMVLAN {
[uint16]$Role_Id, [uint16]$Role_Id,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw [switch]$Raw
) )

View file

@ -63,11 +63,11 @@
[switch]$Raw [switch]$Raw
) )
$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
} # }
$segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans')) $segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))

View file

@ -48,8 +48,6 @@
try { try {
Write-Verbose "Verifying API connectivity..." Write-Verbose "Verifying API connectivity..."
$null = VerifyAPIConnectivity $null = VerifyAPIConnectivity
$script:NetboxConfig.Connected = $true
Write-Verbose "Successfully connected!"
} catch { } catch {
Write-Verbose "Failed to connect. Generating error" Write-Verbose "Failed to connect. Generating error"
Write-Verbose $_.Exception.Message Write-Verbose $_.Exception.Message
@ -60,14 +58,25 @@
} }
} }
Write-Verbose "Caching static choices" Write-Verbose "Caching API definition"
$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition
$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet
$script:NetboxConfig.Choices.Extras = Get-NetboxExtrasChoices if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) {
$script:NetboxConfig.Choices.IPAM = Get-NetboxIPAMChoices $Script:NetboxConfig.Connected = $false
#$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)"
#$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices }
$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices
$script:NetboxConfig.Connected = $true
Write-Verbose "Successfully connected!"
#Write-Verbose "Caching static choices"
#$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices
#$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet
#$script:NetboxConfig.Choices.Extras = Get-NetboxExtrasChoices
#$script:NetboxConfig.Choices.IPAM = Get-NetboxIPAMChoices
##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet
##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices
#$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices
Write-Verbose "Connection process completed" Write-Verbose "Connection process completed"
} }

View file

@ -0,0 +1,29 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174
Created on: 4/28/2020 11:57
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxAPIDefinition.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxAPIDefinition {
[CmdletBinding()]
param ()
#$URI = "https://netbox.neonet.org/api/docs/?format=openapi"
$Segments = [System.Collections.ArrayList]::new(@('docs'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi'}
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Timeout 10
}

View file

@ -12,6 +12,7 @@
'Connected' = $false 'Connected' = $false
'Choices' = @{ 'Choices' = @{
} }
'APIDefinition' = $null
} }
} }

View file

@ -2,9 +2,9 @@
[CmdletBinding()] [CmdletBinding()]
param () param ()
$uriSegments = [System.Collections.ArrayList]::new(@('extras', '_choices')) $uriSegments = [System.Collections.ArrayList]::new(@('extras'))
$uri = BuildNewURI -Segments $uriSegments -SkipConnectedCheck $uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json'} -SkipConnectedCheck
InvokeNetboxRequest -URI $uri InvokeNetboxRequest -URI $uri
} }

View file

@ -16,12 +16,10 @@ function Get-NetboxTenant {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[uint16]$Limit,
[uint16]$Offset,
[string]$Name, [string]$Name,
[string]$Slug,
[uint16[]]$Id, [uint16[]]$Id,
[string]$Query, [string]$Query,
@ -32,6 +30,10 @@ function Get-NetboxTenant {
[hashtable]$CustomFields, [hashtable]$CustomFields,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw [switch]$Raw
) )

View file

@ -46,7 +46,14 @@ function New-NetboxVirtualMachine {
[string]$Comments [string]$Comments
) )
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
#
# # Validate the status against the APIDefinition
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
# }
#
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
@ -55,4 +62,8 @@ function New-NetboxVirtualMachine {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
} }

View file

@ -50,19 +50,19 @@ function Set-NetboxVirtualMachine {
[switch]$Force [switch]$Force
) )
if ($null -ne $Status) { # if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
} # }
#
$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"
$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop #$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop
Write-Verbose "Finished obtaining VM" Write-Verbose "Finished obtaining VM"
if ($Force -or $pscmdlet.ShouldProcess($CurrentVM.Name, "Set")) { if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force' $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments

View file

@ -60,15 +60,13 @@ function Get-NetboxVirtualMachineInterface {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipeline = $true)] [Parameter(ValueFromPipeline = $true)]
[uint16]$Id, [uint16]$Id,
[string]$Name, [string]$Name,
[string]$Query,
[boolean]$Enabled, [boolean]$Enabled,
[uint16]$MTU, [uint16]$MTU,
@ -79,6 +77,10 @@ function Get-NetboxVirtualMachineInterface {
[string]$MAC_Address, [string]$MAC_Address,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw [switch]$Raw
) )

View file

@ -66,16 +66,11 @@ function Get-NetboxVirtualizationCluster {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[uint16]$Limit, [string]$Name,
[uint16]$Offset,
[Alias('q')] [Alias('q')]
[string]$Query, [string]$Query,
[string]$Name,
[Alias('id__in')]
[uint16[]]$Id, [uint16[]]$Id,
[string]$Group, [string]$Group,
@ -90,36 +85,18 @@ function Get-NetboxVirtualizationCluster {
[uint16]$Site_Id, [uint16]$Site_Id,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters'))
$URIParameters = @{ $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
}
foreach ($CmdletParameterName in $PSBoundParameters.Keys) { $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
if ($CmdletParameterName -eq 'Id') {
# Check if there is one or more values for Id and build a URI or query as appropriate
if (@($PSBoundParameters[$CmdletParameterName]).Count -gt 1) {
$URIParameters['id__in'] = $Id -join ','
} else {
[void]$uriSegments.Add($PSBoundParameters[$CmdletParameterName])
}
} elseif ($CmdletParameterName -eq 'Query') {
$URIParameters['q'] = $PSBoundParameters[$CmdletParameterName]
} else {
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }

View file

@ -16,33 +16,28 @@ function Get-NetboxVirtualizationClusterGroup {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[uint16]$Limit,
[uint16]$Offset,
[string]$Name, [string]$Name,
[string]$Slug, [string]$Slug,
[string]$Description,
[string]$Query,
[uint32[]]$Id,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw [switch]$Raw
) )
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups'))
$URIParameters = @{ $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
}
foreach ($CmdletParameterName in $PSBoundParameters.Keys) { $uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }