Skip to content

Commit ffffce4

Browse files
committed
Adding Get-AzureSq1LocationCapabilities cmdlet.
1 parent 8da68f1 commit ffffce4

14 files changed

+634
-18
lines changed

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
<SpecificVersion>False</SpecificVersion>
5252
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.0.19.2-preview\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
5353
</Reference>
54-
<Reference Include="Microsoft.Azure.Management.Sql">
55-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.29.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
56-
</Reference>
5754
<Reference Include="Microsoft.Azure.Common">
5855
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5956
</Reference>
@@ -72,7 +69,7 @@
7269
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
7370
</Reference>
7471
<Reference Include="Microsoft.Azure.Management.Sql">
75-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.36.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
72+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.37.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
7673
</Reference>
7774
<Reference Include="Microsoft.Azure.Management.Storage">
7875
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.2.4.0-preview\lib\net40\Microsoft.Azure.Management.Storage.dll</HintPath>

src/ResourceManager/Sql/Commands.Sql.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Authorization" version="0.19.2-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
10-
<package id="Microsoft.Azure.Management.Sql" version="0.36.0-prerelease" targetFramework="net45" />
10+
<package id="Microsoft.Azure.Management.Sql" version="0.37.0-prerelease" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Test.Framework" version="1.0.5687.28567-prerelease" targetFramework="net45" />
1313
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5687.28567-prerelease" targetFramework="net45" />

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@
9393
<Compile Include="Database Activation\Services\SqlAzureDatabaseActivationCommunicator.cs" />
9494
<Compile Include="Database\Cmdlet\GetAzureSqlDatabaseExpanded.cs" />
9595
<Compile Include="Database\Model\AzureSqlDatabaseModelExpanded.cs" />
96+
<Compile Include="Location Capabilities\Cmdlet\GetAzureSqlLocationCapability.cs" />
97+
<Compile Include="Location Capabilities\Model\EditionCapabilities.cs" />
98+
<Compile Include="Location Capabilities\Model\LocationCapabilityModel.cs" />
99+
<Compile Include="Location Capabilities\Model\MaxSizeCapability.cs" />
100+
<Compile Include="Location Capabilities\Model\ServerVersionCapabilities.cs" />
101+
<Compile Include="Location Capabilities\Model\ServiceObjectiveCapability.cs" />
102+
<Compile Include="Location Capabilities\Services\AzureSqlLocationCapabilitiesAdapter.cs" />
103+
<Compile Include="Location Capabilities\Services\AzureSqlLocationCapabilitiesCommunicator.cs" />
96104
<Compile Include="RecommendedElasticPools\Cmdlet\GetAzureSqlElasticPoolRecommendation.cs" />
97105
<Compile Include="RecommendedElasticPools\Services\AzureSqlElasticPoolRecommendationAdapter.cs" />
98106
<Compile Include="RecommendedElasticPools\Services\AzureSqlElasticPoolRecommendationCommunicator.cs" />
@@ -217,10 +225,6 @@
217225
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.1.3-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
218226
<Private>True</Private>
219227
</Reference>
220-
<Reference Include="Microsoft.Azure.Management.Sql">
221-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.36.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
222-
<SpecificVersion>False</SpecificVersion>
223-
</Reference>
224228
<Reference Include="Microsoft.Azure.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
225229
<SpecificVersion>False</SpecificVersion>
226230
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
@@ -229,6 +233,10 @@
229233
<SpecificVersion>False</SpecificVersion>
230234
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
231235
</Reference>
236+
<Reference Include="Microsoft.Azure.Management.Sql">
237+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.37.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
238+
<SpecificVersion>False</SpecificVersion>
239+
</Reference>
232240
<Reference Include="Microsoft.Azure.Management.Storage">
233241
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.2.4.0-preview\lib\net40\Microsoft.Azure.Management.Storage.dll</HintPath>
234242
</Reference>

src/ResourceManager/Sql/Commands.Sql/FirewallRule/Services/AzureSqlServerFirewallRuleAdapter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
1615
using System.Collections.Generic;
1716
using System.Linq;
18-
using Microsoft.Azure.Commands.Sql.Common;
1917
using Microsoft.Azure.Commands.Sql.FirewallRule.Model;
2018
using Microsoft.Azure.Commands.Sql.FirewallRule.Services;
2119
using Microsoft.Azure.Commands.Sql.Services;
2220
using Microsoft.Azure.Common.Authentication.Models;
23-
using Microsoft.Azure.Management.Sql;
2421
using Microsoft.Azure.Management.Sql.Models;
2522

2623
namespace Microsoft.Azure.Commands.Sql.FirewallRule.Adapter

src/ResourceManager/Sql/Commands.Sql/FirewallRule/Services/AzureSqlServerFirewallRuleCommunicator.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Sql.Common;
1518
using Microsoft.Azure.Common.Authentication;
1619
using Microsoft.Azure.Common.Authentication.Models;
17-
using Microsoft.Azure.Management.Resources;
1820
using Microsoft.Azure.Management.Sql;
1921
using Microsoft.Azure.Management.Sql.Models;
20-
using Microsoft.WindowsAzure.Management.Storage;
21-
using System;
22-
using System.Collections.Generic;
23-
using Microsoft.Azure.Commands.Sql.Common;
2422

