Skip to content

Commit 13d9dda

Browse files
committed
Use V2 Storage accounts for RM based Diagnostics Extenstion
1 parent 74dafb4 commit 13d9dda

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/Diagnostics/SetAzureVMDiagnosticsExtension.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
using Microsoft.Azure.Management.Compute.Models;
2222
using Microsoft.WindowsAzure.Commands.Common.Storage;
2323
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24-
using Microsoft.WindowsAzure.Management.Storage;
24+
using Microsoft.Azure.Commands.Management.Storage;
25+
using Microsoft.Azure.Management.Storage;
2526
using Newtonsoft.Json;
2627

2728
namespace Microsoft.Azure.Commands.Compute
@@ -37,7 +38,7 @@ public class SetAzureVMDiagnosticsExtensionCommand : VirtualMachineExtensionBase
3738
private const string VirtualMachineExtension = "Microsoft.Compute/virtualMachines/extensions";
3839
private const string IaaSDiagnosticsExtension = "IaaSDiagnostics";
3940
private const string ExtensionPublisher = "Microsoft.Azure.Diagnostics";
40-
private StorageManagementClient storageClient;
41+
private IStorageManagementClient storageClient;
4142

4243
[Parameter(
4344
Mandatory = true,
@@ -154,14 +155,14 @@ public string PrivateConfiguration
154155
}
155156
}
156157

157-
public StorageManagementClient StorageClient
158+
public IStorageManagementClient StorageClient
158159
{
159160
get
160161
{
161162
if (this.storageClient == null)
162163
{
163164
this.storageClient = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(
164-
DefaultProfile.Context, AzureEnvironment.Endpoint.ServiceManagement);
165+
DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);
165166
}
166167

167168
return this.storageClient;
@@ -201,14 +202,12 @@ protected string GetStorageKey()
201202

202203
if (!string.IsNullOrEmpty(StorageAccountName))
203204
{
204-
var storageAccount = this.StorageClient.StorageAccounts.Get(StorageAccountName);
205-
if (storageAccount != null)
205+
var storageAccountKeys =
206+
this.StorageClient.StorageAccounts.ListKeys(this.ResourceGroupName,
207+
this.StorageContext.StorageAccountName);
208+
if (storageAccountKeys != null)
206209
{
207-
var keys = this.StorageClient.StorageAccounts.GetKeys(StorageAccountName);
208-
if (keys != null)
209-
{
210-
storageKey = !string.IsNullOrEmpty(keys.PrimaryKey) ? keys.PrimaryKey : keys.SecondaryKey;
211-
}
210+
storageKey = !string.IsNullOrEmpty(storageAccountKeys.StorageAccountKeys.Key1) ? storageAccountKeys.StorageAccountKeys.Key1 : storageAccountKeys.StorageAccountKeys.Key2;
212211
}
213212
}
214213

0 commit comments

Comments
 (0)