From 23399f7d72af8d41f8bb23f2326306523faa8765 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Jun 2023 20:45:39 -0400 Subject: [PATCH 1/3] fix: module dependencies - Added the `RequiredModules` key to the module manifest to specify the minimum dependencies required to install and run the PowerShell module. - Updated `Test-VcfReportingPrereq` to verify that the minimum dependencies are met to run the PowerShell module based on the module's manifest. - Bumps `PowerValidatedSolutions` dependency to v2.5.0 (next release) in the manifest. Signed-off-by: Ryan Johnson --- CHANGELOG.md | 16 ++++++++ VMware.CloudFoundation.Reporting.psd1 | 22 ++++++++--- VMware.CloudFoundation.Reporting.psm1 | 54 ++++++++++++++++----------- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f55abb64..e6d19c31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Release History +## v2.3.0 (Unreleased) + +> Release Date: Unreleased + +Enhancement: + +- Added the `RequiredModules` key to the module manifest to specify the minimum dependencies required to install and run the PowerShell module. [GH-155](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/155) +- Updated `Test-VcfReportingPrereq` to verify that the minimum dependencies are met to run the PowerShell module based on the module's manifest. [GH-155](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/155) + +Chore: + +- Updated `PowerValidatedSolutions` from v2.4.0 to v2.5.0. [GH-155](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/155) + ## [v2.2.0](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/releases/tag/v2.2.0) > Release Date: 2023-06-27 @@ -8,6 +21,9 @@ Bugfix: - Updates `Publish-StorageCapacityHealth` to correct [GH-147](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/issues/147). [GH-148](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/148) +Chore: + +- Updated `PowerValidatedSolutions` from v2.3.0 to v2.4.0. [GH-150](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/150) ## [v2.1.0](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/releases/tag/v2.1.0) diff --git a/VMware.CloudFoundation.Reporting.psd1 b/VMware.CloudFoundation.Reporting.psd1 index 8d14b5b6..cc34ed9f 100644 --- a/VMware.CloudFoundation.Reporting.psd1 +++ b/VMware.CloudFoundation.Reporting.psd1 @@ -1,9 +1,9 @@ # # Module manifest for module 'VMware.CloudFoundation.Reporting' # -# Generated by: Gary Blake, Cloud Infrastructure Business Group (CIBG) +# Generated by: VMware, Inc. # -# Generated on: 2023-06-27 +# Generated on: 2023-07-25 # @{ @@ -12,7 +12,7 @@ RootModule = '.\VMware.CloudFoundation.Reporting.psm1' # Version number of this module. - ModuleVersion = '2.2.0.1000' + ModuleVersion = '2.3.0.1000' # Supported PSEditions # CompatiblePSEditions = @() @@ -51,7 +51,20 @@ # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module - # RequiredModules = @() + RequiredModules = @( + @{ + ModuleName = 'VMware.vSphere.SsoAdmin' + ModuleVersion = '1.3.9' + } + @{ + ModuleName = 'PowerVCF' + ModuleVersion = '2.3.0' + } + @{ + ModuleName = 'PowerValidatedSolutions' + ModuleVersion = '2.5.0' + } + ) # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() @@ -129,4 +142,3 @@ # DefaultCommandPrefix = '' } - diff --git a/VMware.CloudFoundation.Reporting.psm1 b/VMware.CloudFoundation.Reporting.psm1 index a599b687..e8ba7dee 100644 --- a/VMware.CloudFoundation.Reporting.psm1 +++ b/VMware.CloudFoundation.Reporting.psm1 @@ -9227,11 +9227,12 @@ Export-ModuleMember -Function Request-ValidatedSolutionOverview Function Test-VcfReportingPrereq { <# - .SYNOPSIS - Validate prerequisites to run the PowerShell module. + .SYNOPSIS + Verifies that the minimum dependencies are met to run the PowerShell module. .DESCRIPTION - The Test-VcfReportingPrereq cmdlet checks that all the prerequisites have been met to run the PowerShell module. + The Test-VcfReportingPrereq cmdlet verifies that the minimum dependencies are met to + run the the PowerShell module. .EXAMPLE Test-VcfReportingPrereq -sddcManagerFqdn sfo-vcf01.sfo.rainpole.io -sddcManagerUser admin@local -sddcManagerPass VMw@re1!VMw@re1! @@ -9258,13 +9259,6 @@ Function Test-VcfReportingPrereq { $vcfMinVersion = "4.4.0" - $modules = @( - @{ Name=("VMware.PowerCLI"); MinimumVersion=("13.0.0")} - @{ Name=("VMware.vSphere.SsoAdmin"); MinimumVersion=("1.3.9")} - @{ Name=("PowerVCF"); MinimumVersion=("2.3.0")} - @{ Name=("PowerValidatedSolutions"); MinimumVersion=("2.4.0")} - ) - if (Test-VCFConnection -server $sddcManagerFqdn) { if (Test-VCFAuthentication -server $sddcManagerFqdn -user $sddcManagerUser -pass $sddcManagerPass) { @@ -9278,22 +9272,40 @@ Function Test-VcfReportingPrereq { Show-ReportingOutput -Type INFO -Message $message } - foreach ($module in $modules ) { - if ((Get-InstalledModule -ErrorAction SilentlyContinue -Name $module.Name).Version -lt $module.MinimumVersion) { - $message = "PowerShell Module: $($module.Name) $($module.MinimumVersion) minimum required version is not installed." - Show-ReportingOutput -type ERROR -message $message - Break + $moduleName = $myInvocation.myCommand.ModuleName + $moduleData = (Get-Module -Name $moduleName) + + if ($PSEdition -eq 'Core' -and ($PSVersionTable.OS).Split(' ')[0] -eq 'Linux') { + $moduleManifestPath = $moduleData.ModuleBase + '/' + $moduleData.Name + '.psd1' + } else { + $moduleManifestPath = $moduleData.ModuleBase + '\' + $moduleData.Name + '.psd1' + } + + $moduleManifest = Import-PowerShellDataFile -Path $moduleManifestPath + $requiredModules = $moduleManifest.RequiredModules + + foreach ($module in $requiredModules) { + $moduleName = $module.ModuleName + $requiredVersion = $module.ModuleVersion + $installedModule = Get-Module -ListAvailable -Name $moduleName + + if ($installedModule) { + $installedVersion = $installedModule.Version + if ($installedVersion -lt $requiredVersion) { + $message = "$($moduleName) $($installedVersion) is installed. Install $($moduleName) $($requiredVersion) or higher." + Show-ReportingOutput -type ERROR -message $message + } elseif ($installedVersion -ge $requiredVersion) { + $message = "$($moduleName) $($installedVersion) is installed version and meets the minimum required version of $($moduleName) $($requiredVersion)." + Show-ReportingOutput -type INFO -message $message + } } else { - $moduleCurrentVersion = (Get-InstalledModule -Name $module.Name).Version - $message = "PowerShell Module: $($module.Name) $($moduleCurrentVersion) is installed and supports the minimum required version." - Show-ReportingOutput -Type INFO -Message $message + $message = "$($moduleName) is not installed. Install $($moduleName) $($requiredVersion) or higher." + Show-ReportingOutputt -type ERROR -message $message } } } } - - } - Catch { + } Catch { Write-Error $_.Exception.Message } } From 708cd2b0a1e18a0a41d01691c274ee193f9f0567 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Jun 2023 20:45:39 -0400 Subject: [PATCH 2/3] fix: module dependencies - Added the `RequiredModules` key to the module manifest to specify the minimum dependencies required to install and run the PowerShell module. - Updated `Test-VcfReportingPrereq` to verify that the minimum dependencies are met to run the PowerShell module based on the module's manifest. - Bumps `PowerValidatedSolutions` dependency to v2.5.0 (next release) in the manifest. Signed-off-by: Ryan Johnson --- CHANGELOG.md | 16 ++++++++ VMware.CloudFoundation.Reporting.psd1 | 22 ++++++++--- VMware.CloudFoundation.Reporting.psm1 | 54 ++++++++++++++++----------- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f55abb64..e6d19c31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Release History +## v2.3.0 (Unreleased) + +> Release Date: Unreleased + +Enhancement: + +- Added the `RequiredModules` key to the module manifest to specify the minimum dependencies required to install and run the PowerShell module. [GH-155](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/155) +- Updated `Test-VcfReportingPrereq` to verify that the minimum dependencies are met to run the PowerShell module based on the module's manifest. [GH-155](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/155) + +Chore: + +- Updated `PowerValidatedSolutions` from v2.4.0 to v2.5.0. [GH-155](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/155) + ## [v2.2.0](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/releases/tag/v2.2.0) > Release Date: 2023-06-27 @@ -8,6 +21,9 @@ Bugfix: - Updates `Publish-StorageCapacityHealth` to correct [GH-147](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/issues/147). [GH-148](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/148) +Chore: + +- Updated `PowerValidatedSolutions` from v2.3.0 to v2.4.0. [GH-150](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/150) ## [v2.1.0](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/releases/tag/v2.1.0) diff --git a/VMware.CloudFoundation.Reporting.psd1 b/VMware.CloudFoundation.Reporting.psd1 index 8d14b5b6..cc34ed9f 100644 --- a/VMware.CloudFoundation.Reporting.psd1 +++ b/VMware.CloudFoundation.Reporting.psd1 @@ -1,9 +1,9 @@ # # Module manifest for module 'VMware.CloudFoundation.Reporting' # -# Generated by: Gary Blake, Cloud Infrastructure Business Group (CIBG) +# Generated by: VMware, Inc. # -# Generated on: 2023-06-27 +# Generated on: 2023-07-25 # @{ @@ -12,7 +12,7 @@ RootModule = '.\VMware.CloudFoundation.Reporting.psm1' # Version number of this module. - ModuleVersion = '2.2.0.1000' + ModuleVersion = '2.3.0.1000' # Supported PSEditions # CompatiblePSEditions = @() @@ -51,7 +51,20 @@ # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module - # RequiredModules = @() + RequiredModules = @( + @{ + ModuleName = 'VMware.vSphere.SsoAdmin' + ModuleVersion = '1.3.9' + } + @{ + ModuleName = 'PowerVCF' + ModuleVersion = '2.3.0' + } + @{ + ModuleName = 'PowerValidatedSolutions' + ModuleVersion = '2.5.0' + } + ) # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() @@ -129,4 +142,3 @@ # DefaultCommandPrefix = '' } - diff --git a/VMware.CloudFoundation.Reporting.psm1 b/VMware.CloudFoundation.Reporting.psm1 index a599b687..e8ba7dee 100644 --- a/VMware.CloudFoundation.Reporting.psm1 +++ b/VMware.CloudFoundation.Reporting.psm1 @@ -9227,11 +9227,12 @@ Export-ModuleMember -Function Request-ValidatedSolutionOverview Function Test-VcfReportingPrereq { <# - .SYNOPSIS - Validate prerequisites to run the PowerShell module. + .SYNOPSIS + Verifies that the minimum dependencies are met to run the PowerShell module. .DESCRIPTION - The Test-VcfReportingPrereq cmdlet checks that all the prerequisites have been met to run the PowerShell module. + The Test-VcfReportingPrereq cmdlet verifies that the minimum dependencies are met to + run the the PowerShell module. .EXAMPLE Test-VcfReportingPrereq -sddcManagerFqdn sfo-vcf01.sfo.rainpole.io -sddcManagerUser admin@local -sddcManagerPass VMw@re1!VMw@re1! @@ -9258,13 +9259,6 @@ Function Test-VcfReportingPrereq { $vcfMinVersion = "4.4.0" - $modules = @( - @{ Name=("VMware.PowerCLI"); MinimumVersion=("13.0.0")} - @{ Name=("VMware.vSphere.SsoAdmin"); MinimumVersion=("1.3.9")} - @{ Name=("PowerVCF"); MinimumVersion=("2.3.0")} - @{ Name=("PowerValidatedSolutions"); MinimumVersion=("2.4.0")} - ) - if (Test-VCFConnection -server $sddcManagerFqdn) { if (Test-VCFAuthentication -server $sddcManagerFqdn -user $sddcManagerUser -pass $sddcManagerPass) { @@ -9278,22 +9272,40 @@ Function Test-VcfReportingPrereq { Show-ReportingOutput -Type INFO -Message $message } - foreach ($module in $modules ) { - if ((Get-InstalledModule -ErrorAction SilentlyContinue -Name $module.Name).Version -lt $module.MinimumVersion) { - $message = "PowerShell Module: $($module.Name) $($module.MinimumVersion) minimum required version is not installed." - Show-ReportingOutput -type ERROR -message $message - Break + $moduleName = $myInvocation.myCommand.ModuleName + $moduleData = (Get-Module -Name $moduleName) + + if ($PSEdition -eq 'Core' -and ($PSVersionTable.OS).Split(' ')[0] -eq 'Linux') { + $moduleManifestPath = $moduleData.ModuleBase + '/' + $moduleData.Name + '.psd1' + } else { + $moduleManifestPath = $moduleData.ModuleBase + '\' + $moduleData.Name + '.psd1' + } + + $moduleManifest = Import-PowerShellDataFile -Path $moduleManifestPath + $requiredModules = $moduleManifest.RequiredModules + + foreach ($module in $requiredModules) { + $moduleName = $module.ModuleName + $requiredVersion = $module.ModuleVersion + $installedModule = Get-Module -ListAvailable -Name $moduleName + + if ($installedModule) { + $installedVersion = $installedModule.Version + if ($installedVersion -lt $requiredVersion) { + $message = "$($moduleName) $($installedVersion) is installed. Install $($moduleName) $($requiredVersion) or higher." + Show-ReportingOutput -type ERROR -message $message + } elseif ($installedVersion -ge $requiredVersion) { + $message = "$($moduleName) $($installedVersion) is installed version and meets the minimum required version of $($moduleName) $($requiredVersion)." + Show-ReportingOutput -type INFO -message $message + } } else { - $moduleCurrentVersion = (Get-InstalledModule -Name $module.Name).Version - $message = "PowerShell Module: $($module.Name) $($moduleCurrentVersion) is installed and supports the minimum required version." - Show-ReportingOutput -Type INFO -Message $message + $message = "$($moduleName) is not installed. Install $($moduleName) $($requiredVersion) or higher." + Show-ReportingOutputt -type ERROR -message $message } } } } - - } - Catch { + } Catch { Write-Error $_.Exception.Message } } From 32b1074d338d0be2fac48ab4e0cba4e5deadbcca Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Mon, 17 Jul 2023 12:49:45 -0400 Subject: [PATCH 3/3] fix: minor fix Signed-off-by: Ryan Johnson --- VMware.CloudFoundation.Reporting.psm1 | 2 +- docs/documentation/functions/Test-VcfReportingPrereq.md | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/VMware.CloudFoundation.Reporting.psm1 b/VMware.CloudFoundation.Reporting.psm1 index e8ba7dee..ebb41f9d 100644 --- a/VMware.CloudFoundation.Reporting.psm1 +++ b/VMware.CloudFoundation.Reporting.psm1 @@ -9300,7 +9300,7 @@ Function Test-VcfReportingPrereq { } } else { $message = "$($moduleName) is not installed. Install $($moduleName) $($requiredVersion) or higher." - Show-ReportingOutputt -type ERROR -message $message + Show-ReportingOutput -type ERROR -message $message } } } diff --git a/docs/documentation/functions/Test-VcfReportingPrereq.md b/docs/documentation/functions/Test-VcfReportingPrereq.md index 51338287..decdbe07 100644 --- a/docs/documentation/functions/Test-VcfReportingPrereq.md +++ b/docs/documentation/functions/Test-VcfReportingPrereq.md @@ -2,13 +2,12 @@ ## SYNOPSIS -Validate prerequisites to run the PowerShell module. +Verifies that the minimum dependencies are met to run the PowerShell module. ## SYNTAX ```powershell -Test-VcfReportingPrereq [-sddcManagerFqdn] [-sddcManagerUser] [-sddcManagerPass] - [] +Test-VcfReportingPrereq [-sddcManagerFqdn] [-sddcManagerUser] [-sddcManagerPass] [] ``` ## DESCRIPTION