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

Add netbox dcim platform #67

Open
wants to merge 6 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
34 changes: 34 additions & 0 deletions Functions/DCIM/Platform/Add-NetboxDCIMPlatform.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function Add-NetboxDCIMPlatform {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,

[ValidateLength(1, 100)]
[ValidatePattern('^[-a-zA-Z0-9_]+$')]
[string]$Slug,

[uint64]$Manufacturer,

[uint64]$Config_Template,

[string]$Description,

[uint16[]]$Tags

)

$Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms'))

if (-not $PSBoundParameters.ContainsKey('slug')) {
$PSBoundParameters.Add('slug', $($name | Get-NetboxSlug))
}

$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters

$URI = BuildNewURI -Segments $URIComponents.Segments

InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
35 changes: 35 additions & 0 deletions Functions/DCIM/Platform/Remove-NetboxDCIMPlatform.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function Remove-NetboxDCIMPlatform {

[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint64[]]$Id,

[switch]$Force
)

begin {

}

process {
foreach ($PlatformID in $Id) {
$CurrentPlatform = Get-NetboxDCIMPlatform -Id $PlatformID -ErrorAction Stop

if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPlatform.Name) | ID: $($CurrentPlatform.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $CurrentPlatform.Id))

$URI = BuildNewURI -Segments $Segments

InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}

end {

}
}
51 changes: 51 additions & 0 deletions Functions/DCIM/Platform/Set-NetboxDCIMPlatform.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function Set-NetboxDCIMPlatform {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint64[]]$Id,

[string]$Name,

[ValidateLength(1, 100)]
[ValidatePattern('^[-a-zA-Z0-9_]+$')]
[string]$Slug,

[uint64]$Manufacturer,

[uint64]$Config_Template,

[string]$Description,

[uint64[]]$Tags,

[switch]$Force
)

begin {

}

process {
foreach ($FrontPortID in $Id) {
$CurrentPlatform = Get-NetboxDCIMPlatform -Id $FrontPortID -ErrorAction Stop

$Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $CurrentPlatform.Id))

$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'

$URI = BuildNewURI -Segments $Segments

if ($Force -or $pscmdlet.ShouldProcess("Platform ID $($CurrentPlatform.Id)", "Set")) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}

end {

}
}
16 changes: 16 additions & 0 deletions Functions/Helpers/Get-NetboxSlug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function Get-NetboxSlug {
param (
[Parameter(ValueFromPipeline)]
[string]$slug,

[uint16]$chars = 100
)

process {
return $slug -replace '[^\-.\w\s]', '' `
-replace '[^a-zA-Z0-9-_ ]', '' `
-replace '^[\s.]+|[\s.]+$', '' `
-replace '[-.\s]+', '-' `
| ForEach-Object { $_.ToLower().Substring(0, [Math]::Min($_.Length, $chars)) }
}
}
8 changes: 4 additions & 4 deletions Functions/Setup/Connect-NetboxAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@

Write-Verbose "Checking Netbox version compatibility"
$script:NetboxConfig.NetboxVersion = Get-NetboxVersion
if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) {
if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 4.0.1) {
$Script:NetboxConfig.Connected = $false
throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')"
throw "Netbox version is incompatible with this PS module. Requires >=4.0, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')"
} else {
Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!"
}

$script:NetboxConfig.Connected = $true
Write-Verbose "Successfully connected!"

$script:NetboxConfig.ContentTypes = Get-NetboxContentType -Limit 500
$script:NetboxConfig.ObjectTypes = Get-NetboxObjectType -Limit 500

Write-Verbose "Connection process completed"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function Get-NetboxContentType {
function Get-NetboxObjectType {
<#
.SYNOPSIS
Get a content type definition from Netbox
Get a object type definition from Netbox

.DESCRIPTION
A detailed description of the Get-NetboxContentType function.
A detailed description of the Get-NetboxObjectType function.

.PARAMETER Model
A description of the Model parameter.
Expand All @@ -28,7 +28,7 @@
Return the unparsed data from the HTTP request

.EXAMPLE
PS C:\> Get-NetboxContentType
PS C:\> Get-NetboxObjectType

.NOTES
Additional information about the function.
Expand Down Expand Up @@ -61,8 +61,8 @@

switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($ContentType_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('extras', 'content-types', $ContentType_ID))
foreach ($ObjectType_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('extras', 'object-types', $ObjectType_ID))

$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'

Expand All @@ -75,7 +75,7 @@
}

default {
$Segments = [System.Collections.ArrayList]::new(@('extras', 'content-types'))
$Segments = [System.Collections.ArrayList]::new(@('extras', 'object-types'))

$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters

Expand Down
2 changes: 1 addition & 1 deletion Functions/Setup/Support/SetupNetboxConfigVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'Choices' = @{
}
'APIDefinition' = $null
'ContentTypes' = $null
'ObjectTypes' = $null
}
}

Expand Down
26 changes: 13 additions & 13 deletions Functions/Tenancy/ContactRoles/Set-NetboxContactRole.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


function Set-NetboxContactRole {
<#
.SYNOPSIS
Expand Down Expand Up @@ -28,7 +28,7 @@ function Set-NetboxContactRole {
.NOTES
Additional information about the function.
#>

[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
Expand All @@ -37,37 +37,37 @@ function Set-NetboxContactRole {
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint64[]]$Id,

[Parameter(ValueFromPipelineByPropertyName = $true)]
[ValidateLength(1, 100)]
[string]$Name,

[ValidateLength(1, 100)]
[ValidatePattern('^[-a-zA-Z0-9_]+$')]
[string]$Slug,

[ValidateLength(0, 200)]
[string]$Description,

[hashtable]$Custom_Fields,

[switch]$Raw
)

begin {
$Method = 'PATCH'
}

process {
foreach ($ContactRoleId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts', $ContactRoleId))

$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'

$URI = BuildNewURI -Segments $URIComponents.Segments

$CurrentContactRole = Get-NetboxContactRole -Id $ContactRoleId -ErrorAction Stop

if ($Force -or $PSCmdlet.ShouldProcess($CurrentContactRole.Name, 'Update contact role')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
Expand Down
Loading