Skip to content

Commit

Permalink
Merge pull request #30 from TehMuffinMoo/dev
Browse files Browse the repository at this point in the history
v1.9.2.4 - Update New-B1Service & Get-B1Service to replace service specific parameters to a dynamically generated -Type parameter.
  • Loading branch information
TehMuffinMoo authored Feb 28, 2024
2 parents d7e9043 + 04ec44b commit 4998610
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 95 deletions.
17 changes: 12 additions & 5 deletions Modules/ibPS/Functions/BloxOneDDI/Deploy-B1Appliance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@
Wait-Event -Timeout 10
if ($CSPStartCount -gt 120) {
Write-Error "Error. VM failed to register with the BloxOne CSP. Please check VM Console for details."
$Failed = $true
break
}
}
Expand All @@ -612,12 +613,16 @@
Set-VMDvdDrive -VMName $Name -ComputerName $($PSBoundParameters['HyperVServer']) -Path $null ## Cleanup metadata ISO
}

Write-Host "BloxOne Appliance is now available, check the CSP portal for registration of the device" -ForegroundColor Gray
if (!$Failed) {
Write-Host "BloxOne Appliance is now available, check the CSP portal for registration of the device" -ForegroundColor Gray

if (!($SkipCloudChecks)) {
Get-B1Host -IP $IP | Format-Table display_name,ip_address,host_version -AutoSize
if (!($SkipCloudChecks)) {
Get-B1Host -IP $IP | Format-Table display_name,ip_address,host_version -AutoSize
}
Write-Host "BloxOne Appliance deployed successfully." -ForegroundColor Green
} else {
Write-Error "Failed to deploy BloxOne Appliance."
}
Write-Host "BloxOne Appliance deployed successfully." -ForegroundColor Green
} else {
Write-Host "BloxOne Appliance deployed successfully." -ForegroundColor Green
}
Expand All @@ -626,6 +631,8 @@
break
}

