Skip to content

Commit

Permalink
Add CacheName and StorageTargetName alias. (Azure#50)
Browse files Browse the repository at this point in the history
* Update Alias in help

* Add CacheName alias and help text for parameters.

* Add StorageTargetName alias.

* Formatting changes.

* Add description to psd

* Remove whitespaces.
  • Loading branch information
romahamu authored Mar 30, 2020
1 parent fd620c0 commit cdd1022
Show file tree
Hide file tree
Showing 27 changed files with 194 additions and 144 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 @@ -30,7 +30,7 @@ CompanyName = 'Microsoft Corporation'
Copyright = 'Microsoft Corporation. All rights reserved.'

# Description of the functionality provided by this module
Description = ''
Description = 'Microsoft Azure PowerShell - Azure HPC Cache service cmdlets for Azure Resource Manager in Windows PowerShell and PowerShell Core.'

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '5.1'
Expand Down Expand Up @@ -63,13 +63,13 @@ RequiredAssemblies = 'Microsoft.Azure.Management.StorageCache.dll'
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
#FormatsToProcess = 'HPCCache.format.ps1xml'
#FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @('Microsoft.Azure.PowerShell.Cmdlets.HPCCache.dll')

# Functions 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 functions to export.
#FunctionsToExport = @('Test-GetSku')
#FunctionsToExport = @()

# 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-AzHpcCacheSku' , 'Get-AzHpcCacheUsageModels',
Expand Down
28 changes: 17 additions & 11 deletions src/StorageCache/HPCCache/Commands/FlushAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace Microsoft.Azure.Commands.HPCCache
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models;
using Microsoft.Rest.Azure;


/// <summary>
/// Flush HPC Cache.
/// </summary>
Expand All @@ -42,15 +41,22 @@ public class FlushAzHpcCache : HpcCacheBaseCmdlet
/// Gets or sets Name.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.", ParameterSetName = FieldsParameterSet)]
[Alias(CacheNameAlias)]
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]

