Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: module dependencies #155

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-ReportingOutput -type ERROR -message $message
}
}
}
}

}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
Expand Down
5 changes: 2 additions & 3 deletions docs/documentation/functions/Test-VcfReportingPrereq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] <String> [-sddcManagerUser] <String> [-sddcManagerPass] <String>
[<CommonParameters>]
Test-VcfReportingPrereq [-sddcManagerFqdn] <String> [-sddcManagerUser] <String> [-sddcManagerPass] <String> [<CommonParameters>]
```

## DESCRIPTION
Expand Down