Skip to content

Commit 6e8c3fa

Browse files
author
dragonfly91
committed
Moved RmClient to base cmdlet class
1 parent 63e1e26 commit 6e8c3fa

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Restore/RestoreAzureRMRecoveryServicesBackupItem.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ public override void ExecuteCmdlet()
5151
{
5252
base.ExecuteCmdlet();
5353
StorageAccountName = StorageAccountName.ToLower();
54-
WriteDebug("InsideRestore. going to create ResourceManager Client");
55-
ResourcesNS.ResourceManagementClient rmClient = AzureSession.ClientFactory.CreateClient<ResourcesNS.ResourceManagementClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
56-
WriteDebug("Client Created successfully");
5754
ResourceIdentity identity = new ResourceIdentity();
5855
identity.ResourceName = StorageAccountName;
5956
identity.ResourceProviderNamespace = "Microsoft.ClassicStorage/storageAccounts";
@@ -64,13 +61,13 @@ public override void ExecuteCmdlet()
6461
try
6562
{
6663
WriteDebug(String.Format("Query Microsoft.ClassicStorage with name = {0}", StorageAccountName));
67-
resource = rmClient.Resources.GetAsync(StorageAccountResourceGroupName, identity, CancellationToken.None).Result;
64+
resource = RmClient.Resources.GetAsync(StorageAccountResourceGroupName, identity, CancellationToken.None).Result;
6865
}
6966
catch (Exception)
7067
{
7168
identity.ResourceProviderNamespace = "Microsoft.Storage/storageAccounts";
7269
identity.ResourceProviderApiVersion = "2016-01-01";
73-
resource = rmClient.Resources.GetAsync(StorageAccountResourceGroupName, identity, CancellationToken.None).Result;
70+
resource = RmClient.Resources.GetAsync(StorageAccountResourceGroupName, identity, CancellationToken.None).Result;
7471
}
7572

7673
string storageAccountId = resource.Resource.Id;

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using Microsoft.Azure.Commands.Common.Authentication;
3333
using Microsoft.Azure.Commands.Common.Authentication.Models;
3434
using Microsoft.WindowsAzure.Commands.Utilities.Common;
35+
using ResourcesNS = Microsoft.Azure.Management.Resources;
3536

3637
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3738
{
@@ -45,10 +46,17 @@ public abstract class RecoveryServicesBackupCmdletBase : AzureRMCmdlet
4546

4647
protected ServiceClientAdapter ServiceClientAdapter { get; set; }
4748

49+
protected ResourcesNS.ResourceManagementClient RmClient { get; set; }
50+
4851
protected void InitializeAzureBackupCmdlet()
4952
{
5053
var cloudServicesClient = AzureSession.ClientFactory.CreateClient<CloudServiceManagementClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
5154
ServiceClientAdapter = new ServiceClientAdapter(cloudServicesClient.Credentials, cloudServicesClient.BaseUri);
55+
56+
WriteDebug("InsideRestore. going to create ResourceManager Client");
57+
RmClient = AzureSession.ClientFactory.CreateClient<ResourcesNS.ResourceManagementClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
58+
WriteDebug("Client Created successfully");
59+
5260
Logger.Instance = new Logger(WriteWarning, WriteDebug, WriteVerbose, ThrowTerminatingError);
5361
}
5462

0 commit comments

Comments
 (0)