public string Name { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource id of the Cache", ParameterSetName = ResourceIdParameterSet)]

/// <summary>
/// Gets or sets resource id of the cache.
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource id of the Cache", ParameterSetName = ResourceIdParameterSet)]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(ParameterSetName = ObjectParameterSet, Mandatory = true,ValueFromPipeline = true, HelpMessage = "The cache object to flush.")]
/// <summary>
/// Gets or sets cache object.
/// </summary>
[Parameter(ParameterSetName = ObjectParameterSet, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The cache object to flush.")]
[ValidateNotNullOrEmpty]
public PSHPCCache InputObject { get; set; }

Expand All @@ -71,16 +77,16 @@ public class FlushAzHpcCache : HpcCacheBaseCmdlet
/// </summary>
public override void ExecuteCmdlet()
{
if (ParameterSetName == ResourceIdParameterSet)
if (this.ParameterSetName == ResourceIdParameterSet)
{
var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
ResourceGroupName = resourceIdentifier.ResourceGroupName;
Name = resourceIdentifier.ResourceName;
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.Name = resourceIdentifier.ResourceName;
}
else if (ParameterSetName == ObjectParameterSet)
else if (this.ParameterSetName == ObjectParameterSet)
{
ResourceGroupName = InputObject.ResourceGroupName;
Name = InputObject.CacheName;
this.ResourceGroupName = this.InputObject.ResourceGroupName;
this.Name = this.InputObject.CacheName;
}

this.ConfirmAction(
Expand Down
2 changes: 1 addition & 1 deletion src/StorageCache/HPCCache/Commands/GetAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class GetAzHpcCache : HpcCacheBaseCmdlet
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "Name of specific cache.")]
[Alias(CacheNameAlias)]
[ValidateNotNullOrEmpty]
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion src/StorageCache/HPCCache/Commands/GetAzHpcCacheSku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.HPCCache
using Microsoft.Azure.PowerShell.Cmdlets.HPCCache.Models;

/// <summary>
/// Get SKUs related to HPC Cache that are available in subscription
/// Get SKUs related to HPC Cache that are available in subscription.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "HpcCacheSku")]
[OutputType(typeof(PSSku))]
Expand Down
10 changes: 8 additions & 2 deletions src/StorageCache/HPCCache/Commands/GetAzHpcCacheStorageTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ public class GetAzHpcCacheStorageTarget : HpcCacheBaseCmdlet
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
public string CacheName { get; set; }

/// <summary>
/// Gets or sets resource id of the cache.
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource id of the Cache", ParameterSetName = ResourceIdParameterSet)]
[ValidateNotNullOrEmpty]
public string CacheId { get; set; }

/// <summary>
/// Gets or sets cache object.
/// </summary>
[Parameter(ParameterSetName = ObjectParameterSet, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The cache object to start.")]
[ValidateNotNullOrEmpty]
public PSHPCCache CacheObject { get; set; }
Expand All @@ -64,13 +70,13 @@ public class GetAzHpcCacheStorageTarget : HpcCacheBaseCmdlet
/// <inheritdoc/>
public override void ExecuteCmdlet()
{
if (ParameterSetName == ResourceIdParameterSet)
if (this.ParameterSetName == ResourceIdParameterSet)
{
var resourceIdentifier = new ResourceIdentifier(this.CacheId);
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.CacheName = resourceIdentifier.ResourceName;
}
else if (ParameterSetName == ObjectParameterSet)
else if (this.ParameterSetName == ObjectParameterSet)
{
this.ResourceGroupName = this.CacheObject.ResourceGroupName;
this.CacheName = this.CacheObject.CacheName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public override void ExecuteCmdlet()
{
this.WriteObject(new PSHpcCacheUsageModels(usageModel));
}
}
}
}
}
1 change: 1 addition & 0 deletions src/StorageCache/HPCCache/Commands/NewAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class NewAzHpcCache : HpcCacheBaseCmdlet
/// Gets or sets cache name.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.")]
[Alias(CacheNameAlias)]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

Expand Down
20 changes: 11 additions & 9 deletions src/StorageCache/HPCCache/Commands/NewAzHpcStorageTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ public class NewAzHpcStorageTarget : HpcCacheBaseCmdlet
/// Gets or sets resource CacheName.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.")]
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string CacheName { get; set; }

/// <summary>
/// Gets or sets resource storage target name.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of storage target.")]
[Alias(StoragTargetNameAlias)]
[ValidateNotNullOrEmpty]
public string StorageTargetName { get; set; }
public string Name { get; set; }

/// <summary>
/// Gets or sets CLFS storage target.
Expand Down Expand Up @@ -134,12 +136,12 @@ public override void ExecuteCmdlet()

private PSHpcStorageTarget CreateStorageTargetModel()
{
return new PSHpcStorageTarget(
this.HpcCacheClient.StorageTargets.CreateOrUpdate(
this.ResourceGroupName,
this.CacheName,
this.StorageTargetName,
this.storageTarget));
return new PSHpcStorageTarget(
this.HpcCacheClient.StorageTargets.CreateOrUpdate(
this.ResourceGroupName,
this.CacheName,
this.Name,
this.storageTarget));
}

private bool DoesStorageTargetExists()
Expand All @@ -149,9 +151,9 @@ private bool DoesStorageTargetExists()
var resource = this.HpcCacheClient.StorageTargets.Get(
this.ResourceGroupName,
this.CacheName,
this.StorageTargetName);
this.Name);

throw new Exception(string.Format(Resources.UpgradeHpcCache, this.StorageTargetName, this.CacheName));
throw new Exception(string.Format(Resources.UpgradeHpcCache, this.Name, this.CacheName));
}
catch (CloudErrorException e)
{
Expand Down
12 changes: 7 additions & 5 deletions src/StorageCache/HPCCache/Commands/RemoveAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public class RemoveAzHpcCache : HpcCacheBaseCmdlet
/// Gets or sets CacheName.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.")]
[Alias(CacheNameAlias)]
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string CacheName { get; set; }
public string Name { get; set; }

/// <summary>
/// Gets or sets Delete Force - always set to false.
Expand All @@ -68,14 +70,14 @@ public override void ExecuteCmdlet()
{
this.ConfirmAction(
this.Force.IsPresent,
string.Format(Resources.ConfirmDeleteHpcCache, this.CacheName),
string.Format(Resources.DeleteHpcCache, this.CacheName),
this.CacheName,
string.Format(Resources.ConfirmDeleteHpcCache, this.Name),
string.Format(Resources.DeleteHpcCache, this.Name),
this.Name,
() =>
{
try
{
this.HpcCacheClient.Caches.Delete(this.ResourceGroupName, this.CacheName);
this.HpcCacheClient.Caches.Delete(this.ResourceGroupName, this.Name);
if (this.PassThru)
{
this.WriteObject(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ public class RemoveAzHpcCacheStorageTarget : HpcCacheBaseCmdlet
/// Gets or sets CacheName.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.")]
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string CacheName { get; set; }

/// <summary>
/// Gets or sets StorageTargetName.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of storage target.")]
[Alias(StoragTargetNameAlias)]
[ValidateNotNullOrEmpty]
public string StorageTargetName { get; set; }
public string Name { get; set; }

/// <summary>
/// Gets or sets Delete Force - always set to false.
Expand All @@ -75,14 +77,14 @@ public override void ExecuteCmdlet()
{
this.ConfirmAction(
this.Force.IsPresent,
string.Format(Resources.ConfirmDeleteHpcCacheStorageTarget, this.StorageTargetName),
string.Format(Resources.DeleteHpcCacheStorageTarget, this.StorageTargetName),
string.Format(Resources.ConfirmDeleteHpcCacheStorageTarget, this.Name),
string.Format(Resources.DeleteHpcCacheStorageTarget, this.Name),
this.CacheName,
() =>
{
try
{
this.HpcCacheClient.StorageTargets.Delete(this.ResourceGroupName, this.CacheName, this.StorageTargetName);
this.HpcCacheClient.StorageTargets.Delete(this.ResourceGroupName, this.CacheName, this.Name);
if (this.PassThru)
{
this.WriteObject(true);
Expand Down
17 changes: 11 additions & 6 deletions src/StorageCache/HPCCache/Commands/SetAzHpcCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public class SetAzHpcCache : HpcCacheBaseCmdlet
/// Gets or sets resource CacheName.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.", ParameterSetName = FieldsParameterSet)]
[Alias(CacheNameAlias)]
[ValidateNotNullOrEmpty]
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
public string Name { get; set; }

/// <summary>
Expand All @@ -52,6 +54,9 @@ public class SetAzHpcCache : HpcCacheBaseCmdlet
[Parameter(Mandatory = false, HelpMessage = "The tags to associate with HPC Cache.", ParameterSetName = FieldsParameterSet)]
public Hashtable Tag { get; set; }

/// <summary>
/// Gets or sets cache object.
/// </summary>
[Parameter(ParameterSetName = ObjectParameterSet, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The cache object to update.")]
[ValidateNotNullOrEmpty]
public PSHPCCache InputObject { get; set; }
Expand All @@ -69,21 +74,21 @@ public override void ExecuteCmdlet()
{
IDictionary<string, string> tagPairs = null;

if (Tag != null)
if (this.Tag != null)
{
tagPairs = this.Tag.ToDictionaryTags();
}

if (ParameterSetName == ObjectParameterSet)
if (this.ParameterSetName == ObjectParameterSet)
{
ResourceGroupName = InputObject.ResourceGroupName;
Name = InputObject.CacheName;
var tags = InputObject.Tags;
this.ResourceGroupName = this.InputObject.ResourceGroupName;
this.Name = this.InputObject.CacheName;
var tags = this.InputObject.Tags;
var json = JsonConvert.SerializeObject(tags);
var dictionaryOfTags = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
tagPairs = dictionaryOfTags;

}

if (this.ShouldProcess(this.Name, string.Format(Resources.SetCache, this.Name, this.ResourceGroupName)))
{
try
Expand Down
12 changes: 7 additions & 5 deletions src/StorageCache/HPCCache/Commands/SetAzHpcStorageTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ public class SetAzHpcStorageTarget : HpcCacheBaseCmdlet
/// Gets or sets resource CacheName.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of cache.")]
[ResourceNameCompleter("Microsoft.StorageCache/caches", nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string CacheName { get; set; }

/// <summary>
/// Gets or sets resource storage target name.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Name of storage target.")]
[Alias(StoragTargetNameAlias)]
[ValidateNotNullOrEmpty]
public string StorageTargetName { get; set; }
public string Name { get; set; }

/// <summary>
/// Gets or sets CLFS storage target.
Expand Down Expand Up @@ -103,7 +105,7 @@ public override void ExecuteCmdlet()
throw new PSArgumentNullException("CacheName");
}

if (string.IsNullOrWhiteSpace(this.StorageTargetName))
if (string.IsNullOrWhiteSpace(this.Name))
{
throw new PSArgumentNullException("StorageTargetName");
}
Expand All @@ -112,7 +114,7 @@ public override void ExecuteCmdlet()

if (storageT == null)
{
throw new CloudException(string.Format("Storage target {0} does not exists.", this.StorageTargetName));
throw new CloudException(string.Format("Storage target {0} does not exists.", this.Name));
}

this.storageTarget = this.CLFS.IsPresent ? this.CreateClfsStorageTargetParameters(storageT) : this.CreateNfsStorageTargetParameters(storageT);
Expand Down Expand Up @@ -141,7 +143,7 @@ private PSHpcStorageTarget CreateStorageTargetModel()
StorageTarget storageTarget = this.HpcCacheClient.StorageTargets.CreateOrUpdate(
this.ResourceGroupName,
this.CacheName,
this.StorageTargetName,
this.Name,
this.storageTarget);
}
catch (CloudErrorException ex)
Expand Down Expand Up @@ -172,7 +174,7 @@ private StorageTarget DoesStorageTargetExists()
return this.HpcCacheClient.StorageTargets.Get(
this.ResourceGroupName,
this.CacheName,
this.StorageTargetName);
this.Name);
}

/// <summary>
Expand Down
Loading

0 comments on commit cdd1022

Please sign in to comment.