Remove-Item -Path "work-dir" -Recurse ## Cleanup work directory
if (Test-Path 'work-dir') {
Remove-Item -Path "work-dir" -Recurse
} ## Cleanup work directory
}
}
7 changes: 7 additions & 0 deletions Modules/ibPS/Functions/BloxOneDDI/Get-B1Service.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
.PARAMETER Name
Filters the results by the name of the container
.PARAMETER Type
Filters based on the type of service
.PARAMETER Detailed
Additionally returns related host information
Expand Down Expand Up @@ -39,6 +42,7 @@
param(
[Parameter(ParameterSetName="noID",Mandatory=$false)]
[String]$Name,
[String]$Type,
[Switch]$Detailed,
[String]$Limit = "10001",
[Switch]$Strict,
Expand All @@ -54,6 +58,9 @@
if ($id) {
$Filters.Add("id==`"$id`"") | Out-Null
}
if ($Type) {
$Filters.Add("service_type==`"$Type`"") | Out-Null
}
if ($Detailed) {
$ServicesUri = "detail_services"
} else {
Expand Down
117 changes: 32 additions & 85 deletions Modules/ibPS/Functions/BloxOneDDI/New-B1Service.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@
.PARAMETER Name
The name of the new BloxOneDDI Service
.PARAMETER Type
The type of service to deploy
.PARAMETER Description
The description of the new BloxOneDDI Service
.PARAMETER OnPremHost
The name of the OnPremHost to create the service on
The name of the BloxOne DDI Host to create the service on
.PARAMETER Strict
Use strict filter matching. By default, filters are searched using wildcards where possible. Using strict matching will only return results matching exactly what is entered in the applicable parameters.
.PARAMETER NTP
This parameter specifies whether to deploy the NTP Service
.PARAMETER DNS
This parameter specifies whether to deploy the DNS Service
.EXAMPLE
## Create a DNS Service
New-B1Service -Type dns -Name "dns_bloxoneddihost1.mydomain.corp" -OnPremHost "bloxoneddihost1.mydomain.corp"
.PARAMETER DHCP
This parameter specifies whether to deploy the DHCP Service
.Example
New-B1Service -Name "dns_bloxoneddihost1.mydomain.corp" -Host "bloxoneddihost1.mydomain.corp" -NTP -DNS -DHCP
.EXAMPLE
## Create a DHCP Service
New-B1Service -Type dhcp -Name "dhcp_bloxoneddihost1.mydomain.corp" -OnPremHost "bloxoneddihost1.mydomain.corp"
.FUNCTIONALITY
BloxOneDDI
Expand All @@ -41,17 +40,13 @@
[Parameter(Mandatory=$true)]
[String]$Name,
[Parameter(Mandatory=$true)]
[String]$Type,
[Parameter(Mandatory=$true)]
[String]$OnPremHost,
[Parameter(Mandatory=$false)]
[String]$Description = "",
[Parameter(Mandatory=$false)]
[Switch]$Strict,
[Parameter(ParameterSetName="NTP")]
[Switch]$NTP,
[Parameter(ParameterSetName="DNS")]
[Switch]$DNS,
[Parameter(ParameterSetName="DHCP")]
[Switch]$DHCP
[Switch]$Strict
)
$MatchType = Match-Type $Strict
$B1Host = Get-B1Host -Name $OnPremHost -Detailed
Expand All @@ -60,76 +55,28 @@
Write-Host "Too many hosts returned. Please check the -name parameter, or use -Strict for strict parameter checking." -ForegroundColor Red
$B1Host | Format-Table -AutoSize
} else {
if ($NTP) {
if (Get-B1Service -Name $Name -Strict) {
Write-Host "Service $Name already exists" -ForegroundColor Yellow
} else {
$splat = @{
"name" = $Name
"description" = $Description
"service_type" = "ntp"
"desired_state" = "start"
"pool_id" = $($B1Host.pool.pool_id)
"tags" = @{}
"interface_labels" = @()
"destinations" = @()
"source_interfaces" = @()
} | ConvertTo-Json -Depth 3
$NewServiceResult = Query-CSP -Method POST -Uri "$(Get-B1CSPUrl)/api/infra/v1/services" -Data $splat | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue
if ($NewServiceResult.id) {
Write-Host "NTP service created successfully on $OnPremHost" -ForegroundColor Green
if (Get-B1Service -Name $Name -Strict) {
Write-Host "Service $Name already exists" -ForegroundColor Yellow
} else {
$splat = @{
"name" = $Name
"description" = $Description
"service_type" = $Type
"desired_state" = "start"
"pool_id" = $($B1Host.pool.pool_id)
"tags" = @{}
"interface_labels" = @()
"destinations" = @()
"source_interfaces" = @()
} | ConvertTo-Json -Depth 3
$NewServiceResult = Query-CSP -Method POST -Uri "$(Get-B1CSPUrl)/api/infra/v1/services" -Data $splat | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue
if ($NewServiceResult.id) {
Write-Host "$($Type.ToUpper()) service created successfully on $OnPremHost" -ForegroundColor Green
if ($Type -eq "ntp") {
Set-B1NTPServiceConfiguration -Name $Name -UseGlobalNTPConfig
} else {
Write-Host "Failed to create NTP service on $OnPremHost" -ForegroundColor Red
}
}
}

if ($DNS) {
if (Get-B1Service -Name $Name -Strict) {
Write-Host "Service $Name already exists" -ForegroundColor Red
} else {
$splat = @{
"name" = $Name
"description" = $Description
"service_type" = "dns"
"desired_state" = "start"
"pool_id" = $($B1Host.pool.pool_id)
"tags" = @{}
"interface_labels" = @()
"destinations" = @()
"source_interfaces" = @()
} | ConvertTo-Json -Depth 3
$NewServiceResult = Query-CSP -Method POST -Uri "$(Get-B1CSPUrl)/api/infra/v1/services" -Data $splat | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue
if ($NewServiceResult.id) {
Write-Host "DNS service created successfully on $OnPremHost" -ForegroundColor Green
} else {
Write-Host "Failed to create DNS service $OnPremHost" -ForegroundColor Green
}
}
}

if ($DHCP) {
if (Get-B1Service -Name $Name -Strict) {
Write-Host "Service $Name already exists" -ForegroundColor Red
} else {
$splat = @{
"name" = $Name
"description" = $Description
"service_type" = "dhcp"
"desired_state" = "start"
"pool_id" = $($B1Host.pool.pool_id)
"tags" = @{}
"interface_labels" = @()
"destinations" = @()
"source_interfaces" = @()
} | ConvertTo-Json -Depth 3
$NewServiceResult = Query-CSP -Method POST -Uri "$(Get-B1CSPUrl)/api/infra/v1/services" -Data $splat | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue
if ($NewServiceResult.id) {
Write-Host "DHCP service created successfully on $OnPremHost" -ForegroundColor Green
} else {
Write-Host "Failed to create DHCP service $OnPremHost" -ForegroundColor Green
}
Write-Host "Failed to create $($Type.ToUpper()) service on $OnPremHost" -ForegroundColor Red
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Modules/ibPS/Functions/BloxOneDDI/Private/ArgCompleter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ $endpoints = {
(((Query-CSP GET "$(Get-B1CSPUrl)/apidoc/docs/$($fakeBoundParameters['App'])").paths).psobject.properties | ForEach-Object -begin {$h=@{}} -process {$h."$($_.Name)" = $_.Value} -end {$h}).GetEnumerator() | Where-Object {$_.Name -like "$wordToComplete*"} | ForEach-Object {$_.Name}
}
Register-ArgumentCompleter -CommandName Get-B1Object,Get-B1Schema -ParameterName Endpoint -ScriptBlock $endpoints

$applications = {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
Get-B1Applications | Where-Object {$_ -like "$wordToComplete*"}
}
Register-ArgumentCompleter -CommandName Get-B1Service,New-B1Service -ParameterName Type -ScriptBlock $applications
Binary file not shown.
6 changes: 3 additions & 3 deletions Modules/ibPS/ibPS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Mat Cox
#
# Generated on: 2/14/2024
# Generated on: 2/28/2024
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'BloxOne-Main.psm1'

# Version number of this module.
ModuleVersion = '1.9.2.3'
ModuleVersion = '1.9.2.4'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -165,7 +165,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = 'v1.9.2.3 - Fix issue deploying BloxOne OVA with Infoblox self-signed certificate'
ReleaseNotes = 'v1.9.2.4 - Update New-B1Service & Get-B1Service to replace service specific parameters to a dynamically generated -Type parameter.'

# Prerelease string of this module
# Prerelease = ''
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Get-B1APIKey -Name "servicekeyname" -CreatedBy "user@domain.corp"
Get-B1UserAPIKey
Retrieves a list of interactive API Keys configured for your user within the BloxOne Cloud
Get-B1Service -Name "dns_bloxoneddihost1.mydomain.corp"
Get-B1Service -Type dns -Name "dns_bloxoneddihost1.mydomain.corp"
Retrieves a list of deployed BloxOneDDI Services
Start-B1Service -Name "dns_bloxoneddihost1.mydomain.corp"
Expand Down Expand Up @@ -366,7 +366,7 @@ Start-B1TDDossierLookup -Type host -Value eicar.co
New-B1TDTideDataProfile -Name "My Profile" -Description "My TIDE Data Profile" -RPZFeed "my-rpz-feed" -DefaultTTL $false
Creates a new TIDE Data Profile
New-B1Service -Name "dns_bloxoneddihost1.mydomain.corp" -Host "bloxoneddihost1.mydomain.corp" -NTP -DNS -DHCP
New-B1Service -Type dns -Name "dns_bloxoneddihost1.mydomain.corp" -Host "bloxoneddihost1.mydomain.corp"
Deploys a new BloxOneDDI Service
New-B1AuthoritativeZone -FQDN "prod.mydomain.corp" -View "Global" -DNSHosts "bloxoneddihost1.mydomain.corp","bloxoneddihost2.mydomain.corp" -Description "Prod Zone"
Expand Down

0 comments on commit 4998610

Please sign in to comment.