From 6b3807dba81019bf5e5744282233969bf7074291 Mon Sep 17 00:00:00 2001 From: jonathanmedd Date: Wed, 4 Apr 2018 18:00:54 +0100 Subject: [PATCH 1/2] Initial draft --- .../composition-service/Get-vRABlueprint.ps1 | 197 ++++++++++++++++++ .../Get-vRABlueprint.ps1 | 162 -------------- 2 files changed, 197 insertions(+), 162 deletions(-) create mode 100644 src/Functions/Public/composition-service/Get-vRABlueprint.ps1 delete mode 100644 src/Functions/Public/content-management-service/Get-vRABlueprint.ps1 diff --git a/src/Functions/Public/composition-service/Get-vRABlueprint.ps1 b/src/Functions/Public/composition-service/Get-vRABlueprint.ps1 new file mode 100644 index 00000000..525a74ef --- /dev/null +++ b/src/Functions/Public/composition-service/Get-vRABlueprint.ps1 @@ -0,0 +1,197 @@ +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" +#> +[CmdletBinding(DefaultParameterSetName="Standard")][OutputType('System.Management.Automation.PSObject')] + + Param ( + + [parameter(Mandatory=$true,ValueFromPipeline=$false,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 { + + } +} \ No newline at end of file diff --git a/src/Functions/Public/content-management-service/Get-vRABlueprint.ps1 b/src/Functions/Public/content-management-service/Get-vRABlueprint.ps1 deleted file mode 100644 index d5dda3a9..00000000 --- a/src/Functions/Public/content-management-service/Get-vRABlueprint.ps1 +++ /dev/null @@ -1,162 +0,0 @@ -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 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" -#> -[CmdletBinding(DefaultParameterSetName="Standard")][OutputType('System.Management.Automation.PSObject')] - - Param ( - - [parameter(Mandatory=$true,ValueFromPipeline=$false,ParameterSetName="ById")] - [ValidateNotNullOrEmpty()] - [String[]]$Id, - - [parameter(Mandatory=$true,ValueFromPipeline=$false,ParameterSetName="ByName")] - [ValidateNotNullOrEmpty()] - [String[]]$Name, - - [parameter(Mandatory=$false,ValueFromPipeline=$false)] - [ValidateNotNullOrEmpty()] - [String]$Limit = "100" - ) - - # --- Test for vRA API version - xRequires -Version 7.0 - - try { - switch ($PsCmdlet.ParameterSetName) - { - "ById" { - - foreach ($BlueprintId in $Id){ - - $URI = "/content-management-service/api/contents/$($BlueprintId)" - - # --- Run vRA REST Request - $Response = Invoke-vRARestMethod -Method GET -URI $URI - - $Blueprints = $Response | Where-Object {$_.contentTypeId -eq "composite-blueprint"} - - foreach ($Blueprint in $Blueprints){ - - [pscustomobject]@{ - - Name = $Blueprint.name - Id = $Blueprint.id - Description = $Blueprint.description - ContentId = $Blueprint.contentId - TenantId = $Blueprint.tenantId - MimeType = $Blueprint.mimeType - SubtenantId = $Blueprint.subtenantId - Dependencies = $Blueprint.dependencies - CreatedDate = $Blueprint.createdDate - LastUpdated = $Blueprint.lastUpdated - version = $Blueprint.version - } - } - } - - break - } - - "ByName" { - - foreach ($BlueprintName in $Name){ - - $URI = "/content-management-service/api/contents?`$filter=name%20eq%20'$($BlueprintName)'" - - # --- Run vRA REST Request - $Response = Invoke-vRARestMethod -Method GET -URI $URI - - $Blueprints = $Response.content | Where-Object {$_.contentTypeId -eq "composite-blueprint"} - - if (-not $Blueprints){ - - throw "Unable to find vRA Blueprint: $($BlueprintName)" - } - - foreach ($Blueprint in $Blueprints){ - - [pscustomobject]@{ - - Name = $Blueprint.name - Id = $Blueprint.id - Description = $Blueprint.description - ContentId = $Blueprint.contentId - TenantId = $Blueprint.tenantId - MimeType = $Blueprint.mimeType - SubtenantId = $Blueprint.subtenantId - Dependencies = $Blueprint.dependencies - CreatedDate = $Blueprint.createdDate - LastUpdated = $Blueprint.lastUpdated - version = $Blueprint.version - } - } - } - - break - } - - "Standard" { - - $URI = "/content-management-service/api/contents?`$filter=contentTypeId%20eq%20'composite-blueprint'" - - # --- Run vRA REST Request - $Response = Invoke-vRARestMethod -Method GET -URI $URI - - $Blueprints = $Response.content - - foreach ($Blueprint in $Blueprints){ - - [pscustomobject]@{ - - Name = $Blueprint.name - Id = $Blueprint.id - Description = $Blueprint.description - ContentId = $Blueprint.contentId - TenantId = $Blueprint.tenantId - MimeType = $Blueprint.mimeType - SubtenantId = $Blueprint.subtenantId - Dependencies = $Blueprint.dependencies - CreatedDate = $Blueprint.createdDate - LastUpdated = $Blueprint.lastUpdated - version = $Blueprint.version - } - } - - break - } - } - } - catch [Exception]{ - - throw - } -} \ No newline at end of file From 2bdb20c22bb9029dcc5c81f95d9dcbcc6d9098c6 Mon Sep 17 00:00:00 2001 From: jonathanmedd Date: Wed, 11 Apr 2018 18:27:40 +0100 Subject: [PATCH 2/2] Updates to support pipeline Added example Updated test --- .../Public/composition-service/Get-vRABlueprint.ps1 | 5 ++++- tests/Test006-BlueprintAndServiceBlueprint.Tests.ps1 | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Functions/Public/composition-service/Get-vRABlueprint.ps1 b/src/Functions/Public/composition-service/Get-vRABlueprint.ps1 index 525a74ef..537c9a04 100644 --- a/src/Functions/Public/composition-service/Get-vRABlueprint.ps1 +++ b/src/Functions/Public/composition-service/Get-vRABlueprint.ps1 @@ -33,12 +33,15 @@ .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=$false,ParameterSetName="ById")] + [parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="ById")] [ValidateNotNullOrEmpty()] [String[]]$Id, diff --git a/tests/Test006-BlueprintAndServiceBlueprint.Tests.ps1 b/tests/Test006-BlueprintAndServiceBlueprint.Tests.ps1 index 16c678b8..aff718cc 100644 --- a/tests/Test006-BlueprintAndServiceBlueprint.Tests.ps1 +++ b/tests/Test006-BlueprintAndServiceBlueprint.Tests.ps1 @@ -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