Skip to content

Commit 0415024

Browse files
committed
Added SupportedVirtualMachineSkus command.
1 parent 42795b5 commit 0415024

File tree

11 files changed

+302
-6
lines changed

11 files changed

+302
-6
lines changed

src/Accounts/Accounts/AzureRmAlias/Mappings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
"Test-AzBatchAutoScale": "Test-AzureBatchAutoScale",
357357
"Get-AzBatchLocationQuotas": "Get-AzureRmBatchLocationQuotas",
358358
"Get-AzBatchSubtask": "Get-AzureBatchSubtask",
359+
"Get-AzGetSupportedVirtualMachineSkus": "Get-AzureBatchSupportedVirtualMachineSkus",
359360
"Get-AzBatchTask": "Get-AzureBatchTask",
360361
"New-AzBatchTask": "New-AzureBatchTask",
361362
"Remove-AzBatchTask": "Remove-AzureBatchTask",

src/Batch/Batch.Test/Locations/GetBatchLocationQuotasCommandTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
using Microsoft.Azure.Commands.Batch.Models;
1616
using Microsoft.Azure.Management.Batch.Models;
17+
using Microsoft.Azure.ServiceManagement.Common.Models;
1718
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1819
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1920
using Moq;
2021
using System.Collections.Generic;
2122
using System.Management.Automation;
2223
using Xunit;
24+
using Xunit.Abstractions;
2325
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
2426

2527
namespace Microsoft.Azure.Commands.Batch.Test.Subscriptions
@@ -30,9 +32,9 @@ public class GetBatchLocationQuotasCommandTests : RMTestBase
3032
private Mock<BatchClient> batchClientMock;
3133
private Mock<ICommandRuntime> commandRuntimeMock;
3234

