Skip to content

Commit

Permalink
Create wrapper for SDK management client (Azure#5)
Browse files Browse the repository at this point in the history
* Fix GetAzSku wrt client changes.

* Restructure base cmdlet and mangement client class.
  • Loading branch information
romahamu authored Feb 6, 2020
1 parent ad42fb3 commit 5523095
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 95 deletions.
15 changes: 11 additions & 4 deletions src/StorageCache/HPCCache/Commands/GetAzSku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.HPCCache
{
using System;
using System.Management.Automation;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models;

/// <summary>
/// Get Azure SKU related to HPC Cache service.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Sku")]
public class GetAzSku : HpcCacheCmdletBase
public class GetAzSku : HpcCacheBaseCmdlet
{
/// <inheritdoc/>
public override void ExecuteCmdlet()
{
var skulist = CacheClient.GetSku();
WriteObject(skulist);
// var skulist = CacheClient.GetSku();
var skulist = this.HpcCacheClient.Skus.List();
this.WriteObject(skulist);
}
}
}
51 changes: 51 additions & 0 deletions src/StorageCache/HPCCache/Models/HpcCacheBaseCmdlet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models
{
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.Azure.Management.StorageCache;

/// <summary>
/// Base Cmdlet class for HPC cache cmdlets.
/// </summary>
public abstract class HpcCacheBaseCmdlet : AzureRMCmdlet
{
private HpcCacheManagementClientWrapper hpcCacheClientWrapper;

/// <summary>
/// Gets or Sets HPC Cache client.
/// </summary>
public IStorageCacheManagementClient HpcCacheClient
{
get
{
if (this.hpcCacheClientWrapper == null)
{
this.hpcCacheClientWrapper = new HpcCacheManagementClientWrapper(this.DefaultProfile.DefaultContext);
}

this.hpcCacheClientWrapper.VerboseLogger = this.WriteVerboseWithTimestamp;
this.hpcCacheClientWrapper.ErrorLogger = this.WriteErrorWithTimestamp;
this.hpcCacheClientWrapper.HpcCacheManagementClient.ApiVersion = "2019-11-01";
return this.hpcCacheClientWrapper.HpcCacheManagementClient;
}

set
{
this.hpcCacheClientWrapper = new HpcCacheManagementClientWrapper(value);
}
}
}
}
50 changes: 0 additions & 50 deletions src/StorageCache/HPCCache/Models/HpcCacheClient.cs

This file was deleted.

29 changes: 0 additions & 29 deletions src/StorageCache/HPCCache/Models/HpcCacheCmdletBase.cs

This file was deleted.

95 changes: 95 additions & 0 deletions src/StorageCache/HPCCache/Models/HpcCacheManagementClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models
{
using System;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Management.StorageCache;

/// <summary>
/// Hpc cache management client wrapper.
/// </summary>
public partial class HpcCacheManagementClientWrapper
{
/// <summary>
/// Initializes a new instance of the <see cref="HpcCacheManagementClientWrapper"/> class.
/// </summary>
/// <param name="context">Azure context.</param>
public HpcCacheManagementClientWrapper(IAzureContext context)
: this(AzureSession.Instance.ClientFactory.CreateArmClient<StorageCacheManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
{
}

/// <summary>
/// Initializes a new instance of the <see cref="HpcCacheManagementClientWrapper"/> class.
/// </summary>
/// <param name="resourceManagementClient">Resource management client.</param>
public HpcCacheManagementClientWrapper(IStorageCacheManagementClient resourceManagementClient)
{
this.HpcCacheManagementClient = resourceManagementClient;
}

/// <summary>
/// Gets or sets hpc Cache management client.
/// </summary>
public IStorageCacheManagementClient HpcCacheManagementClient { get; set; }

/// <summary>
/// Gets or sets verbose logging.
/// </summary>
public Action<string> VerboseLogger { get; set; }

/// <summary>
/// Gets or sets error logging.
/// </summary>
public Action<string> ErrorLogger { get; set; }

/// <summary>
/// Gets or sets warning Logger.
/// </summary>
public Action<string> WarningLogger { get; set; }

/// <summary>
/// Writes verbose.
/// </summary>
/// <param name="verboseFormat">Verbose format.</param>
/// <param name="args">Arguments to write verbose.</param>
private void WriteVerbose(string verboseFormat, params object[] args)
{
this.VerboseLogger?.Invoke(string.Format(verboseFormat, args));
}

/// <summary>
/// Write warning.
/// </summary>
/// <param name="warningFormat">Warning format.</param>
/// <param name="args">Arguments to write warning.</param>
private void WriteWarning(string warningFormat, params object[] args)
{
this.WarningLogger?.Invoke(string.Format(warningFormat, args));
}

/// <summary>
/// Write error.
/// </summary>
/// <param name="errorFormat">Error format.</param>
/// <param name="args">Arguments to write error.</param>
private void WriteError(string errorFormat, params object[] args)
{
this.ErrorLogger?.Invoke(string.Format(errorFormat, args));
}
}
}
12 changes: 0 additions & 12 deletions src/StorageCache/HPCCache/Models/PSSku.cs

This file was deleted.

0 comments on commit 5523095

Please sign in to comment.