Skip to content

Commit feb6a31

Browse files
committed
Merge pull request #979 from chidmdxx/AddSkuParameter
Add Sku parameter for Set-AzureResource and New-AzureResource
2 parents e2ba4d4 + 4e1e475 commit feb6a31

File tree

6 files changed

+94
-8
lines changed

6 files changed

+94
-8
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<Compile Include="Entities\Resources\Resource.cs" />
121121
<Compile Include="Entities\Resources\ResourceObjectFormat.cs" />
122122
<Compile Include="Entities\Resources\ResourcePlan.cs" />
123+
<Compile Include="Entities\Resources\ResourceSku.cs" />
123124
<Compile Include="Entities\Resources\TerminalProvisioningStates.cs" />
124125
<Compile Include="Extensions\AsyncExtensions.cs" />
125126
<Compile Include="Extensions\ExceptionExtensions.cs" />

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/Resource.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public class Resource<TProperties>
4747
[JsonProperty(Required = Required.Default)]
4848
public string Type { get; set; }
4949

50+
/// <summary>
51+
/// Gets or sets the resource <c>sku</c>.
52+
/// </summary>
53+
[JsonProperty(Required = Required.Default)]
54+
public ResourceSku Sku { get; set; }
55+
56+
5057
/// <summary>
5158
/// Gets or sets the kind of the resource definition.
5259
/// </summary>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// The resource sku object.
21+
/// </summary>
22+
public class ResourceSku
23+
{
24+
/// <summary>
25+
/// Gets or sets the <c>sku</c> name.
26+
/// </summary>
27+
[JsonProperty(Required = Required.Always)]
28+
public string Name { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the <c>sku</c> tier.
32+
/// </summary>
33+
[JsonProperty(Required = Required.Default)]
34+
public string Tier { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the <c>sku</c> size.
38+
/// </summary>
39+
[JsonProperty(Required = Required.Default)]
40+
public string Size { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the <c>sku</c> family.
44+
/// </summary>
45+
[JsonProperty(Required = Required.Default)]
46+
public string Family { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets the <c>sku</c> capacity.
50+
/// </summary>
51+
[JsonProperty(Required = Required.Default)]
52+
public int? Capacity { get; set; }
53+
}
54+
}
55+

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/NewAzureResourceCmdlet.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public sealed class NewAzureResourceCmdlet : ResourceManipulationCmdletBase
6060
[ValidateNotNullOrEmpty]
6161
public Hashtable PlanObject { get; set; }
6262

63+
/// <summary>
64+
/// Gets or sets the plan object.
65+
/// </summary>
66+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents sku properties.")]
67+
[ValidateNotNullOrEmpty]
68+
public Hashtable SkuObject { get; set; }
69+
70+
6371
/// <summary>
6472
/// Gets or sets the tags.
6573
/// </summary>
@@ -174,6 +182,7 @@ private Resource<JToken> GetResource()
174182
Location = this.Location,
175183
Kind = this.Kind,
176184
Plan = this.PlanObject.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourcePlan>(),
185+
Sku = this.SkuObject.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>(),
177186
Tags = TagsHelper.GetTagsDictionary(this.Tag),
178187
Properties = this.Properties.ToResourcePropertiesBody(),
179188
};

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/SetAzureResourceCmdlet.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public sealed class SetAzureResourceCmdlet : ResourceManipulationCmdletBase
5353
[ValidateNotNullOrEmpty]
5454
public Hashtable Plan { get; set; }
5555

56+
/// <summary>
57+
/// Gets or sets the plan object.
58+
/// </summary>
59+
[Alias("SkuObject")]
60+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents sku properties.")]
61+
[ValidateNotNullOrEmpty]
62+
public Hashtable Sku { get; set; }
63+
64+
5665
/// <summary>
5766
/// Gets or sets the tags.
5867
/// </summary>
@@ -165,6 +174,7 @@ private JToken GetResourceBody()
165174
{
166175
Kind = this.Kind,
167176
Plan = this.Plan.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourcePlan>(),
177+
Sku = this.Sku.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>(),
168178
Tags = TagsHelper.GetTagsDictionary(this.Tag),
169179
Properties = this.Properties.ToResourcePropertiesBody(),
170180
}.ToJToken();
@@ -176,6 +186,7 @@ private JToken GetResourceBody()
176186
{
177187
Kind = this.Kind ?? resource.Kind,
178188
Plan = this.Plan.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourcePlan>() ?? resource.Plan,
189+
Sku = this.Sku.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>() ?? resource.Sku,
179190
Tags = TagsHelper.GetTagsDictionary(this.Tag) ?? resource.Tags,
180191
Location = resource.Location,
181192
Properties = this.Properties == null ? resource.Properties : this.Properties.ToResourcePropertiesBody(),
@@ -194,7 +205,7 @@ private JToken GetResourceBody()
194205
/// </summary>
195206
private bool ShouldUsePatchSemantics()
196207
{
197-
return this.UsePatchSemantics || (this.Tag != null && this.Plan == null && this.Properties == null && this.Kind == null);
208+
return this.UsePatchSemantics || ((this.Tag != null || this.Sku != null) && this.Plan == null && this.Properties == null && this.Kind == null);
198209
}
199210

200211
/// <summary>

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceTests.ps1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function Test-CreatesNewSimpleResource
2727
$resourceType = "Microsoft.Sql/servers"
2828

2929
# Test
30-
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
31-
$actual = New-AzureRmResource -Name $rname -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -ApiVersion $apiversion
32-
$expected = Get-AzureRmResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType -ApiVersion $apiversion
30+
New-AzureRMResourceGroup -Name $rgname -Location $rglocation
31+
$actual = New-AzureRMResource -Name $rname -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion
32+
$expected = Get-AzureRMResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType -ApiVersion $apiversion
3333

3434
$list = Get-AzureRmResource -ResourceGroupName $rgname
3535

@@ -38,7 +38,8 @@ function Test-CreatesNewSimpleResource
3838
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
3939
Assert-AreEqual $expected.ResourceType $actual.ResourceType
4040
Assert-AreEqual 1 @($list).Count
41-
Assert-AreEqual $expected.Name $list[0].Name
41+
Assert-AreEqual $expected.Name $list[0].Name
42+
Assert-AreEqual $expected.Sku $actual.Sku
4243
}
4344

4445
<#
@@ -258,12 +259,14 @@ function Test-SetAResource
258259
$resourceType = "Providers.Test/statefulResources"
259260

260261
# Test
261-
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
262-
$resource = New-AzureRmResource -Name $rname -Location $rglocation -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -ApiVersion $apiversion -Force
263-
Set-AzureRmResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force
262+
New-AzureRMResourceGroup -Name $rgname -Location $rglocation
263+
$resource = New-AzureRMResource -Name $rname -Location $rglocation -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
264+
Set-AzureRMResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force
265+
Set-AzureRMResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -SkuObject @{ Name = "A1" } -Force
264266

265267
$modifiedResource = Get-AzureRmResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType
266268

267269
# Assert
268270
Assert-AreEqual $modifiedResource.Properties.key2 "value2"
271+
Assert-AreEqual $modifiedResource.Sku.Name "A1"
269272
}

0 commit comments

Comments
 (0)