Skip to content

Commit

Permalink
Example using the API check for how we can use Private Functions. To …
Browse files Browse the repository at this point in the history
…fix issue #47
  • Loading branch information
jonathanmedd committed Sep 12, 2016
1 parent 2ae569c commit 4968e4c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
54 changes: 54 additions & 0 deletions PowervRA/Functions/Private Functions/PrivateFunctions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function xRequires {
<#
.SYNOPSIS
Checks the required API Version for the current function
.DESCRIPTION
Checks the required API Version for the current function
.PARAMETER Version
The API Version that the function supports
.PARAMETER Context
The functions execution context. This should always be $MyInvocation
.INPUTS
System.Int
System.Management.Automation.PSObject.
.OUTPUTS
None
.EXAMPLE
function Get-Example {
# This function does not support API versions lower than Version 7
xRequires -Version 7 -Context $MyInvocation
}
#>

[CmdletBinding()]

Param (

[Parameter(Mandatory=$true)]
[Int]$Version,

[Parameter(Mandatory=$true)]
[PSCustomobject]$Context

)
# --- Test for vRA API version
if (-not $Global:vRAConnection){

throw "vRA Connection variable does not exist. Please run Connect-vRAServer first to create it"
}

elseif ($Global:vRAConnection.APIVersion -lt $Version) {

throw "$($Context.MyCommand) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"
}
}
9 changes: 1 addition & 8 deletions PowervRA/Functions/Set-vRAUserPrincipal.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,7 @@ function Set-vRAUserPrincipal {

begin {
# --- Test for vRA API version
if (-not $Global:vRAConnection){

throw "vRA Connection variable does not exist. Please run Connect-vRAServer first to create it"
}
elseif ($Global:vRAConnection.APIVersion -lt 7){

throw "$($MyInvocation.MyCommand) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"
}
xRequires -Version 7 -Context $MyInvocation
}

process {
Expand Down
4 changes: 2 additions & 2 deletions PowervRA/PowervRA.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PowerShellVersion = '4.0'
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
ScriptsToProcess = 'Functions\Private Functions\PrivateFunctions.ps1'

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
Expand Down Expand Up @@ -145,7 +145,7 @@ NestedModules = 'Functions\Add-vRAPrincipalToTenantRole.psm1',
'Functions\Set-vRAStorageReservationPolicy.psm1',
'Functions\Set-vRATenant.psm1',
'Functions\Set-vRATenantDirectory.psm1',
'Functions\Set-vRAUserPrincipal.psm1'
'Functions\Set-vRAUserPrincipal.psm1'

# Functions to export from this module
FunctionsToExport = 'Add-vRAPrincipalToTenantRole','Add-vRAReservationNetwork','Add-vRAReservationStorage','Connect-vRAServer','Disconnect-vRAServer','Export-vRAContentPackage','Get-vRAApplianceServiceStatus','Get-vRAAuthorizationRole','Get-vRABlueprint','Get-vRABusinessGroup','Get-vRACatalogItem','Get-vRACatalogPrincipal','Get-vRAConsumerCatalogItem','Get-vRAConsumerCatalogItemRequestTemplate','Get-vRAConsumerEntitledCatalogItem','Get-vRAConsumerRequest','Get-vRAConsumerResource','Get-vRAConsumerResourceOperation','Get-vRAConsumerResourceType','Get-vRAConsumerService','Get-vRAContentPackage','Get-vRAEntitledCatalogItem','Get-vRAEntitlement','New-vRAGroupPrincipal','Get-vRAGroupPrincipal','Get-vRAReservation','Get-vRAReservationComputeResource','Get-vRAReservationComputeResourceMemory','Get-vRAReservationComputeResourceNetwork','Get-vRAReservationComputeResourceResourcePool','Get-vRAReservationComputeResourceStorage','Get-vRAReservationPolicy','Get-vRAReservationTemplate','Get-vRAReservationType', 'Get-vRAResourceMetric', 'Get-vRAResourceOperation','Get-vRAResourceType','Get-vRAService','Get-vRAServiceBlueprint','Get-vRAStorageReservationPolicy','Get-vRATenant','Get-vRATenantDirectory','Get-vRATenantDirectoryStatus','Get-vRATenantRole','Get-vRAUserPrincipal','Get-vRAVersion','Invoke-vRARestMethod','New-vRABusinessGroup','New-vRAContentPackage','New-vRAEntitlement','New-vRAReservation','New-vRAReservationNetworkDefinition','New-vRAReservationPolicy','New-vRAReservationStorageDefinition','New-vRAService','New-vRAStorageReservationPolicy','New-vRATenant','New-vRATenantDirectory','New-vRAUserPrincipal','Remove-vRABusinessGroup','Remove-vRAContentPackage', 'Remove-vRAGroupPrincipal','Remove-vRAPrincipalFromTenantRole','Remove-vRAReservation','Remove-vRAReservationPolicy','Remove-vRAService','Remove-vRAStorageReservationPolicy','Remove-vRATenant','Remove-vRATenantDirectory','Remove-vRAUserPrincipal','Request-vRAConsumerCatalogItem','Set-vRABusinessGroup','Set-vRACatalogItem','Set-vRAEntitlement','Set-vRAReservation','Set-vRAReservationNetwork','Set-vRAReservationPolicy','Set-vRAReservationStorage','Set-vRAService','Set-vRAStorageReservationPolicy','Set-vRATenant','Set-vRATenantDirectory','Set-vRAUserPrincipal'
Expand Down

0 comments on commit 4968e4c

Please sign in to comment.