Enhance (DCIM) Site (#25)

* Site(DCIM): Fix Get without parameter

* Site(DCIM): Fix indent (use 4 spaces for header)

* Site(DCIM): Add New-NetboxDCIMSite for Add DCIM Site

* Site(DCIM): Add Remove-NetboxDCIMSite for Remove DCIM Site
This commit is contained in:
Alexis La Goutte 2021-09-10 17:34:37 +02:00 committed by GitHub
parent e162c05900
commit e8a5fdf15d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 161 additions and 12 deletions

View file

@ -1,20 +1,20 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-10-02 15:52
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMSite.ps1
===========================================================================
.DESCRIPTION
A description of the file.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-10-02 15:52
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMSite.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMSite {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'Query')]
[OutputType([pscustomobject])]
param
(
@ -107,4 +107,3 @@ function Get-NetboxDCIMSite {
}
}
}

View file

@ -0,0 +1,86 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-10-02 15:52
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxDCIMSite.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function New-NetboxDCIMSite {
<#
.SYNOPSIS
Create a new Site to Netbox
.DESCRIPTION
Create a new Site to Netbox
.EXAMPLE
New-NetboxDCIMSite -name MySite
Add new Site MySite on Netbox
#>
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$Slug,
[string]$Facility,
[uint32]$ASN,
[decimal]$Latitude,
[decimal]$Longitude,
[string]$Contact_Name,
[string]$Contact_Phone,
[string]$Contact_Email,
[int]$Tenant_Group,
[int]$Tenant,
[string]$Status,
[uint32]$Region,
[string]$Description,
[string]$Comments,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites'))
$Method = 'POST'
if (-not $PSBoundParameters.ContainsKey('slug')) {
$PSBoundParameters.Add('slug', $name)
}
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($name, 'Create new Site')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}

View file

@ -0,0 +1,64 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-10-02 15:52
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxDCIMSite.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Remove-NetboxDCIMSite {
<#
.SYNOPSIS
Remove a Site
.DESCRIPTION
Remove a DCIM Site from Netbox
.EXAMPLE
Remove-NetboxDCIMSite -Id 1
Remove DCM Site with id 1
.EXAMPLE
Get-NetboxDCIMSite -name My Site | Remove-NetboxDCIMSite -confirm:$false
Remove DCM Site with name My Site without confirmation
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint]$Id
)
begin {
}
process {
$CurrentSite = Get-NetboxDCIMSite -Id $Id -ErrorAction Stop
if ($pscmdlet.ShouldProcess("$($CurrentSite.Name)/$($CurrentSite.Id)", "Remove Site")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $CurrentSite.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
end {
}
}