2523
namespace Microsoft.Azure.Commands.Sql.FirewallRule.Services
2624
{
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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 System.Management.Automation;
16+
using Microsoft.Azure.Commands.Sql.Location_Capabilities.Model;
17+
using Microsoft.Azure.Commands.Sql.Location_Capabilities.Services;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using System.Linq;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Location_Capabilities.Cmdlet
22+
{
23+
/// <summary>
24+
/// Defines the Get-AzureSqlLocationCapability cmdlet
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, "AzureSqlLocationCapability",
27+
ConfirmImpact = ConfirmImpact.None,
28+
DefaultParameterSetName = _filtered)]
29+
public class GetAzureSqlLocationCapability : AzurePSCmdlet
30+
{
31+
/// <summary>
32+
/// Parameter set name for when the cmdlet is invoked without specifying -Default
33+
/// </summary>
34+
private const string _filtered = "FilterResults";
35+
36+
/// <summary>
37+
/// Parameter set name for when the cmdlet is invoked with the -Default switch specified
38+
/// </summary>
39+
private const string _default = "DefaultResults";
40+
41+
/// <summary>
42+
/// Gets or sets the name of the Location
43+
/// </summary>
44+
[Parameter(Mandatory = true,
45+
ValueFromPipelineByPropertyName = true,
46+
Position = 0,
47+
HelpMessage = "The name of the Location for which to get the capabilities")]
48+
[ValidateNotNullOrEmpty]
49+
public string LocationName { get; set; }
50+
51+
/// <summary>
52+
/// Gets or sets the name of the server version
53+
/// </summary>
54+
[Parameter(Mandatory = false,
55+
ValueFromPipelineByPropertyName = true,
56+
HelpMessage = "The name of the server version for which to get the capabilities",
57+
ParameterSetName = _filtered)]
58+
[ValidateNotNullOrEmpty]
59+
public string ServerVersionName { get; set; }
60+
61+
/// <summary>
62+
/// Gets or sets the name of the database edition
63+
/// </summary>
64+
[Parameter(Mandatory = false,
65+
ValueFromPipelineByPropertyName = true,
66+
HelpMessage = "The name of the database edition for which to get the capabilities",
67+
ParameterSetName = _filtered)]
68+
[ValidateNotNullOrEmpty]
69+
public string EditionName { get; set; }
70+
71+
/// <summary>
72+
/// Gets or sets the name of the edition service level objective
73+
/// </summary>
74+
[Parameter(Mandatory = false,
75+
ValueFromPipelineByPropertyName = true,
76+
HelpMessage = "The name of the edition Service Objective for which to get the capabilities",
77+
ParameterSetName = _filtered)]
78+
[ValidateNotNullOrEmpty]
79+
public string ServiceObjectiveName { get; set; }
80+
81+
[Parameter(Mandatory = false,
82+
HelpMessage = "Indicates that the results should be filtered such that only defaults are shown",
83+
ParameterSetName = _default)]
84+
public SwitchParameter Defaults { get; set; }
85+
86+
/// <summary>
87+
/// Executes the cmdlet
88+
/// </summary>
89+
public override void ExecuteCmdlet()
90+
{
91+
AzureSqlLocationCapabilitiesAdapter adapter = new AzureSqlLocationCapabilitiesAdapter(Profile, Profile.Context.Subscription);
92+
LocationCapabilityModel model = adapter.GetLocationCapabilities(LocationName);
93+
94+
switch(ParameterSetName)
95+
{
96+
case _default:
97+
{
98+
FilterByDefaults(model);
99+
}
100+
break;
101+
case _filtered:
102+
{
103+
if (this.MyInvocation.BoundParameters.ContainsKey("ServerVersionName"))
104+
{
105+
FilterByServerVersion(model);
106+
}
107+
if (this.MyInvocation.BoundParameters.ContainsKey("EditionName"))
108+
{
109+
FilterByEditionName(model);
110+
}
111+
if (this.MyInvocation.BoundParameters.ContainsKey("ServiceObjectiveName"))
112+
{
113+
FilterByServiceObjectiveName(model);
114+
}
115+
}
116+
break;
117+
}
118+
119+
this.WriteObject(model);
120+
}
121+
122+
/// <summary>
123+
/// Filter the results based on what is marked as status
124+
/// </summary>
125+
/// <param name="model">The model to filter</param>
126+
private void FilterByDefaults(LocationCapabilityModel model)
127+
{
128+
model.SupportedServerVersions = model.SupportedServerVersions.Where(v => { return v.Status == "Default"; }).ToList();
129+
130+
// Get all defaults
131+
var defaultVersion = model.SupportedServerVersions;
132+
defaultVersion[0].SupportedEditions = defaultVersion[0].SupportedEditions.Where(v => { return v.Status == "Default"; }).ToList();
133+
var defaultEdition = defaultVersion[0].SupportedEditions;
134+
defaultEdition[0].SupportedServiceLevelObjectives = defaultEdition[0].SupportedServiceLevelObjectives.Where(v => { return v.Status == "Default"; }).ToList();
135+
var defaultServiceObjective = defaultEdition[0].SupportedServiceLevelObjectives;
136+
137+
// Assign defaults back to model.
138+
defaultServiceObjective[0].SupportedMaxSizes = defaultServiceObjective[0].SupportedMaxSizes.Where(v => { return v.Status == "Default"; }).ToList();
139+
defaultEdition[0].SupportedServiceLevelObjectives = defaultServiceObjective;
140+
defaultVersion[0].SupportedEditions = defaultEdition;
141+
model.SupportedServerVersions = defaultVersion;
142+
}
143+
144+
/// <summary>
145+
/// Filter the results based on the Service Objective Name
146+
/// </summary>
147+
/// <param name="model">The model to filter</param>
148+
private void FilterByServiceObjectiveName(LocationCapabilityModel model)
149+
{
150+
foreach (var version in model.SupportedServerVersions)
151+
{
152+
foreach (var edition in version.SupportedEditions)
153+
{
154+
// Remove all service objectives with a name that does not match the desired value
155+
edition.SupportedServiceLevelObjectives =
156+
edition.SupportedServiceLevelObjectives
157+
.Where(slo => { return slo.ServiceObjectiveName == this.ServiceObjectiveName; })
158+
.ToList();
159+
}
160+
161+
// Remove editions that have no supported service objectives after filtering
162+
version.SupportedEditions = version.SupportedEditions.Where(e => e.SupportedServiceLevelObjectives.Count > 0).ToList();
163+
}
164+
165+
// Remove server versions that have no supported editions after filtering
166+
model.SupportedServerVersions = model.SupportedServerVersions.Where(v => v.SupportedEditions.Count > 0).ToList();
167+
}
168+
169+
/// <summary>
170+
/// Filter the results based on the Edition Name
171+
/// </summary>
172+
/// <param name="model">The model to filter</param>
173+
private void FilterByEditionName(LocationCapabilityModel model)
174+
{
175+
foreach(var version in model.SupportedServerVersions)
176+
{
177+
// Remove all editions that do not match the desired edition name
178+
version.SupportedEditions =
179+
version.SupportedEditions
180+
.Where(e => { return e.EditionName == this.EditionName; })
181+
.ToList();
182+
}
183+
184+
// Remove server versions that have no supported editions after filtering
185+
model.SupportedServerVersions = model.SupportedServerVersions.Where(v => v.SupportedEditions.Count > 0).ToList();
186+
}
187+
188+
/// <summary>
189+
/// Filter the results based on the server version name
190+
/// </summary>
191+
/// <param name="model">The model to filter</param>
192+
private void FilterByServerVersion(LocationCapabilityModel model)
193+
{
194+
// Remove all server versions that don't match the desired name
195+
model.SupportedServerVersions =
196+
model.SupportedServerVersions
197+
.Where(obj => { return obj.ServerVersionName == this.ServerVersionName; })
198+
.ToList();
199+
}
200+
}
201+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright Microsoft Corporation
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
// ----------------------------------------------------------------------------------
13+
14+
using System.Collections.Generic;
15+
16+
namespace Microsoft.Azure.Commands.Sql.Location_Capabilities.Model
17+
{
18+
/// <summary>
19+
/// Represents an Edition for an Azure SQL Database and its capabilities
20+
/// </summary>
21+
public class EditionCapabilities
22+
{
23+
/// <summary>
24+
/// Gets or sets the name of the Edition
25+
/// </summary>
26+
public string EditionName { get; set; }
27+
28+
/// <summary>
29+
/// Gets or sets the status of the Edition with respect to Azure SQL Server version for the current subscription
30+
/// </summary>
31+
public string Status { get; set; }
32+
33+
/// <summary>
34+
/// Gets or sets the list of supported Service Level Objectives and their capabilities.
35+
/// </summary>
36+
public IList<ServiceObjectiveCapability> SupportedServiceLevelObjectives { get; set; }
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 System.Collections.Generic;
16+
17+
namespace Microsoft.Azure.Commands.Sql.Location_Capabilities.Model
18+
{
19+
/// <summary>
20+
/// Represents the capabilities available in a region
21+
/// </summary>
22+
public class LocationCapabilityModel
23+
{
24+
/// <summary>
25+
/// Gets or sets the name of the region
26+
/// </summary>
27+
public string LocationName { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the status of the region with respect to Azure SQL for the current subscription
31+
/// </summary>
32+
public string Status { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets a list of all the supported server versions and their capabilities
36+
/// </summary>
37+
public IList<ServerVersionCapabilities> SupportedServerVersions { get; set; }
38+
}
39+
}

0 commit comments

Comments
 (0)