Skip to content

Commit 03852e5

Browse files
authored
Merge pull request #10005 from wastoresh/srpfileshare
[Storage] Support Managed File Share in SRP
2 parents 44a5e7e + 13de674 commit 03852e5

23 files changed

+3723
-11
lines changed

src/EventGrid/EventGrid.Test/EventGrid.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="Microsoft.Azure.Management.EventHub" Version="2.5.0" />
1616
<PackageReference Include="Microsoft.Azure.Management.Relay" Version="2.0.2" />
1717
<PackageReference Include="Microsoft.Azure.Management.ServiceBus" Version="2.1.0" />
18-
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="12.0.0" />
18+
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="13.1.0" />
1919
</ItemGroup>
2020

2121
</Project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
16+
using Microsoft.Azure.ServiceManagement.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.Management.Storage.Test.ScenarioTests
23+
{
24+
public class StorageFileTests : RMTestBase
25+
{
26+
public XunitTracingInterceptor _logger;
27+
28+
public StorageFileTests(ITestOutputHelper output)
29+
{
30+
_logger = new XunitTracingInterceptor(output);
31+
XunitTracingInterceptor.AddToContext(_logger);
32+
}
33+
34+
[Fact]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
public void TestStorageFileShare()
37+
{
38+
TestController.NewInstance.RunPsTest(_logger, "Test-StorageFileShare");
39+
}
40+
}
41+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Test Storage File Share
18+
.DESCRIPTION
19+
SmokeTest
20+
#>
21+
function Test-StorageFileShare
22+
{
23+
# Setup
24+
$rgname = Get-StorageManagementTestResourceName;
25+
26+
try
27+
{
28+
# Test
29+
$stoname = 'sto' + $rgname;
30+
$stotype = 'Standard_GRS';
31+
$loc = Get-ProviderLocation ResourceManagement;
32+
$kind = 'StorageV2'
33+
$shareName = "share"+ $rgname
34+
35+
Write-Verbose "RGName: $rgname | Loc: $loc"
36+
New-AzResourceGroup -Name $rgname -Location $loc;
37+
38+
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -Kind $kind
39+
$stos = Get-AzStorageAccount -ResourceGroupName $rgname;
40+
41+
New-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName
42+
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName
43+
Assert-AreEqual $rgname $share.ResourceGroupName
44+
Assert-AreEqual $stoname $share.StorageAccountName
45+
Assert-AreEqual $shareName $share.Name
46+
47+
$quotaGiB = 100
48+
$metadata = @{tag0="value0";tag1="value1"}
49+
50+
Update-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName -QuotaGiB $quotaGiB -Metadata $metadata
51+
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName
52+
Assert-AreEqual $rgname $share.ResourceGroupName
53+
Assert-AreEqual $stoname $share.StorageAccountName
54+
Assert-AreEqual $shareName $share.Name
55+
Assert-AreEqual $quotaGiB $share.QuotaGiB
56+
Assert-AreEqual $metadata.Count $share.Metadata.Count
57+
58+
$quotaGiB = 200
59+
$metadata = @{tag0="value0";tag1="value1";tag2="value2"}
60+
$share | Update-AzRmStorageShare -QuotaGiB $quotaGiB -Metadata $metadata
61+
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName
62+
Assert-AreEqual $rgname $share.ResourceGroupName
63+
Assert-AreEqual $stoname $share.StorageAccountName
64+
Assert-AreEqual $shareName $share.Name
65+
Assert-AreEqual $quotaGiB $share.QuotaGiB
66+
Assert-AreEqual $metadata.Count $share.Metadata.Count
67+
68+
$quotaGiB = 300
69+
$metadata = @{tag0="value0";tag1="value1";tag2="value2";tag3="value3"}
70+
$shareName2 = "share2"+ $rgname
71+
$stos | New-AzRmStorageShare -Name $shareName2 -QuotaGiB $quotaGiB -Metadata $metadata
72+
$share = $stos | Get-AzRmStorageShare -Name $shareName2
73+
Assert-AreEqual $rgname $share.ResourceGroupName
74+
Assert-AreEqual $stoname $share.StorageAccountName
75+
Assert-AreEqual $shareName2 $share.Name
76+
Assert-AreEqual $quotaGiB $share.QuotaGiB
77+
Assert-AreEqual $metadata.Count $share.Metadata.Count
78+
79+
$shares = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname
80+
Assert-AreEqual 2 $shares.Count
81+
Assert-AreEqual $shareName $shares[1].Name
82+
Assert-AreEqual $shareName2 $shares[0].Name
83+
84+
Remove-AzRmStorageShare -Force -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName
85+
$shares = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname
86+
Assert-AreEqual 1 $shares.Count
87+
Assert-AreEqual $shareName2 $shares[0].Name
88+
89+
$stos | Get-AzRmStorageShare -Name $shareName2 | Remove-AzRmStorageShare -Force
90+
$shares = Get-AzRmStorageShare -StorageAccount $stos
91+
Assert-AreEqual 0 $shares.Count
92+
93+
Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $stoname;
94+
}
95+
finally
96+
{
97+
# Cleanup
98+
Clean-ResourceGroup $rgname
99+
}
100+
}
101+
102+
103+

src/Storage/Storage.Management.Test/SessionRecords/Microsoft.Azure.Commands.Management.Storage.Test.ScenarioTests.StorageFileTests/TestStorageFileShare.json

Lines changed: 1797 additions & 0 deletions
Large diffs are not rendered by default.

src/Storage/Storage.Management.Test/Storage.Management.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="12.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="13.1.0" />
1515
</ItemGroup>
1616

1717
</Project>

src/Storage/Storage.Management/Az.Storage.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ CmdletsToExport = 'Get-AzStorageAccount', 'Get-AzStorageAccountKey',
155155
'Get-AzStorageBlobServiceProperty',
156156
'Enable-AzStorageBlobDeleteRetentionPolicy',
157157
'Disable-AzStorageBlobDeleteRetentionPolicy',
158-
'Get-AzStorageFileHandle', 'Close-AzStorageFileHandle'
158+
'Get-AzStorageFileHandle', 'Close-AzStorageFileHandle',
159+
'New-AzRmStorageShare', 'Remove-AzRmStorageShare',
160+
'Get-AzRmStorageShare', 'Update-AzRmStorageShare'
159161

160162
# Variables to export from this module
161163
# VariablesToExport = @()

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
* Updated example in reference documentation for `Get-AzStorageAccountKey`
2222
* Fix Upload block blob with properties/metadate fail on container enabled ImmutabilityPolicy.
2323
- Set-AzStorageBlobContent
24+
* Support manage Azure File shares with Management plane API
25+
- New-AzRmStorageShare
26+
- Get-AzRmStorageShare
27+
- Update-AzRmStorageShare
28+
- Remove-AzRmStorageShare
2429

2530
## Version 1.6.0
2631
* Fixed miscellaneous typos across module
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Management.Storage.Models;
16+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
17+
using Microsoft.Azure.Management.Storage;
18+
using Microsoft.Azure.Management.Storage.Models;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Management.Automation;
22+
23+
namespace Microsoft.Azure.Commands.Management.Storage
24+
{
25+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMStoragePrefix + StorageShareNounStr, DefaultParameterSetName = AccountNameParameterSet), OutputType(typeof(PSShare))]
26+
public class GetAzureStorageShareCommand : StorageFileBaseCmdlet
27+
{
28+
/// <summary>
29+
/// AccountName Parameter Set
30+
/// </summary>
31+
private const string AccountNameParameterSet = "AccountName";
32+
33+
/// <summary>
34+
/// Account object parameter set
35+
/// </summary>
36+
private const string AccountObjectParameterSet = "AccountObject";
37+
38+
/// <summary>
39+
/// Share ResourceId parameter set
40+
/// </summary>
41+
private const string ShareResourceIdParameterSet = "ShareResourceId";
42+
43+
[Parameter(
44+
Position = 0,
45+
Mandatory = true,
46+
HelpMessage = "Resource Group Name.",
47+
ParameterSetName = AccountNameParameterSet)]
48+
[ValidateNotNullOrEmpty]
49+
public string ResourceGroupName { get; set; }
50+
51+
[Parameter(
52+
Position = 1,
53+
Mandatory = true,
54+
HelpMessage = "Storage Account Name.",
55+
ParameterSetName = AccountNameParameterSet)]
56+
[Alias(AccountNameAlias)]
57+
[ValidateNotNullOrEmpty]
58+
public string StorageAccountName { get; set; }
59+
60+
[Parameter(Mandatory = true,
61+
HelpMessage = "Storage account object",
62+
ValueFromPipeline = true,
63+
ParameterSetName = AccountObjectParameterSet)]
64+
[ValidateNotNullOrEmpty]
65+
public PSStorageAccount StorageAccount { get; set; }
66+
67+
[Parameter(
68+
Position = 0,
69+
Mandatory = true,
70+
ValueFromPipelineByPropertyName = true,
71+
HelpMessage = "Input a File Share Resource Id.",
72+
ParameterSetName = ShareResourceIdParameterSet)]
73+
[ValidateNotNullOrEmpty]
74+
public string ResourceId { get; set; }
75+
76+
[Alias("N", "ShareName")]
77+
[Parameter(HelpMessage = "Share Name",
78+
Mandatory = false)]
79+
public string Name { get; set; }
80+
81+
public override void ExecuteCmdlet()
82+
{
83+
base.ExecuteCmdlet();
84+
85+
switch (ParameterSetName)
86+
{
87+
case AccountObjectParameterSet:
88+
this.ResourceGroupName = StorageAccount.ResourceGroupName;
89+
this.StorageAccountName = StorageAccount.StorageAccountName;
90+
break;
91+
case ShareResourceIdParameterSet:
92+
ResourceIdentifier shareResource = new ResourceIdentifier(ResourceId);
93+
this.ResourceGroupName = shareResource.ResourceGroupName;
94+
this.StorageAccountName = PSBlobServiceProperties.GetStorageAccountNameFromResourceId(ResourceId);
95+
this.Name = shareResource.ResourceName;
96+
break;
97+
default:
98+
// For AccountNameParameterSet, the ResourceGroupName and StorageAccountName can get from input directly
99+
break;
100+
}
101+
102+
if (!string.IsNullOrEmpty(this.Name))
103+
{
104+
var Share = this.StorageClient.FileShares.Get(
105+
this.ResourceGroupName,
106+
this.StorageAccountName,
107+
this.Name);
108+
WriteObject(new PSShare(Share));
109+
}
110+
else
111+
{
112+
var Shares = this.StorageClient.FileShares.List(
113+
this.ResourceGroupName,
114+
this.StorageAccountName);
115+
WriteShareList(Shares);
116+
}
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)