Skip to content

Commit

Permalink
v2.3.2 (#23)
Browse files Browse the repository at this point in the history
v2.3.2 - March 2019

- Patch #19 (Add remove methods)
- Merge in #21 (Make sure HTTPS link handling doesn't break when handling paging)
- Merge in #20 (Add support for ports in the netbox API url)
  • Loading branch information
BatmanAMA authored Mar 12, 2019
1 parent 8a48dd7 commit 518a266
Show file tree
Hide file tree
Showing 13 changed files with 1,580 additions and 193 deletions.
10 changes: 8 additions & 2 deletions module/Private/CreateCommands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Function createcommands {
Name = 'New'
OutFile = '..\public\New-nbx.ps1'
InFile = 'New.txt'
},
[PSCustomObject]@{
Name = 'Remove'
OutFile = '..\public\Remove-nbx.ps1'
InFile = 'Remove.txt'
}
)
)
Expand All @@ -32,8 +37,8 @@ Function createcommands {
foreach ($command in $commands) {
$ScriptPath = Join-Path -Path $cwd -ChildPath $command.Outfile -Resolve
("#" * 80 + "`n" +
"## AUTO GENERATED FILE" + "#" * 57 + "`n" +
"## Regenerate using CreateCommands.ps1 from private functions" + "#" * 17 + "`n" +
"## AUTO GENERATED FILE".PadRight(79,' ') + "#`n" +
"## Regenerate using CreateCommands.ps1 from private functions".PadRight(79,' ') + "#`n" +
"#" * 80 + "`n") | Out-File -FilePath $ScriptPath -Encoding default -Force
foreach ($key in $ResourceMap.Keys) {
$defPath = (Join-Path -Path $cwd -ChildPath $command.InFile)
Expand All @@ -46,3 +51,4 @@ Function createcommands {
end {
}
}
createcommands
22 changes: 22 additions & 0 deletions module/Private/Remove.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
.SYNOPSIS
Deletes a |short| in Netbox
.DESCRIPTION
Deletes a netbox |short| by ID or via the pipeline.
.EXAMPLE
# Remove the |short| by id
Remove-nb|short| -id 1
.EXAMPLE
#Remove |short| returned from a get-nb|short|
Get-Nb|short| -search mything.contoso.com -Resource 'virtualization/virtual-machines' |
Remove-nb|short| -Resource 'virtualization/virtual-machines'
#>
Function Remove-nb|short| {
Param (
# ID of the |short| to delete
[Parameter()]
[Int]
$Id
)
Remove-nbObject -Resource '|long|' -id $id
}
2 changes: 1 addition & 1 deletion module/Public/Get-nbObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function Get-nbObject {
while (![string]::IsNullOrEmpty($object.next)) {
Write-Verbose $object.next
$url = if ($APIUrl.Scheme -eq 'https' -or $Script:APIUrl.Scheme -eq 'https') {
$object.next -replace 'http','https'
$object.next -replace '^http:', 'https:'
} else {
$object.next
}
Expand Down
4 changes: 2 additions & 2 deletions module/Public/Get-nbx.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
## AUTO GENERATED FILE#########################################################
## Regenerate using CreateCommands.ps1 from private functions#################
## AUTO GENERATED FILE #
## Regenerate using CreateCommands.ps1 from private functions #
################################################################################

<#
Expand Down
1 change: 1 addition & 0 deletions module/Public/Invoke-nbApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function Invoke-nbApi {
Host = $_APIUrl.DnsSafeHost
Path = $_APIUrl.LocalPath.TrimEnd('/') + '/' + $Resource
Query = $QueryString
Port = $_APIUrl.Port
}
} else {
$URI = [UriBuilder]::new($rawUrl)
Expand Down
4 changes: 2 additions & 2 deletions module/Public/New-nbx.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
## AUTO GENERATED FILE#########################################################
## Regenerate using CreateCommands.ps1 from private functions#################
## AUTO GENERATED FILE #
## Regenerate using CreateCommands.ps1 from private functions #
################################################################################

<#
Expand Down
32 changes: 32 additions & 0 deletions module/Public/Remove-nbObject.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<#
.SYNOPSIS
Deletes an object from netbox
.DESCRIPTION
Deletes a netbox object by ID or via the pipeline.
.EXAMPLE
# Remove the object by id
Remove-nbObject -id 1 -Resource 'virtualization/virtual-machines'
.EXAMPLE
#Remove an object from a get-nbobject
Get-NbObject -search mything.contoso.com -Resource 'virtualization/virtual-machines' |
Remove-nbObject -Resource 'virtualization/virtual-machines'
#>
function Remove-nbObject {
[CmdletBinding()]
param (
# Which resource to delete
[Parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
[Int]
$Id,
# Which resource type to delete
[Parameter(Mandatory = $true, Position = 1)]
[String]
[Alias("type")]
$Resource
)


process {
Invoke-nbApi -Resource "$Resource/$id" -HttpVerb Delete
}
}
Loading

0 comments on commit 518a266

Please sign in to comment.