33-
public GetBatchLocationQuotasCommandTests(Xunit.Abstractions.ITestOutputHelper output)
35+
public GetBatchLocationQuotasCommandTests(ITestOutputHelper output)
3436
{
35-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagement.Common.Models.XunitTracingInterceptor(output));
37+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
3638
batchClientMock = new Mock<BatchClient>();
3739
commandRuntimeMock = new Mock<ICommandRuntime>();
3840
cmdlet = new GetBatchLocationQuotaCommand()
@@ -46,8 +48,6 @@ public GetBatchLocationQuotasCommandTests(Xunit.Abstractions.ITestOutputHelper o
4648
[Trait(Category.AcceptanceType, Category.CheckIn)]
4749
public void GetBatchLocationQuotasTest()
4850
{
49-
List<PSBatchLocationQuotas> pipelineOutput = new List<PSBatchLocationQuotas>();
50-
5151
// Return a pre-built object when the command is issued.
5252
string location = "westus";
5353
PSBatchLocationQuotas quotas = new PSBatchLocationQuotas(location, new BatchLocationQuota(accountQuota: 5));
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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.Batch;
16+
using Microsoft.Azure.Commands.Batch.Models;
17+
using Microsoft.Azure.Management.Batch.Models;
18+
using Microsoft.Azure.ServiceManagement.Common.Models;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
21+
using Moq;
22+
using System.Collections.Generic;
23+
using System.Linq;
24+
using System.Management.Automation;
25+
using Xunit;
26+
using Xunit.Abstractions;
27+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
28+
29+
namespace Microsoft.Azure.Commands.Batch.Test.Subscriptions
30+
{
31+
public class GetSupportedVirtualMachineSkusTests : RMTestBase
32+
{
33+
private GetSupportedVirtualMachineSkusCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public GetSupportedVirtualMachineSkusTests(ITestOutputHelper output)
38+
{
39+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
40+
batchClientMock = new Mock<BatchClient>();
41+
commandRuntimeMock = new Mock<ICommandRuntime>();
42+
cmdlet = new GetSupportedVirtualMachineSkusCommand()
43+
{
44+
CommandRuntime = commandRuntimeMock.Object,
45+
BatchClient = batchClientMock.Object
46+
};
47+
}
48+
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void TestGetSupportedSkus()
52+
{
53+
string location = "westus";
54+
55+
var skus = CreateSkus();
56+
batchClientMock.Setup(client => client.GetSupportedVirtualMachineSkus(location, default, default)).Returns(skus);
57+
58+
cmdlet.Location = location;
59+
cmdlet.ExecuteCmdlet();
60+
61+
commandRuntimeMock.Verify(r => r.WriteObject(skus, true), Times.Once());
62+
}
63+
64+
65+
[Fact]
66+
[Trait(Category.AcceptanceType, Category.CheckIn)]
67+
public void TestGetSupportedSkusWithODataParameters()
68+
{
69+
string location = "westus";
70+
71+
var skus = CreateSkus();
72+
batchClientMock.Setup(client => client.GetSupportedVirtualMachineSkus(location, 3, "testfilter")).Returns(skus);
73+
74+
cmdlet.Location = location;
75+
cmdlet.MaxResults = 3;
76+
cmdlet.Filter = "testfilter";
77+
cmdlet.ExecuteCmdlet();
78+
79+
commandRuntimeMock.Verify(r => r.WriteObject(skus, true), Times.Once());
80+
}
81+
82+
private List<PSSupportedSku> CreateSkus()
83+
{
84+
List<PSSupportedSku> skus = new List<PSSupportedSku>()
85+
{
86+
new PSSupportedSku("testsku1", "testfamily", new List<PSSkuCapability>()
87+
{
88+
new PSSkuCapability("cap1", "val1"),
89+
new PSSkuCapability("cap2", "val2")
90+
}),
91+
new PSSupportedSku("testsku2", "testfamily", new List<PSSkuCapability>()
92+
{
93+
new PSSkuCapability("cap1", "val1"),
94+
}),
95+
new PSSupportedSku("testsku3", "testfamily", new List<PSSkuCapability>()
96+
{
97+
new PSSkuCapability("cap1", "val1"),
98+
new PSSkuCapability("cap2", "val2"),
99+
new PSSkuCapability("cap2", "val2")
100+
}),
101+
new PSSupportedSku("testsku4", "testfamily", new List<PSSkuCapability>()
102+
{
103+
new PSSkuCapability("cap1", "val1"),
104+
}),
105+
};
106+
107+
return skus;
108+
}
109+
}
110+
}

src/Batch/Batch/Az.Batch.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ CmdletsToExport = 'Remove-AzBatchAccount', 'Get-AzBatchAccount',
113113
'Remove-AzBatchJobSchedule', 'Get-AzBatchTaskCount',
114114
'Get-AzBatchPoolNodeCount',
115115
'Start-AzBatchComputeNodeServiceLogUpload',
116-
'New-AzBatchResourceFile'
116+
'New-AzBatchResourceFile',
117+
'Get-AzBatchSupportedVirtualMachineSkus'
117118

118119
# Variables to export from this module
119120
# VariablesToExport = @()

src/Batch/Batch/Batch.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
1818
</ItemGroup>
1919

20+
<ItemGroup>
21+
<Compile Update="Properties\Resources.Designer.cs">
22+
<DesignTime>True</DesignTime>
23+
</Compile>
24+
</ItemGroup>
25+
2026
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Microsoft.Azure.Commands.Batch.Models;
2+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
3+
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
4+
using System.Collections.Generic;
5+
using System.Management.Automation;
6+
7+
namespace Microsoft.Azure.Commands.Batch
8+
{
9+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzurePrefix + "BatchSupportedVirtualMachineSkus"), OutputType(typeof(PSSupportedSku))]
10+
public class GetSupportedVirtualMachineSkusCommand : BatchCmdletBase
11+
{
12+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
13+
HelpMessage = "The region to get the supported SKUs from.")]
14+
[LocationCompleter("Microsoft.Batch/locations/quotas")]
15+
[ValidateNotNullOrEmpty]
16+
public string Location { get; set; }
17+
18+
[Parameter(Position = 1, ValueFromPipelineByPropertyName = true,
19+
HelpMessage = "The maximum number of items to return in the response.")]
20+
[ValidateNotNullOrEmpty]
21+
public int? MaxResults { get; set; }
22+
23+
[Parameter(Position = 2, ValueFromPipelineByPropertyName = true,
24+
HelpMessage = "OData filter expression. Valid properties for filtering are \"familyName\".")]
25+
[ValidateNotNullOrEmpty]
26+
public string Filter { get; set; }
27+
28+
protected override void ExecuteCmdletImpl()
29+
{
30+
IList<PSSupportedSku> skus = BatchClient.GetSupportedVirtualMachineSkus(Location, MaxResults, Filter);
31+
WriteObject(skus, true);
32+
}
33+
}
34+
}

