Skip to content

Commit 3d542f7

Browse files
committed
Merge pull request #336 from Azure/dev
.
2 parents 1edec5e + 1fc95aa commit 3d542f7

File tree

6 files changed

+188
-118
lines changed

6 files changed

+188
-118
lines changed

setup/azurecmd.wxs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
<RegistrySearch Id="PSCOMPATIBLEVERSION" Root="HKLM" Key="SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine" Name="PSCompatibleVersion" Type="raw" />
3232
</Property>
3333

34-
<SetProperty Action="SetBase64" Id="BaseModulesFolder" Value="[ProgramFiles64Folder]WindowsPowerShell\Modules" Before="AppSearch">
34+
<SetProperty Action="SetBase64" Id="BaseModulesFolder" Value="[ProgramFiles64Folder]WindowsPowerShell\Modules\" Before="AppSearch">
3535
VersionNT64
3636
</SetProperty>
3737

38-
<SetProperty Action="SetBase32" Id="BaseModulesFolder" Value="[ProgramFilesFolder]WindowsPowerShell\Modules" Before="AppSearch">
38+
<SetProperty Action="SetBase32" Id="BaseModulesFolder" Value="[ProgramFilesFolder]WindowsPowerShell\Modules\" Before="AppSearch">
3939
NOT VersionNT64
4040
</SetProperty>
4141

@@ -81,7 +81,7 @@
8181
<Component Id="PSModulePath.System" Guid="273525B9-7AAB-421A-90C8-8E50A1840B8D">
8282
<CreateFolder />
8383
<!-- Work around bug that PowerShell does not always consider default module paths. -->
84-
<Environment Id="PSModulePath.SystemAppRoot" Action="set" Name="PSMODULEPATH" Part="last" Value="[BaseModulesFolder];[PowerShellFolder]ResourceManager\AzureResourceManager;[PowerShellFolder]ServiceManagement" System="yes" />
84+
<Environment Id="PSModulePath.SystemAppRoot" Action="set" Name="PSMODULEPATH" Part="last" Value="[BaseModulesFolder];[PowerShellFolder]ResourceManager\AzureResourceManager\;[PowerShellFolder]ServiceManagement\" System="yes" />
8585
</Component>
8686
</DirectoryRef>
8787

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using System.Text;
2828
using System.Linq;
2929
using System.Threading;
30+
using Microsoft.Rest;
3031

