Skip to content

Commit

Permalink
Merge pull request Azure#7 from romahamu/remakar
Browse files Browse the repository at this point in the history
Cmdlet - New-AzHpcCache/Get-AzHpcCache/Get-AzHpcCacheUsageModels/Get-AzHpcCacheSku/Remove-AzHpcCache
  • Loading branch information
rebecca-makar authored Feb 14, 2020
2 parents 1d30d2c + 2888c33 commit f2d4940
Show file tree
Hide file tree
Showing 20 changed files with 461 additions and 248 deletions.
6 changes: 3 additions & 3 deletions src/StorageCache/HPCCache/Az.HPCCache.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ NestedModules = @('Microsoft.Azure.PowerShell.Cmdlets.HPCCache.dll')
#FunctionsToExport = @('Test-GetSku')

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = 'Get-AzSku' , 'Get-AzUsageModels',
'Get-AzHPCCaches', 'New-AzHpcCache',
'Remove-AzHpcCache'
CmdletsToExport = 'Get-AzHpcCacheSku' , 'Get-AzHpcCacheUsageModels',
'Get-AzHpcCache', 'New-AzHpcCache',
'Remove-AzHpcCache', 'Update-AzHpcCache'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
// ----------------------------------------------------------------------------------
namespace Microsoft.Azure.Commands.HPCCache
{
using System;
using System.Management.Automation;
using System.Net;
using Microsoft.Azure.Common.Properties;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.Management.StorageCache.Models;
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models;
Expand All @@ -23,7 +25,7 @@ namespace Microsoft.Azure.Commands.HPCCache
/// <summary>
/// Get Cache / RG specific cache(s) / subscription wide caches.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HPCCaches")]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HpcCache")]
[OutputType(typeof(PSHPCCache))]
public class GetAzHPCCaches : HpcCacheBaseCmdlet
{
Expand All @@ -48,55 +50,26 @@ public override void ExecuteCmdlet()
{
if (!string.IsNullOrEmpty(this.CacheName))
{
// Get single cache directly by RP call
try
{
var singlecache = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName);
this.WriteObject(new PSHPCCache(singlecache));
}
catch (CloudException ce)
{
if (ce.Response.StatusCode == HttpStatusCode.NotFound)
{
// return object
}

throw;
}
}
var singleCache = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName);
var singleCacheIp = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName).MountAddresses;
this.WriteObject(new PSHPCCache(singleCache, singleCacheIp), true);

}
else
{
try
{
var resourgeGroupCaches = this.HpcCacheClient.Caches.ListByResourceGroup(this.ResourceGroupName);
this.WriteObject(resourgeGroupCaches);
}
catch (CloudException ce)
var resourgeGroupCaches = this.HpcCacheClient.Caches.ListByResourceGroup(this.ResourceGroupName);
foreach(var cache in resourgeGroupCaches.Value)
{
if (ce.Response.StatusCode == HttpStatusCode.NotFound)
{
// return object
}

throw;
this.WriteObject(new PSHPCCache(cache, cache.MountAddresses),true);
}
}
}
else
{
try
{
var allCaches = this.HpcCacheClient.Caches.List();
this.WriteObject(allCaches);
}
catch (CloudException ce)
var allCaches = this.HpcCacheClient.Caches.List();
foreach (var cache in allCaches.Value)
{
if (ce.Response.StatusCode == HttpStatusCode.NotFound)
{
// return object
}

throw;
this.WriteObject(new PSHPCCache(cache, cache.MountAddresses), true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@

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.
/// Get SKUs related to HPC Cache service.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Sku")]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HpcCacheSku")]
[OutputType(typeof(PSSku))]
public class GetAzSku : HpcCacheBaseCmdlet
{
/// <inheritdoc/>
public override void ExecuteCmdlet()
{
var skulist = this.HpcCacheClient.Skus.List();
this.WriteObject(new PSSku(skulist));
var resourceSkus = this.HpcCacheClient.Skus.List().Value;
foreach(var sku in resourceSkus)
{
WriteObject(new PSSku(sku));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,26 @@
// ----------------------------------------------------------------------------------
namespace Microsoft.Azure.Commands.HPCCache
{
using System;
using System.Management.Automation;
using System.Net;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models;
using Microsoft.Rest.Azure;

/// <summary>
/// Get UsageModels related to HPC Cache Storage Target.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "UsageModels")]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HpcCacheUsageModels")]
public class GetAzUsageModels : HpcCacheBaseCmdlet
{
/// <summary>
/// Returns Usage Models.
/// </summary>
public override void ExecuteCmdlet()
{
try
var usageModelList = this.HpcCacheClient.UsageModels.List().Value;
foreach (var usageModel in usageModelList)
{
var usagemodellist = this.HpcCacheClient.UsageModels.List();
this.WriteObject(usagemodellist);
WriteObject(new PSHpcCacheUsageModels(usageModel));
}
catch (CloudException ce)
{
if (ce.Response.StatusCode == HttpStatusCode.NotFound)
{
// return something
}

throw;
}
}
}
}
39 changes: 25 additions & 14 deletions src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
namespace Microsoft.Azure.Commands.HPCCache
{
using System;
using System.Collections;
using System.Management.Automation;
using System.Net;
using Microsoft.Azure.Common.Properties;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.Commands.HPCCache;
using Microsoft.Azure.Management.StorageCache.Models;
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models;
using Microsoft.Rest.Azure;
Expand Down Expand Up @@ -52,46 +55,54 @@ public class NewAzHpcCache : HpcCacheBaseCmdlet
/// <summary>
/// Gets or sets subnetUri.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "subnetURI.")]
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "SubnetURI.")]
[ValidateNotNullOrEmpty]
public string SubnetUri { get; set; }

/// <summary>
/// Gets or sets cache size.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "cachesize.")]
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "CacheSize.")]
[ValidateNotNullOrEmpty]
public int Cachesize { get; set; }
public int CacheSize { get; set; }

/// <summary>
/// Gets or sets location.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "location.")]
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Location.")]
[ValidateNotNullOrEmpty]
public string Location { get; set; }

/// <summary>
/// The tags to associate with HPC Cache.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "The tags to associate with HPC Cache.")]
public Hashtable Tag { get; set; }

/// <summary>
/// Execution cmdlet.
/// </summary>
public override void ExecuteCmdlet()
{
try
{
var cacheSku = new CacheSku() { Name = this.Sku };
var cacheParameters = new Cache() { CacheSizeGB = this.Cachesize, Location = this.Location, Sku = cacheSku, Subnet = this.SubnetUri };

var cache = this.HpcCacheClient.Caches.CreateOrUpdate(this.ResourceGroupName, this.CacheName, cacheParameters);
this.WriteObject(new PSHPCCache(cache));
var cacheExists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.CacheName);
throw new CloudException(string.Format("Cache name {0} already exists", this.CacheName));
}
catch (CloudException ce)
catch (CloudErrorException ex)
{
if (ce.Response.StatusCode == HttpStatusCode.NotFound)
if (ex.Body.Error.Code != "ResourceNotFound")
{
// return obj
throw;
}

throw;
}
Utility.ValidateResourceGroup(ResourceGroupName);
var cacheSku = new CacheSku() { Name = this.Sku };
var Tag = this.Tag.ToDictionaryTags();
var cacheParameters = new Cache() { CacheSizeGB = this.CacheSize, Location = this.Location, Sku = cacheSku, Subnet = this.SubnetUri, Tags = Tag};
var cache = this.HpcCacheClient.Caches.CreateOrUpdate(this.ResourceGroupName, this.CacheName, cacheParameters);
this.WriteObject(new PSHPCCache(cache, cache.MountAddresses));

}
}
}
40 changes: 26 additions & 14 deletions src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Microsoft.Azure.Commands.HPCCache
using System;
using System.Management.Automation;
using System.Net;
using Hyak.Common.Properties;
using Microsoft.Azure.Management.StorageCache;
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models;
using Microsoft.Rest.Azure;
Expand All @@ -24,7 +25,7 @@ namespace Microsoft.Azure.Commands.HPCCache
/// Remove HPC Cache.
/// </summary>
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HpcCache")]
[OutputType(typeof(PSHPCCache))]
[OutputType(typeof(bool))]
public class RemoveAzHpcCache : HpcCacheBaseCmdlet
{
/// <summary>
Expand All @@ -41,25 +42,36 @@ public class RemoveAzHpcCache : HpcCacheBaseCmdlet
[ValidateNotNullOrEmpty]
public string CacheName { get; set; }

/// <summary>
/// Delete Force - always set to false.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "Indicates that the cmdlet does not prompt you for confirmation. By default, this cmdlet prompts you to confirm that you want to delete the cache.")]
public SwitchParameter Force { get; set; }

/// <summary>
/// Switch parameter if you do not want to wait till success.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "This Cmdlet does not return an object by default. If this switch is specified, it returns true if successful.")]
public SwitchParameter PassThru { get; set; }

/// <summary>
/// Execution Cmdlet.
/// </summary>
public override void ExecuteCmdlet()
{
try
{
var deletecache = this.HpcCacheClient.Caches.Delete(this.ResourceGroupName, this.CacheName);
this.WriteObject(deletecache);
}
catch (CloudException ce)
{
if (ce.Response.StatusCode == HttpStatusCode.NotFound)
ConfirmAction(
Force.IsPresent,
string.Format("Deleting cache."),
string.Format("Cache is deleted."),
CacheName,
() =>
{
// return object
}

throw;
}
this.HpcCacheClient.Caches.Delete(this.ResourceGroupName, this.CacheName);
if (PassThru)
{
WriteObject(true);
}
});
}
}
}
Loading

0 comments on commit f2d4940

Please sign in to comment.