Skip to content

[#111731500] Updated AzureRm module to include major versions for each package #1678

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

Merged
merged 4 commits into from
Jan 20, 2016
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
4 changes: 2 additions & 2 deletions src/Common/Commands.Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ protected static void InitializeDataCollectionProfile()
{
if (string.Equals(value, bool.FalseString, StringComparison.OrdinalIgnoreCase))
{
// Disable data collection only if it is explictly set to 'false'.
// Disable data collection only if it is explicitly set to 'false'.
_dataCollectionProfile = new AzurePSDataCollectionProfile(true);
}
else if (string.Equals(value, bool.TrueString, StringComparison.OrdinalIgnoreCase))
{
// Enable data collection only if it is explictly set to 'true'.
// Enable data collection only if it is explicitly set to 'true'.
_dataCollectionProfile = new AzurePSDataCollectionProfile(false);
}
}
Expand Down
119 changes: 67 additions & 52 deletions tools/AzureRM/AzureRM.psm1
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
$AzureMajorVersion = "1"

$AzureRMModules = @(
"AzureRM.ApiManagement",
"AzureRM.Automation",
"AzureRM.Backup",
"AzureRM.Batch",
"AzureRM.Compute",
"AzureRM.DataFactories",
"AzureRM.DataLakeAnalytics",
"AzureRM.DataLakeStore",
"AzureRM.Dns",
"AzureRM.HDInsight",
"AzureRM.Insights",
"AzureRM.KeyVault",
"AzureRM.Network",
"AzureRM.NotificationHubs",
"AzureRM.OperationalInsights",
"AzureRM.RecoveryServices",
"AzureRM.RedisCache",
"AzureRM.Resources",
"AzureRM.SiteRecovery",
"AzureRM.Sql",
"AzureRM.Storage",
"AzureRM.StreamAnalytics",
"AzureRM.Tags",
"AzureRM.TrafficManager",
"AzureRM.UsageAggregates",
"AzureRM.Websites"
)
$AzureRMDependencies = @{
"Azure.Storage" = "1.0.3";
"AzureRM.Profile" = "1.0.3";
}

$AzureRMModules = @{
"AzureRM.ApiManagement" = "1.0.3";
"AzureRM.Automation" = "1.0.3";
"AzureRM.Backup" = "1.0.3";
"AzureRM.Batch" = "1.0.3";
"AzureRM.Compute" = "1.2.1";
"AzureRM.DataFactories" = "1.0.3";
"AzureRM.DataLakeAnalytics" = "1.0.3";
"AzureRM.DataLakeStore" = "1.0.3";
"AzureRM.Dns" = "1.0.3";
"AzureRM.HDInsight" = "1.0.4";
"AzureRM.Insights" = "1.0.3";
"AzureRM.KeyVault" = "1.1.2";
"AzureRM.Network" = "1.0.3";
"AzureRM.NotificationHubs" = "1.0.3";
"AzureRM.OperationalInsights" = "1.0.3";
"AzureRM.RecoveryServices" = "1.0.4";
"AzureRM.RedisCache" = "1.1.1";
"AzureRM.Resources" = "1.0.3";
"AzureRM.SiteRecovery" = "1.1.2";
"AzureRM.Sql" = "1.0.3";
"AzureRM.Storage" = "1.0.3";
"AzureRM.StreamAnalytics" = "1.0.3";
"AzureRM.Tags" = "1.0.3";
"AzureRM.TrafficManager" = "1.0.3";
"AzureRM.UsageAggregates" = "1.0.3";
"AzureRM.Websites" = "1.0.3";
}

function Test-AdminRights([string]$Scope)
{
Expand Down Expand Up @@ -64,10 +67,10 @@ function CheckIncompatibleVersion([bool]$Force)
}
}