3132
namespace Microsoft.WindowsAzure.Commands.Utilities.Common
3233
{
@@ -40,6 +41,9 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
4041
private RecordingTracingInterceptor _httpTracingInterceptor;
4142

4243
private DebugStreamTraceListener _adalListener;
44+
45+
private ServiceClientTracingInterceptor _serviceClientTracingInterceptor;
46+
4347
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null;
4448
protected static string _errorRecordFolderPath = null;
4549
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff";
@@ -95,12 +99,12 @@ protected static void InitializeDataCollectionProfile()
9599
{
96100
if (string.Equals(value, bool.FalseString, StringComparison.OrdinalIgnoreCase))
97101
{
98-
// Disable data collection only if it is explictly set to 'false'.
102+
// Disable data collection only if it is explicitly set to 'false'.
99103
_dataCollectionProfile = new AzurePSDataCollectionProfile(true);
100104
}
101105
else if (string.Equals(value, bool.TrueString, StringComparison.OrdinalIgnoreCase))
102106
{
103-
// Enable data collection only if it is explictly set to 'true'.
107+
// Enable data collection only if it is explicitly set to 'true'.
104108
_dataCollectionProfile = new AzurePSDataCollectionProfile(false);
105109
}
106110
}
@@ -216,8 +220,10 @@ protected override void BeginProcessing()
216220

217221
_httpTracingInterceptor = _httpTracingInterceptor ?? new RecordingTracingInterceptor(_debugMessages);
218222
_adalListener = _adalListener ?? new DebugStreamTraceListener(_debugMessages);
223+
_serviceClientTracingInterceptor = _serviceClientTracingInterceptor ?? new ServiceClientTracingInterceptor(_debugMessages);
219224
RecordingTracingInterceptor.AddToContext(_httpTracingInterceptor);
220225
DebugStreamTraceListener.AddAdalTracing(_adalListener);
226+
ServiceClientTracing.AddTracingInterceptor(_serviceClientTracingInterceptor);
221227

222228
ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue(
223229
ModuleName, string.Format("v{0}", ModuleVersion));
@@ -237,6 +243,7 @@ protected override void EndProcessing()
237243

238244
RecordingTracingInterceptor.RemoveFromContext(_httpTracingInterceptor);
239245
DebugStreamTraceListener.RemoveAdalTracing(_adalListener);
246+
ServiceClientTracingInterceptor.RemoveTracingInterceptor(_serviceClientTracingInterceptor);
240247
FlushDebugMessages();
241248

242249
AzureSession.ClientFactory.UserAgents.RemoveWhere(u => u.Product.Name == ModuleName);

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<Compile Include="ProfileClientExtensions.cs" />
171171
<Compile Include="ClientCreatedArgs.cs" />
172172
<Compile Include="CmdletExtensions.cs" />
173+
<Compile Include="ServiceClientTracingInterceptor.cs" />
173174
<Compile Include="TestMockSupport.cs" />
174175
<Compile Include="PSAzureAccount.cs" />
175176
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Rest;
16+
using System;
17+
using System.Collections.Concurrent;
18+
using System.Collections.Generic;
19+
using System.Diagnostics;
20+
using System.Linq;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
24+
namespace Microsoft.WindowsAzure.Commands.Common
25+
{
26+
class ServiceClientTracingInterceptor : IServiceClientTracingInterceptor
27+
{
28+
public ServiceClientTracingInterceptor(ConcurrentQueue<string> queue)
29+
{
30+
MessageQueue = queue;
31+
}
32+
33+
public ConcurrentQueue<string> MessageQueue { get; private set; }
34+
35+
public void Configuration(string source, string name, string value)
36+
{
37+
// Ignore
38+
}
39+
40+
public void EnterMethod(string invocationId, object instance, string method, IDictionary<string, object> parameters)
41+
{
42+
// Ignore
43+
}
44+
45+
public void ExitMethod(string invocationId, object returnValue)
46+
{
47+
// Ignore
48+
}
49+
50+
public void Information(string message)
51+
{
52+
MessageQueue.Enqueue(message);
53+
}
54+
55+
public void ReceiveResponse(string invocationId, System.Net.Http.HttpResponseMessage response)
56+
{
57+
string responseAsString = response == null ? string.Empty : response.AsFormattedString();
58+
MessageQueue.Enqueue(responseAsString);
59+
}
60+
61+
public void SendRequest(string invocationId, System.Net.Http.HttpRequestMessage request)
62+
{
63+
string requestAsString = request == null ? string.Empty : request.AsFormattedString();
64+
MessageQueue.Enqueue(requestAsString);
65+
}
66+
67+
public void TraceError(string invocationId, Exception exception)
68+
{
69+
// Ignore
70+
}
71+
72+
public static void RemoveTracingInterceptor(ServiceClientTracingInterceptor interceptor)
73+
{
74+
if (interceptor != null)
75+
{
76+
ServiceClientTracing.RemoveTracingInterceptor(interceptor);
77+
}
78+
}
79+
}
80+
}

tools/AzureRM/AzureRM.psm1

Lines changed: 71 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
$AzureMajorVersion = "1"
2-
3-
$AzureRMModules = @(
4-
"AzureRM.ApiManagement",
5-
"AzureRM.Automation",
6-
"AzureRM.Backup",
7-
"AzureRM.Batch",
8-
"AzureRM.Compute",
9-
"AzureRM.DataFactories",
10-
"AzureRM.DataLakeAnalytics",
11-
"AzureRM.DataLakeStore",
12-
"AzureRM.Dns",
13-
"AzureRM.HDInsight",
14-
"AzureRM.Insights",
15-
"AzureRM.KeyVault",
16-
"AzureRM.Network",
17-
"AzureRM.NotificationHubs",
18-
"AzureRM.OperationalInsights",
19-
"AzureRM.RecoveryServices",
20-
"AzureRM.RedisCache",
21-
"AzureRM.Resources",
22-
"AzureRM.SiteRecovery",
23-
"AzureRM.Sql",
24-
"AzureRM.Storage",
25-
"AzureRM.StreamAnalytics",
26-
"AzureRM.Tags",
27-
"AzureRM.TrafficManager",
28-
"AzureRM.UsageAggregates",
29-
"AzureRM.Websites"
30-
)
1+
$AzureRMDependencies = @{
2+
"Azure.Storage" = "1.0.3";
3+
"AzureRM.Profile" = "1.0.3";
4+
}
5+
6+
$AzureRMModules = @{
7+
"AzureRM.ApiManagement" = "1.0.3";
8+
"AzureRM.Automation" = "1.0.3";
9+
"AzureRM.Backup" = "1.0.3";
10+
"AzureRM.Batch" = "1.0.3";
11+
"AzureRM.Compute" = "1.2.1";
12+
"AzureRM.DataFactories" = "1.0.3";
13+
"AzureRM.DataLakeAnalytics" = "1.0.3";
14+
"AzureRM.DataLakeStore" = "1.0.3";
15+
"AzureRM.Dns" = "1.0.3";
16+
"AzureRM.HDInsight" = "1.0.4";
17+
"AzureRM.Insights" = "1.0.3";
18+
"AzureRM.KeyVault" = "1.1.2";
19+
"AzureRM.Network" = "1.0.3";
20+
"AzureRM.NotificationHubs" = "1.0.3";
21+
"AzureRM.OperationalInsights" = "1.0.3";
22+
"AzureRM.RecoveryServices" = "1.0.4";
23+
"AzureRM.RedisCache" = "1.1.1";
24+
"AzureRM.Resources" = "1.0.3";
25+
"AzureRM.SiteRecovery" = "1.1.2";
26+
"AzureRM.Sql" = "1.0.3";
27+
"AzureRM.Storage" = "1.0.3";
28+
"AzureRM.StreamAnalytics" = "1.0.3";
29+
"AzureRM.Tags" = "1.0.3";
30+
"AzureRM.TrafficManager" = "1.0.3";
31+
"AzureRM.UsageAggregates" = "1.0.3";
32+
"AzureRM.Websites" = "1.0.3";
33+
}
3134

3235
function Test-AdminRights([string]$Scope)
3336
{
@@ -64,25 +67,25 @@ function CheckIncompatibleVersion([bool]$Force)
6467
}
6568
}
6669

