Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public StorageFileTests(ITestOutputHelper output)
public void TestStorageFileShare()
{
TestController.NewInstance.RunPsTest(_logger, "Test-StorageFileShare");
}
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestStorageFileShareGetUsage()
{
TestController.NewInstance.RunPsTest(_logger, "Test-StorageFileShareGetUsage");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,47 @@ function Test-StorageFileShare
}
}

function Test-StorageFileShareGetUsage
{
# Setup
$rgname = Get-StorageManagementTestResourceName;

try
{
# Test
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
$loc = Get-ProviderLocation ResourceManagement;
$kind = 'StorageV2'
$shareName = "share"+ $rgname

Write-Verbose "RGName: $rgname | Loc: $loc"
New-AzResourceGroup -Name $rgname -Location $loc;

New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -Kind $kind
$stos = Get-AzStorageAccount -ResourceGroupName $rgname;

New-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName
Assert-AreEqual $rgname $share.ResourceGroupName
Assert-AreEqual $stoname $share.StorageAccountName
Assert-AreEqual $shareName $share.Name

# Get share usage
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName -GetShareUsage
Assert-AreEqual $shareName $share.Name
Assert-AreEqual 0 $share.ShareUsageBytes
Assert-AreEqual $null $share.Deleted


Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $stoname;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}



Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
- `New-AzStorageContainerSASToken`
* support create account Sas token with new permission x,t,f
- `New-AzStorageAccountSASToken`

* Support get single file share usage
- `Get-AzRmStorageShare`

## Version 2.3.0
* Fixed the issue that UserAgent is not added for some data plane cmdlets.
* Supported create/update Storage account with MinimumTlsVersion and AllowBlobPublicAccess
Expand Down
80 changes: 70 additions & 10 deletions src/Storage/Storage.Management/File/GetAzureStorageShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,45 @@
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using System;
using System.Collections.Generic;
using Microsoft.Rest.Azure;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Management.Storage
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMStoragePrefix + StorageShareNounStr, DefaultParameterSetName = AccountNameParameterSet), OutputType(typeof(PSShare))]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMStoragePrefix + StorageShareNounStr, DefaultParameterSetName = AccountNameSingleParameterSet), OutputType(typeof(PSShare))]
public class GetAzureStorageShareCommand : StorageFileBaseCmdlet
{
/// <summary>
/// AccountName Parameter Set
/// AccountName list Parameter Set
/// </summary>
private const string AccountNameParameterSet = "AccountName";

/// <summary>
/// Account object parameter set
/// Account object list parameter set
/// </summary>
private const string AccountObjectParameterSet = "AccountObject";

/// <summary>
/// AccountName Parameter Set
/// </summary>
private const string AccountNameSingleParameterSet = "AccountNameSingle";

/// <summary>
/// Account object parameter set
/// </summary>
private const string AccountObjectSingleParameterSet = "AccountObjectSingle";

/// <summary>
/// Share ResourceId parameter set
/// </summary>
private const string ShareResourceIdParameterSet = "ShareResourceId";

[Parameter(
Position = 0,
Mandatory = true,
HelpMessage = "Resource Group Name.",
ParameterSetName = AccountNameSingleParameterSet)]
[Parameter(
Position = 0,
Mandatory = true,
Expand All @@ -48,6 +63,11 @@ public class GetAzureStorageShareCommand : StorageFileBaseCmdlet
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(
Position = 1,
Mandatory = true,
HelpMessage = "Storage Account Name.",
ParameterSetName = AccountNameSingleParameterSet)]
[Parameter(
Position = 1,
Mandatory = true,
Expand All @@ -57,13 +77,18 @@ public class GetAzureStorageShareCommand : StorageFileBaseCmdlet
[ValidateNotNullOrEmpty]
public string StorageAccountName { get; set; }

[Parameter(Mandatory = true,
HelpMessage = "Storage account object",
ValueFromPipeline = true,
ParameterSetName = AccountObjectSingleParameterSet)]
[Parameter(Mandatory = true,
HelpMessage = "Storage account object",
ValueFromPipeline = true,
ParameterSetName = AccountObjectParameterSet)]
[ValidateNotNullOrEmpty]
public PSStorageAccount StorageAccount { get; set; }

[CmdletParameterBreakingChange("ResourceId", ChangeDescription = "Will not allow to input '-ResourceId', '-Name' together in a future release, since name info is already inclouded in ResourceId.")]
[Parameter(
Position = 0,
Mandatory = true,
Expand All @@ -75,44 +100,79 @@ public class GetAzureStorageShareCommand : StorageFileBaseCmdlet

[Alias("N", "ShareName")]
[Parameter(HelpMessage = "Share Name",
Mandatory = false)]
Mandatory = true,
ParameterSetName = AccountObjectSingleParameterSet)]
[Parameter(HelpMessage = "Share Name",
Mandatory = false,
ParameterSetName = AccountNameSingleParameterSet)]
[Parameter(HelpMessage = "Share Name",
Mandatory = false,
ParameterSetName = ShareResourceIdParameterSet)]
public string Name { get; set; }


[Parameter(HelpMessage = "Specify this parameter to get the Share Usage in Bytes.",
Mandatory = false,
ParameterSetName = AccountObjectSingleParameterSet)]
[Parameter(HelpMessage = "Specify this parameter to get the Share Usage in Bytes.",
Mandatory = false,
ParameterSetName = AccountNameSingleParameterSet)]
[Parameter(HelpMessage = "Specify this parameter to get the Share Usage in Bytes.",
Mandatory = false,
ParameterSetName = ShareResourceIdParameterSet)]
public SwitchParameter GetShareUsage { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

switch (ParameterSetName)
{
case AccountObjectSingleParameterSet:
case AccountObjectParameterSet:
this.ResourceGroupName = StorageAccount.ResourceGroupName;
this.StorageAccountName = StorageAccount.StorageAccountName;
break;
case ShareResourceIdParameterSet:
if (!string.IsNullOrEmpty(this.Name))
{
WriteWarning("The -Name parameter will be omit, as -ResourceId already contains share name.");
}
ResourceIdentifier shareResource = new ResourceIdentifier(ResourceId);
this.ResourceGroupName = shareResource.ResourceGroupName;
this.StorageAccountName = PSBlobServiceProperties.GetStorageAccountNameFromResourceId(ResourceId);
this.Name = shareResource.ResourceName;
break;
default:
// For AccountNameParameterSet, the ResourceGroupName and StorageAccountName can get from input directly
// For AccountNameParameterSet, AccountNameSingleParameterSet, the ResourceGroupName and StorageAccountName can get from input directly
break;
}

if (!string.IsNullOrEmpty(this.Name))
{
GetShareExpand? expend = null;
if(this.GetShareUsage)
{
expend = GetShareExpand.Stats;
}
var Share = this.StorageClient.FileShares.Get(
this.ResourceGroupName,
this.StorageAccountName,
this.Name);
this.Name,
expend);
WriteObject(new PSShare(Share));
}
else
{
var Shares = this.StorageClient.FileShares.List(
IPage<FileShareItem> shares = this.StorageClient.FileShares.List(
this.ResourceGroupName,
this.StorageAccountName);
WriteShareList(Shares);
WriteShareList(shares);
while (shares.NextPageLink != null)
{
shares = this.StorageClient.FileShares.ListNext(shares.NextPageLink);
WriteShareList(shares);
}
}
}
}
Expand Down
40 changes: 39 additions & 1 deletion src/Storage/Storage.Management/Models/PSShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public PSShare(StorageModels.FileShare share)
this.Etag = share.Etag;
this.LastModifiedTime = share.LastModifiedTime;
this.QuotaGiB = share.ShareQuota;
this.Version = share.Version;
this.Deleted = share.Deleted;
this.DeletedTime = share.DeletedTime;
this.RemainingRetentionDays = share.RemainingRetentionDays;
this.EnabledProtocols = share.EnabledProtocols;
this.RootSquash = share.RootSquash;
this.ShareUsageBytes = share.ShareUsageBytes;
this.AccessTier = share.AccessTier;
this.AccessTierChangeTime = share.AccessTierChangeTime;
this.AccessTierStatus = share.AccessTierStatus;
}

public PSShare(FileShareItem share)
Expand All @@ -52,6 +62,16 @@ public PSShare(FileShareItem share)
this.Etag = share.Etag;
this.LastModifiedTime = share.LastModifiedTime;
this.QuotaGiB = share.ShareQuota;
this.Version = share.Version;
this.Deleted = share.Deleted;
this.DeletedTime = share.DeletedTime;
this.RemainingRetentionDays = share.RemainingRetentionDays;
this.EnabledProtocols = share.EnabledProtocols;
this.RootSquash = share.RootSquash;
this.ShareUsageBytes = share.ShareUsageBytes;
this.AccessTier = share.AccessTier;
this.AccessTierChangeTime = share.AccessTierChangeTime;
this.AccessTierStatus = share.AccessTierStatus;
}

[Ps1Xml(Label = "ResourceGroupName", Target = ViewControl.List, Position = 0)]
Expand All @@ -78,7 +98,25 @@ public PSShare(FileShareItem share)
[Ps1Xml(Label = "LastModifiedTime", Target = ViewControl.List, ScriptBlock = "$_.LastModifiedTime.ToString(\"u\")", Position = 5)]
public DateTime? LastModifiedTime { get; set; }


[Ps1Xml(Label = "Version", Target = ViewControl.List, Position = 7)]
public string Version { get; set; }

public bool? Deleted { get; private set; }

[Ps1Xml(Label = "DeletedTime", Target = ViewControl.List, ScriptBlock = "$_.DeletedTime.ToString(\"u\")", Position = 6)]
public DateTime? DeletedTime { get; private set; }

public int? RemainingRetentionDays { get; private set; }

public string EnabledProtocols { get; set; }
public string RootSquash { get; set; }

public string AccessTier { get; set; }
public DateTime? AccessTierChangeTime { get; }
public string AccessTierStatus { get; }

public long? ShareUsageBytes { get; }

public static string ParseResourceGroupFromId(string idFromServer)
{
if (!string.IsNullOrEmpty(idFromServer))
Expand Down
34 changes: 23 additions & 11 deletions src/Storage/Storage.Management/Storage.Management.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Management.Storage.Models.PSShare</TypeName>
</ViewSelectedBy>
<GroupBy>
<ScriptBlock>$_.ResourceGroupName + ", StorageAccountName: " + $_.StorageAccountName</ScriptBlock>
<Label>ResourceGroupName</Label>
</GroupBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
Expand All @@ -344,23 +348,27 @@
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>StorageAccountName</Label>
<Label>QuotaGiB</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>ResourceGroupName</Label>
<Label>EnabledProtocol</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>Etag</Label>
<Label>AccessTier</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>QuotaGiB</Label>
<Label>Deleted</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>LastModifiedTime</Label>
<Label>Version</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>ShareUsageBytes</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
Expand All @@ -372,23 +380,27 @@
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<PropertyName>StorageAccountName</PropertyName>
<PropertyName>QuotaGiB</PropertyName>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<PropertyName>ResourceGroupName</PropertyName>
<PropertyName>EnabledProtocol</PropertyName>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<PropertyName>Etag</PropertyName>
<PropertyName>AccessTier</PropertyName>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<PropertyName>QuotaGiB</PropertyName>
</TableColumnItem>
<PropertyName>Deleted</PropertyName>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<PropertyName>Version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<ScriptBlock>$_.LastModifiedTime.ToString("u")</ScriptBlock>
<PropertyName>ShareUsageBytes</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
Expand Down
Loading