Skip to content

Add Sku parameter for Set-AzureResource and New-AzureResource #979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2015
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 @@ -120,6 +120,7 @@
<Compile Include="Entities\Resources\Resource.cs" />
<Compile Include="Entities\Resources\ResourceObjectFormat.cs" />
<Compile Include="Entities\Resources\ResourcePlan.cs" />
<Compile Include="Entities\Resources\ResourceSku.cs" />
<Compile Include="Entities\Resources\TerminalProvisioningStates.cs" />
<Compile Include="Extensions\AsyncExtensions.cs" />
<Compile Include="Extensions\ExceptionExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public class Resource<TProperties>
[JsonProperty(Required = Required.Default)]
public string Type { get; set; }

/// <summary>
/// Gets or sets the resource <c>sku</c>.
/// </summary>
[JsonProperty(Required = Required.Default)]
public ResourceSku Sku { get; set; }


/// <summary>
/// Gets or sets the kind of the resource definition.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources
{
using Newtonsoft.Json;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using should be above namespace


/// <summary>
/// The resource sku object.
/// </summary>
public class ResourceSku
{
/// <summary>
/// Gets or sets the <c>sku</c> name.
/// </summary>
[JsonProperty(Required = Required.Always)]
public string Name { get; set; }

/// <summary>
/// Gets or sets the <c>sku</c> tier.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string Tier { get; set; }

/// <summary>
/// Gets or sets the <c>sku</c> size.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string Size { get; set; }

/// <summary>
/// Gets or sets the <c>sku</c> family.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string Family { get; set; }

/// <summary>
/// Gets or sets the <c>sku</c> capacity.
/// </summary>
[JsonProperty(Required = Required.Default)]
public int? Capacity { get; set; }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public sealed class NewAzureResourceCmdlet : ResourceManipulationCmdletBase
[ValidateNotNullOrEmpty]
public Hashtable PlanObject { get; set; }

/// <summary>
/// Gets or sets the plan object.
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents sku properties.")]
[ValidateNotNullOrEmpty]
public Hashtable SkuObject { get; set; }


/// <summary>
/// Gets or sets the tags.
/// </summary>
Expand Down Expand Up @@ -174,6 +182,7 @@ private Resource<JToken> GetResource()
Location = this.Location,
Kind = this.Kind,
Plan = this.PlanObject.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourcePlan>(),
Sku = this.SkuObject.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>(),
Tags = TagsHelper.GetTagsDictionary(this.Tag),
Properties = this.Properties.ToResourcePropertiesBody(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public sealed class SetAzureResourceCmdlet : ResourceManipulationCmdletBase
[ValidateNotNullOrEmpty]
public Hashtable Plan { get; set; }

/// <summary>
/// Gets or sets the plan object.
/// </summary>
[Alias("SkuObject")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents sku properties.")]
[ValidateNotNullOrEmpty]
public Hashtable Sku { get; set; }


/// <summary>
/// Gets or sets the tags.
/// </summary>
Expand Down Expand Up @@ -165,6 +174,7 @@ private JToken GetResourceBody()
{
Kind = this.Kind,
Plan = this.Plan.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourcePlan>(),
Sku = this.Sku.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>(),
Tags = TagsHelper.GetTagsDictionary(this.Tag),
Properties = this.Properties.ToResourcePropertiesBody(),
}.ToJToken();
Expand All @@ -176,6 +186,7 @@ private JToken GetResourceBody()
{
Kind = this.Kind ?? resource.Kind,
Plan = this.Plan.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourcePlan>() ?? resource.Plan,
Sku = this.Sku.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>() ?? resource.Sku,
Tags = TagsHelper.GetTagsDictionary(this.Tag) ?? resource.Tags,
Location = resource.Location,
Properties = this.Properties == null ? resource.Properties : this.Properties.ToResourcePropertiesBody(),
Expand All @@ -194,7 +205,7 @@ private JToken GetResourceBody()
/// </summary>
private bool ShouldUsePatchSemantics()
{
return this.UsePatchSemantics || (this.Tag != null && this.Plan == null && this.Properties == null && this.Kind == null);
return this.UsePatchSemantics || ((this.Tag != null || this.Sku != null) && this.Plan == null && this.Properties == null && this.Kind == null);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function Test-CreatesNewSimpleResource
$resourceType = "Microsoft.Sql/servers"

# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
$actual = New-AzureRmResource -Name $rname -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -ApiVersion $apiversion
$expected = Get-AzureRmResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType -ApiVersion $apiversion
New-AzureRMResourceGroup -Name $rgname -Location $rglocation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should be AzureRm not AzureRM

$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
$expected = Get-AzureRMResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType -ApiVersion $apiversion

$list = Get-AzureRmResource -ResourceGroupName $rgname

Expand All @@ -38,7 +38,8 @@ function Test-CreatesNewSimpleResource
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.ResourceType $actual.ResourceType
Assert-AreEqual 1 @($list).Count
Assert-AreEqual $expected.Name $list[0].Name
Assert-AreEqual $expected.Name $list[0].Name
Assert-AreEqual $expected.Sku $actual.Sku
}

<#
Expand Down Expand Up @@ -258,12 +259,14 @@ function Test-SetAResource
$resourceType = "Providers.Test/statefulResources"

# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
$resource = New-AzureRmResource -Name $rname -Location $rglocation -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -ApiVersion $apiversion -Force
Set-AzureRmResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force
New-AzureRMResourceGroup -Name $rgname -Location $rglocation
$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
Set-AzureRMResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force
Set-AzureRMResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -SkuObject @{ Name = "A1" } -Force

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

# Assert
Assert-AreEqual $modifiedResource.Properties.key2 "value2"
Assert-AreEqual $modifiedResource.Sku.Name "A1"
}