67-
function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[string]$Repository,[string]$Scope)
70+
function Install-ModuleWithVersionCheck([string]$Name,[string]$MinimumVersion,[string]$Repository,[string]$Scope,[switch]$Force)
6871
{
69-
$_MinVer = "$MajorVersion.0.0.0"
70-
$_MaxVer = "$MajorVersion.9999.9999.9999"
72+
$_MinVer = $MinimumVersion
73+
$_MaxVer = "$($_MinVer.Split(".")[0]).9999.9999.9999"
7174
$script:InstallCounter ++
7275
try {
7376
$_ExistingModule = Get-Module -ListAvailable -Name $Name
7477
$_ModuleAction = "installed"
7578
if ($_ExistingModule -ne $null)
7679
{
77-
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -Force -ErrorAction Stop
80+
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -Force:$force -ErrorAction Stop
7881
$_ModuleAction = "updated"
7982
}
8083
else
8184
{
8285
Install-Module -Name $Name -Repository $Repository -Scope $Scope -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Stop
8386
}
8487
$v = (Get-InstalledModule -Name $Name -ErrorAction Ignore)[0].Version.ToString()
85-
Write-Output "$Name $v $_ModuleAction [$script:InstallCounter/$($AzureRMModules.Count + 2)]..."
88+
Write-Output "$Name $v $_ModuleAction [$script:InstallCounter/$($AzureRMModules.Count + $AzureRMDependencies.Count)]..."
8689
} catch {
8790
Write-Warning "Skipping $Name package..."
8891
Write-Warning $_
@@ -104,14 +107,17 @@ function Install-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion,[str
104107
105108
.Parameter Scope
106109
Specifies the parameter scope.
110+
111+
.Parameter Force
112+
Force download and installation of modules already installed.
107113
#>
108114
function Update-AzureRM
109115
{
110116

111117
param(
112118
[Parameter(Position=0, Mandatory = $false)]
113119
[string]
114-
$MajorVersion = $AzureMajorVersion,
120+
$MajorVersion,
115121
[Parameter(Position=1, Mandatory = $false)]
116122
[string]
117123
$Repository = "PSGallery",
@@ -134,12 +140,17 @@ function Update-AzureRM
134140
{
135141
Set-PSRepository -Name $Repository -InstallationPolicy Trusted
136142

137-
Install-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion $Repository $Scope
138-
Install-ModuleWithVersionCheck "Azure.Storage" $MajorVersion $Repository $Scope
143+
# Update Profile and Storage
144+
Install-ModuleWithVersionCheck "AzureRM.Profile" $AzureRMDependencies["AzureRM.Profile"] $Repository $Scope -Force:$force
145+
Install-ModuleWithVersionCheck "Azure.Storage" $AzureRMDependencies["Azure.Storage"] $Repository $Scope -Force:$force
139146

140147
# Start new job
141-
$AzureRMModules | ForEach {
142-
Install-ModuleWithVersionCheck $_ $MajorVersion $Repository $Scope
148+
$AzureRMModules.Keys | ForEach {
149+
$_MinVer = $MajorVersion
150+
if(!$MajorVersion) {
151+
$_MinVer = $AzureRMModules[$_]
152+
}
153+
Install-ModuleWithVersionCheck $_ $_MinVer $Repository $Scope -Force:$force
143154
}
144155
} finally {
145156
# Clean up
@@ -162,14 +173,17 @@ function Import-AzureRM
162173
param(
163174
[Parameter(Position=0, Mandatory = $false)]
164175
[string]
165-
$MajorVersion = $AzureMajorVersion)
176+
$MajorVersion )
166177
Write-Output "Importing AzureRM modules."
167178

168-
$_MinVer = "$MajorVersion.0.0.0"
169-
$_MaxVer = "$MajorVersion.9999.9999.9999"
170-
171-
$AzureRMModules | ForEach {
179+
$AzureRMModules.Keys | ForEach {
172180
$moduleName = $_
181+
$_MinVer = $MajorVersion
182+
if(!MajorVersion ) {
183+
$_MinVer = $AzureRMModules[$_]
184+
}
185+
$_MaxVer = "$($_MinVer.Split(".")[0]).9999.9999.9999"
186+
173187
$_MatchedModule = Get-InstalledModule -Name $moduleName -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $moduleName}
174188
if ($_MatchedModule -ne $null) {
175189
try {
@@ -183,10 +197,10 @@ function Import-AzureRM
183197
}
184198
}
185199

186-
function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion)
200+
function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MinVersion)
187201
{
188-
$_MinVer = "$MajorVersion.0.0.0"
189-
$_MaxVer = "$MajorVersion.9999.9999.9999"
202+
$_MinVer = $MinVersion
203+
$_MaxVer = "$($_MinVer.Split(".")[0]).9999.9999.9999"
190204
# This is a workaround for a bug in PowerShellGet that uses "start with" matching for module name
191205
$_MatchedModule = Get-InstalledModule -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
192206
if ($_MatchedModule -ne $null) {
@@ -223,19 +237,23 @@ function Uninstall-AzureRM
223237
param(
224238
[Parameter(Position=0, Mandatory = $false)]
225239
[string]
226-
$MajorVersion = $AzureMajorVersion)
240+
$MinVersion)
227241

228242
Test-AdminRights "AllUsers"
229243

230244
Write-Output "Uninstalling AzureRM modules."
231245

232-
$AzureRMModules | ForEach {
246+
$AzureRMModules.Keys | ForEach {
233247
$moduleName = $_
234-
Uninstall-ModuleWithVersionCheck $_ $MajorVersion
248+
$_MinVer = $MinVersion
249+
if(!$MinVersion) {
250+
$_MinVer = $AzureRMModules[$_]
251+
}
252+
Uninstall-ModuleWithVersionCheck $_ $_MinVer
235253
}
236254

237-
Uninstall-ModuleWithVersionCheck "Azure.Storage" $MajorVersion
238-
Uninstall-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion
255+
Uninstall-ModuleWithVersionCheck "Azure.Storage" $AzureRMDependencies["Azure.Storage"]
256+
Uninstall-ModuleWithVersionCheck "AzureRM.Profile" $AzureRMDependencies["AzureRM.Profile"]
239257
}
240258

241259
New-Alias -Name Install-AzureRM -Value Update-AzureRM

0 commit comments

Comments
 (0)