Skip to content

Commit

Permalink
Merge pull request #179 from jakkulabs/bugfix-Get-vRABlueprint-limit-…
Browse files Browse the repository at this point in the history
…and-api-endpoint

Bugfix - Get-vRABlueprint Limit implementation and changed API endpoint
  • Loading branch information
jonathanmedd authored Apr 12, 2018
2 parents 9d14291 + 2bdb20c commit 1cd84c9
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 162 deletions.
200 changes: 200 additions & 0 deletions src/Functions/Public/composition-service/Get-vRABlueprint.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
function Get-vRABlueprint {
<#
.SYNOPSIS
Retrieve vRA Blueprints
.DESCRIPTION
Retrieve vRA Blueprints
.PARAMETER Id
Specify the ID of a Blueprint
.PARAMETER Name
Specify the Name of a Blueprint
.PARAMETER ExtendedProperties
Return Blueprint Extended Properties. Performance will be slower since
additional API requests may be required
.PARAMETER Limit
The number of entries returned per page from the API. This has a default value of 100.
.INPUTS
System.String
.OUTPUTS
System.Management.Automation.PSObject.
.EXAMPLE
Get-vRABlueprint
.EXAMPLE
Get-vRABlueprint -Id "309100fd-b8ce-4e8c-ac8c-a667b8ace54f"
.EXAMPLE
Get-vRABlueprint -Name "Blueprint01","Blueprint02"
.EXAMPLE
Get-vRABlueprint -Name "Blueprint01","Blueprint02" -ExtendedProperties
#>
[CmdletBinding(DefaultParameterSetName="Standard")][OutputType('System.Management.Automation.PSObject')]

Param (

[parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="ById")]
[ValidateNotNullOrEmpty()]
[String[]]$Id,

[parameter(Mandatory=$true,ValueFromPipeline=$false,ParameterSetName="ByName")]
[ValidateNotNullOrEmpty()]
[String[]]$Name,

[parameter(Mandatory=$false,ValueFromPipeline=$false)]
[Switch]$ExtendedProperties,

[parameter(Mandatory=$false,ValueFromPipeline=$false)]
[ValidateNotNullOrEmpty()]
[String]$Limit = "100"
)

# --- Add begin, process, end
# -- Functions for standard and extended output
begin {

# --- Test for vRA API version
xRequires -Version 7.0

function StandardOutput ($Blueprint) {

[pscustomobject]@{

Name = $Blueprint.name
Id = $Blueprint.id
Description = $Blueprint.description
CreatedDate = $Blueprint.createdDate
LastUpdated = $Blueprint.lastUpdated
Version = $Blueprint.version
PublishStatus = $Blueprint.publishStatusName
}
}
function ExtendedOutput ($Blueprint) {

[pscustomobject]@{

Name = $Blueprint.name
Id = $Blueprint.id
Description = $Blueprint.description
CreatedDate = $Blueprint.createdDate
LastUpdated = $Blueprint.lastUpdated
Version = $Blueprint.version
PublishStatus = $Blueprint.publishStatusName
Components = $Blueprint.components
Properties = $Blueprint.properties
PropertyGroups = $Blueprint.propertyGroups
ExternalId = $Blueprint.externalId
Layout = $Blueprint.layout
SnapshotVersion = $Blueprint.snapshotVersion
}
}
}

process {

try {
switch ($PsCmdlet.ParameterSetName)
{
"ById" {

foreach ($BlueprintId in $Id){

$URI = "/composition-service/api/blueprints/$($BlueprintId)"

# --- Run vRA REST Request
$ReturnedBlueprint = Invoke-vRARestMethod -Method GET -URI $URI

if ($PSBoundParameters.ContainsKey('ExtendedProperties')){

ExtendedOutput($ReturnedBlueprint)
}
else {
StandardOutput($ReturnedBlueprint)
}
}

break
}

"ByName" {

foreach ($BlueprintName in $Name){

$URI = "/composition-service/api/blueprints?`$filter=name%20eq%20'$($BlueprintName)'"

# --- Run vRA REST Request
$Response = Invoke-vRARestMethod -Method GET -URI $URI
$Blueprints = $Response.content

if (-not $Blueprints){

throw "Unable to find vRA Blueprint: $($BlueprintName)"
}

foreach ($ReturnedBlueprint in $Blueprints){

if ($PSBoundParameters.ContainsKey('ExtendedProperties')){

$URI = "/composition-service/api/blueprints/$($ReturnedBlueprint.id)"

# --- Run vRA REST Request
$ReturnedExtendedBlueprint = Invoke-vRARestMethod -Method GET -URI $URI

ExtendedOutput($ReturnedExtendedBlueprint)
}
else {

StandardOutput($ReturnedBlueprint)
}
}
}

break
}

"Standard" {

$URI = "/composition-service/api/blueprints?limit=$($Limit)"

# --- Run vRA REST Request
$Response = Invoke-vRARestMethod -Method GET -URI $URI
$Blueprints = $Response.content

foreach ($ReturnedBlueprint in $Blueprints){

if ($PSBoundParameters.ContainsKey('ExtendedProperties')){

$URI = "/composition-service/api/blueprints/$($ReturnedBlueprint.id)"

# --- Run vRA REST Request
$ReturnedExtendedBlueprint = Invoke-vRARestMethod -Method GET -URI $URI

ExtendedOutput($ReturnedExtendedBlueprint)
}
else {

StandardOutput($ReturnedBlueprint)
}
}

break
}
}
}
catch [Exception]{

throw
}
}
end {

}
}
162 changes: 0 additions & 162 deletions src/Functions/Public/content-management-service/Get-vRABlueprint.ps1

This file was deleted.

6 changes: 6 additions & 0 deletions tests/Test006-BlueprintAndServiceBlueprint.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Describe -Name 'Blueprint Tests' -Fixture {
$BlueprintA.Name | Should Be $JSON.Blueprint.Name
}

It -Name "Return named Blueprint $($JSON.Blueprint.Name) Extended Properties" -Test {

$BlueprintB = Get-vRABlueprint -Name $JSON.Blueprint.Name -ExtendedProperties
$BlueprintB.ExternalId | Should BeOfType System.String
}

It -Name "Return named Service Blueprint $($JSON.ServiceBlueprint.Name)" -Test {

$ServiceBlueprintA = Get-vRAServiceBlueprint -Name $JSON.ServiceBlueprint.Name
Expand Down

0 comments on commit 1cd84c9

Please sign in to comment.