Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tags field for set-netboxipamaddress #59

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Functions/IPAM/Address/Set-NetboxIPAMAddress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function Set-NetboxIPAMAddress {

[uint64]$Tenant,

[uint64][]$Tags,

[uint64]$VRF,

[object]$Role,
Expand Down Expand Up @@ -80,4 +82,4 @@ function Set-NetboxIPAMAddress {
}
}
}
}
}
103 changes: 56 additions & 47 deletions NetboxPS/NetboxPS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -271,80 +271,89 @@ function Add-NetboxVirtualMachineInterface {


function BuildNewURI {
<#
.SYNOPSIS
Create a new URI for Netbox

.DESCRIPTION
Internal function used to build a URIBuilder object.

.PARAMETER Hostname
Hostname of the Netbox API

.PARAMETER Segments
Array of strings for each segment in the URL path

.PARAMETER Parameters
Hashtable of query parameters to include

.PARAMETER HTTPS
Whether to use HTTPS or HTTP

.PARAMETER Port
A description of the Port parameter.

.PARAMETER APIInfo
A description of the APIInfo parameter.

.EXAMPLE
PS C:\> BuildNewURI

.NOTES
Additional information about the function.
#>

<#
.SYNOPSIS
Create a new URI for Netbox
.DESCRIPTION
Internal function used to build a URIBuilder object.
.PARAMETER Hostname
Hostname of the Netbox API
.PARAMETER Segments
Array of strings for each segment in the URL path
.PARAMETER Parameters
Hashtable of query parameters to include
.PARAMETER HTTPS
Whether to use HTTPS or HTTP
.PARAMETER Port
A description of the Port parameter.
.PARAMETER APIInfo
A description of the APIInfo parameter.
.EXAMPLE
PS C:\> BuildNewURI
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
[OutputType([System.UriBuilder])]
param
(
[Parameter(Mandatory = $false)]
[string[]]$Segments,

[Parameter(Mandatory = $false)]
[hashtable]$Parameters,

[switch]$SkipConnectedCheck
)

Write-Verbose "Building URI"

if (-not $SkipConnectedCheck) {
# There is no point in continuing if we have not successfully connected to an API
$null = CheckNetboxIsConnected
}

# Begin a URI builder with HTTP/HTTPS and the provided hostname
$uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort)

# Generate the path by trimming excess slashes and whitespace from the $segments[] and joining together
$uriBuilder.Path = "api/{0}/" -f ($Segments.ForEach({
$_.trim('/').trim()
}) -join '/')

Write-Verbose " URIPath: $($uriBuilder.Path)"

if ($parameters) {
if ($Parameters) {
# Loop through the parameters and use the HttpUtility to create a Query string
[System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)

[System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString($uriBuilder.Query)
foreach ($param in $Parameters.GetEnumerator()) {
Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)"
$URIParams[$param.Key] = $param.Value
if ($param.Key -eq 'q') {
# Append the query string directly
$uriBuilder.Query = $uriBuilder.Query.TrimStart('?') + '&' + $param.Value
}
else {
$URIParams[$param.Key] = $param.Value
}
}

$uriBuilder.Query = $URIParams.ToString()

# Combine the existing query with new parameters
$existingQuery = $uriBuilder.Query.TrimStart('?')
$newQuery = $URIParams.ToString()
$uriBuilder.Query = ($existingQuery + '&' + $newQuery).Trim('&')
}

Write-Verbose " Completed building URIBuilder"
# Return the entire UriBuilder object
$uriBuilder
Expand Down