Skip to content

Commit

Permalink
fix: module dependencies
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
Ryan Johnson committed Jul 17, 2023
1 parent ff67857 commit 708cd2b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
22 changes: 17 additions & 5 deletions VMware.CloudFoundation.Reporting.psd1
Original file line number Diff line number Diff line change
@@ -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
#

@{
Expand All @@ -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 = @()
Expand Down Expand Up @@ -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 = @()
Expand Down Expand Up @@ -129,4 +142,3 @@
# DefaultCommandPrefix = ''

}

54 changes: 33 additions & 21 deletions VMware.CloudFoundation.Reporting.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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) {

Expand All @@ -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
}
}
Expand Down

0 comments on commit 708cd2b

Please sign in to comment.