function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[string]$Repository,[string]$Scope,[switch]$Force)
function Install-ModuleWithVersionCheck([string]$Name,[string]$MinimumVersion,[string]$Repository,[string]$Scope,[switch]$Force)
{
$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"
$_MinVer = $MinimumVersion
$_MaxVer = "$($_MinVer.Split(".")[0]).9999.9999.9999"
$script:InstallCounter ++
try {
$_ExistingModule = Get-Module -ListAvailable -Name $Name
Expand All @@ -82,7 +85,7 @@ function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[str
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Stop
}
$v = (Get-InstalledModule -Name $Name -ErrorAction Ignore)[0].Version.ToString()
Write-Output "$Name $v $_ModuleAction [$script:InstallCounter/$($AzureRMModules.Count + 2)]..."
Write-Output "$Name $v $_ModuleAction [$script:InstallCounter/$($AzureRMModules.Count + $AzureRMDependencies.Count)]..."
} catch {
Write-Warning "Skipping $Name package..."
Write-Warning $_
Expand Down Expand Up @@ -114,7 +117,7 @@ function Update-AzureRM
param(
[Parameter(Position=0, Mandatory = $false)]
[string]
$MajorVersion = $AzureMajorVersion,
$MajorVersion,
[Parameter(Position=1, Mandatory = $false)]
[string]
$Repository = "PSGallery",
Expand All @@ -137,12 +140,17 @@ function Update-AzureRM
{
Set-PSRepository -Name $Repository -InstallationPolicy Trusted

Install-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion $Repository $Scope -Force:$force
Install-ModuleWithVersionCheck "Azure.Storage" $MajorVersion $Repository $Scope -Force:$force
# Update Profile and Storage
Install-ModuleWithVersionCheck "AzureRM.Profile" $AzureRMDependencies["AzureRM.Profile"] $Repository $Scope -Force:$force
Install-ModuleWithVersionCheck "Azure.Storage" $AzureRMDependencies["Azure.Storage"] $Repository $Scope -Force:$force

# Start new job
$AzureRMModules | ForEach {
Install-ModuleWithVersionCheck $_ $MajorVersion $Repository $Scope -Force:$force
$AzureRMModules.Keys | ForEach {
$_MinVer = $MajorVersion
if(!$MajorVersion) {
$_MinVer = $AzureRMModules[$_]
}
Install-ModuleWithVersionCheck $_ $_MinVer $Repository $Scope -Force:$force
}
} finally {
# Clean up
Expand All @@ -165,14 +173,17 @@ function Import-AzureRM
param(
[Parameter(Position=0, Mandatory = $false)]
[string]
$MajorVersion = $AzureMajorVersion)
$MajorVersion )
Write-Output "Importing AzureRM modules."

$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"

$AzureRMModules | ForEach {
$AzureRMModules.Keys | ForEach {
$moduleName = $_
$_MinVer = $MajorVersion
if(!MajorVersion ) {
$_MinVer = $AzureRMModules[$_]
}
$_MaxVer = "$($_MinVer.Split(".")[0]).9999.9999.9999"

$_MatchedModule = Get-InstalledModule -Name $moduleName -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $moduleName}
if ($_MatchedModule -ne $null) {
try {
Expand All @@ -186,10 +197,10 @@ function Import-AzureRM
}
}

function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion)
function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MinVersion)
{
$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"
$_MinVer = $MinVersion
$_MaxVer = "$($_MinVer.Split(".")[0]).9999.9999.9999"
# This is a workaround for a bug in PowerShellGet that uses "start with" matching for module name
$_MatchedModule = Get-InstalledModule -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
if ($_MatchedModule -ne $null) {
Expand Down Expand Up @@ -226,19 +237,23 @@ function Uninstall-AzureRM
param(
[Parameter(Position=0, Mandatory = $false)]
[string]
$MajorVersion = $AzureMajorVersion)
$MinVersion)

Test-AdminRights "AllUsers"

Write-Output "Uninstalling AzureRM modules."

$AzureRMModules | ForEach {
$AzureRMModules.Keys | ForEach {
$moduleName = $_
Uninstall-ModuleWithVersionCheck $_ $MajorVersion
$_MinVer = $MinVersion
if(!$MinVersion) {
$_MinVer = $AzureRMModules[$_]
}
Uninstall-ModuleWithVersionCheck $_ $_MinVer
}

Uninstall-ModuleWithVersionCheck "Azure.Storage" $MajorVersion
Uninstall-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion
Uninstall-ModuleWithVersionCheck "Azure.Storage" $AzureRMDependencies["Azure.Storage"]
Uninstall-ModuleWithVersionCheck "AzureRM.Profile" $AzureRMDependencies["AzureRM.Profile"]
}

New-Alias -Name Install-AzureRM -Value Update-AzureRM
Expand Down
84 changes: 24 additions & 60 deletions tools/AzureRM/AzureRM.psm1-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<!--Generated by PS Cmdlet Help Editor-->
<command:details>
<command:name>Import-ModuleWithVersionCheck</command:name>
<command:name>Install-ModuleWithVersionCheck</command:name>
<maml:description>
<maml:para />
</maml:description>
<maml:copyright>
<maml:para />
</maml:copyright>
<command:verb>Import</command:verb>
<command:verb>Install</command:verb>
<command:noun>ModuleWithVersionCheck</command:noun>
<dev:version />
</command:details>
Expand All @@ -18,7 +18,7 @@
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>Import-ModuleWithVersionCheck</maml:name>
<maml:name>Install-ModuleWithVersionCheck</maml:name>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="0">
<maml:name>Name</maml:name>
<maml:description>
Expand Down Expand Up @@ -107,7 +107,7 @@
<maml:description/>
</dev:type>
<maml:description>
<maml:para />
<maml:para />
</maml:description>
</command:inputType>
</command:inputTypes>
Expand All @@ -119,7 +119,7 @@
<maml:description/>
</dev:type>
<maml:description>
<maml:para />
<maml:para />
</maml:description>
</command:returnValue>
</command:returnValues>
Expand Down Expand Up @@ -181,31 +181,7 @@
</command:syntax>
<command:parameters>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="0">
<maml:name>Repository</maml:name>
<maml:description>
<maml:para />
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>InformationAction</maml:name>
<maml:description>
<maml:para />
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>InformationVariable</maml:name>
<maml:name>MinVersion</maml:name>
<maml:description>
<maml:para />
</maml:description>
Expand All @@ -225,7 +201,7 @@
<maml:description/>
</dev:type>
<maml:description>
<maml:para />
<maml:para />
</maml:description>
</command:inputType>
</command:inputTypes>
Expand All @@ -237,7 +213,7 @@
<maml:description/>
</dev:type>
<maml:description>
<maml:para />
<maml:para />
</maml:description>
</command:returnValue>
</command:returnValues>
Expand Down Expand Up @@ -305,7 +281,19 @@
</command:syntaxItem>
</command:syntax>
<command:parameters>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="0">
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="0">
<maml:name>MajorVersion</maml:name>
<maml:description>
<maml:para>Minimum major version for the update.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1">
<maml:name>Repository</maml:name>
<maml:description>
<maml:para>Limit the search for &quot;AzureRM&quot; cmdlets in a specific repository.</maml:para>
Expand All @@ -317,7 +305,7 @@
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1">
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2">
<maml:name>Scope</maml:name>
<maml:description>
<maml:para>Specifies the parameter scope.</maml:para>
Expand All @@ -329,30 +317,6 @@
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>InformationAction</maml:name>
<maml:description>
<maml:para />
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>InformationVariable</maml:name>
<maml:description>
<maml:para />
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
Expand Down Expand Up @@ -394,14 +358,14 @@
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<!--Generated by PS Cmdlet Help Editor-->
<command:details>
<command:name>Validate-AdminRights</command:name>
<command:name>Test-AdminRights</command:name>
<maml:description>
<maml:para>Validate this session is running as Administrator</maml:para>
</maml:description>
<maml:copyright>
<maml:para />
</maml:copyright>
<command:verb>Validate</command:verb>
<command:verb>Test</command:verb>
<command:noun>AdminRights</command:noun>
<dev:version />
</command:details>
Expand Down