src/Batch/Batch/Models/BatchClient.Locations.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
using Microsoft.Azure.Commands.Batch.Properties;
1616
using Microsoft.Azure.Management.Batch;
1717
using Microsoft.Azure.Management.Batch.Models;
18+
using Microsoft.Rest.Azure;
1819
using System;
20+
using System.Collections.Generic;
21+
using System.Linq;
1922

2023
namespace Microsoft.Azure.Commands.Batch.Models
2124
{
@@ -38,5 +41,44 @@ public virtual PSBatchLocationQuotas GetLocationQuotas(string location)
3841
BatchLocationQuota response = this.BatchManagementClient.Location.GetQuotas(location);
3942
return new PSBatchLocationQuotas(location, response);
4043
}
44+
45+
public virtual List<PSSupportedSku> GetSupportedVirtualMachineSkus(string location)
46+
{
47+
return GetSupportedVirtualMachineSkus(location, default, default);
48+
}
49+
50+
public virtual List<PSSupportedSku> GetSupportedVirtualMachineSkus(string location, int? maxResults, string filter)
51+
{
52+
if (string.IsNullOrEmpty(location))
53+
{
54+
throw new ArgumentNullException("location");
55+
}
56+
57+
if (maxResults == default && filter == default)
58+
{
59+
WriteVerbose(string.Format(Resources.GettingSupportedVirtualMachineSkus, location));
60+
}
61+
else
62+
{
63+
WriteVerbose(string.Format(Resources.GettingSupportedVirtualMachineSkus, location, maxResults, filter));
64+
}
65+
66+
IPage<SupportedSku> response = BatchManagementClient.Location.ListSupportedVirtualMachineSkus(location, maxResults, filter);
67+
List<PSSupportedSku> psSupportedSkus = response.Select(ConvertToPSSupportedSku).ToList();
68+
69+
while (response.NextPageLink != null)
70+
{
71+
response = BatchManagementClient.Location.ListSupportedVirtualMachineSkusNext(response.NextPageLink);
72+
psSupportedSkus.AddRange(response.Select(ConvertToPSSupportedSku));
73+
}
74+
75+
return psSupportedSkus;
76+
}
77+
78+
private static PSSupportedSku ConvertToPSSupportedSku(SupportedSku sku)
79+
{
80+
IList<PSSkuCapability> capabilities = sku.Capabilities.Select(c => new PSSkuCapability(c.Name, c.Value)).ToList();
81+
return new PSSupportedSku(sku.Name, sku.FamilyName, capabilities);
82+
}
4183
}
4284
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Microsoft.Azure.Commands.Batch.Models
6+
{
7+
public class PSSkuCapability
8+
{
9+
/// <summary>
10+
/// Initializes a new instance of the SkuCapability class.
11+
/// </summary>
12+
/// <param name="name">The name of the feature.</param>
13+
/// <param name="value">The value of the feature.</param>
14+
public PSSkuCapability(string name, string value)
15+
{
16+
Name = name;
17+
Value = value;
18+
}
19+
20+
/// <summary>
21+
/// Gets the name of the feature.
22+
/// </summary>
23+
public string Name { get; private set; }
24+
25+
/// <summary>
26+
/// Gets the value of the feature.
27+
/// </summary>
28+
public string Value { get; private set; }
29+
}
30+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.Management.Batch.Models;
16+
using System;
17+
using System.Collections.Generic;
18+
19+
namespace Microsoft.Azure.Commands.Batch.Models
20+
{
21+
/// <summary>
22+
/// The quotas of a subscription in the Batch Service.
23+
/// </summary>
24+
public class PSSupportedSku
25+
{
26+
public PSSupportedSku(string name, string familyName, IList<PSSkuCapability> capabilities)
27+
{
28+
Name = name;
29+
FamilyName = familyName;
30+
Capabilities = capabilities;
31+
}
32+
33+
/// <summary>
34+
/// The number of the SKU.
35+
/// </summary>
36+
public string Name { get; private set; }
37+
38+
/// <summary>
39+
/// The family name of the SKU.
40+
/// </summary>
41+
public string FamilyName { get; private set; }
42+
43+
/// <summary>
44+
/// Gets a collection of capabilities which this SKU supports.
45+
/// </summary>
46+
public IList<PSSkuCapability> Capabilities { get; private set; }
47+
}
48+
}

src/Batch/Batch/Properties/Resources.Designer.cs

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)