Skip to content

Commit 17a48bf

Browse files
committed
Adding AseName and AseResourceGroupName parameters in New-AzureRmAppServicePlan cmdlet
1 parent 2a4d281 commit 17a48bf

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* New-AzureRmWebAppSSLBinding
77
* Get-AzureRmWebAppSSLBinding
88
* Remove-AzureRmWebAppSSLBinding
9+
* Azure Websites: Added AseName and AseResourceGroupName parameters in New-AzureRmAppServicePlan cmdlet
910

1011
## 2015.12.14 version 1.0.2
1112
* Azure Compute (ARM):

src/ResourceManager/Websites/Commands.Websites/Cmdlets/AppServicePlans/NewAzureAppServicePlan.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public class NewAzureAppServicePlanCmdlet : AppServicePlanBaseCmdlet
4141
[ValidateSet("Small", "Medium", "Large", "ExtraLarge", IgnoreCase = true)]
4242
public string WorkerSize { get; set; }
4343

44+
[Parameter(Position = 6, Mandatory = false, HelpMessage = "Name of application service environment")]
45+
[ValidateNotNullOrEmpty]
46+
public string AseName { get; set; }
47+
48+
[Parameter(Position = 7, Mandatory = false, HelpMessage = "Name of the application service environment resource group")]
49+
[ValidateNotNullOrEmpty]
50+
public string AseResourceGroupName { get; set; }
51+
4452
public override void ExecuteCmdlet()
4553
{
4654
if (string.IsNullOrWhiteSpace(Tier))
@@ -53,6 +61,14 @@ public override void ExecuteCmdlet()
5361
WorkerSize = "Small";
5462
}
5563

64+
var aseResourceGroupName = AseResourceGroupName;
65+
66+
if (!string.IsNullOrEmpty(AseName)
67+
&& string.IsNullOrEmpty(aseResourceGroupName))
68+
{
69+
aseResourceGroupName = ResourceGroupName;
70+
}
71+
5672
var capacity = NumberofWorkers < 1 ? 1 : NumberofWorkers;
5773
var skuName = CmdletHelpers.GetSkuName(Tier, WorkerSize);
5874

@@ -63,7 +79,7 @@ public override void ExecuteCmdlet()
6379
Capacity = capacity
6480
};
6581

66-
WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, Location, null, sku), true);
82+
WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, Location, null, sku, AseName, aseResourceGroupName), true);
6783
}
6884
}
6985
}

src/ResourceManager/Websites/Commands.Websites/Utilities/CmdletHelpers.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public static class CmdletHelpers
3737

3838
private static readonly Dictionary<string, int> WorkerSizes = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { { "Small", 1 }, { "Medium", 2 }, { "Large", 3 }, { "ExtraLarge", 4 } };
3939

40+
public const string ApplicationServiceEnvironmentResourcesName = "hostingEnvironments";
41+
private const string ApplicationServiceEnvironmentResourceIdFormat =
42+
"/subscriptions/{0}/resourcegroups/{1}/providers/Microsoft.Web/{2}/{3}";
43+
4044
public static Dictionary<string, string> ConvertToStringDictionary(this Hashtable hashtable)
4145
{
4246
return hashtable == null ? null : hashtable.Cast<DictionaryEntry>()
@@ -208,6 +212,12 @@ internal static bool TryParseAppAndSlotNames(string name, out string webAppName,
208212
return false;
209213
}
210214

215+
internal static string GetApplicationServiceEnvironmentResourceId(string subscriptionId, string resourceGroupName, string applicationServiceEnvironmentName)
216+
{
217+
return string.Format(ApplicationServiceEnvironmentResourceIdFormat, subscriptionId, resourceGroupName, ApplicationServiceEnvironmentResourcesName,
218+
applicationServiceEnvironmentName);
219+
}
220+
211221
internal static HostNameSslState[] GetHostNameSslStatesFromSiteResponse(Site site, string hostName = null)
212222
{
213223
var hostNameSslState = new HostNameSslState[0];

src/ResourceManager/Websites/Commands.Websites/Utilities/WebsitesClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public IList<ResourceMetric> GetWebAppUsageMetrics(string resourceGroupName, str
266266
return usageMetrics.Value;
267267
}
268268

269-
public ServerFarmWithRichSku CreateAppServicePlan(string resourceGroupName, string appServicePlanName, string location, string adminSiteName, SkuDescription sku)
269+
public ServerFarmWithRichSku CreateAppServicePlan(string resourceGroupName, string appServicePlanName, string location, string adminSiteName, SkuDescription sku, string aseName = null, string aseResourceGroupName = null)
270270
{
271271
var serverFarm = new ServerFarmWithRichSku
272272
{
@@ -275,6 +275,17 @@ public ServerFarmWithRichSku CreateAppServicePlan(string resourceGroupName, stri
275275
Sku = sku,
276276
AdminSiteName = adminSiteName
277277
};
278+
279+
if(!string.IsNullOrEmpty(aseName)
280+
&& !string.IsNullOrEmpty(aseResourceGroupName))
281+
{
282+
serverFarm.HostingEnvironmentProfile = new HostingEnvironmentProfile
283+
{
284+
Id = CmdletHelpers.GetApplicationServiceEnvironmentResourceId(WrappedWebsitesClient.SubscriptionId, aseResourceGroupName, aseName),
285+
Type = CmdletHelpers.ApplicationServiceEnvironmentResourcesName,
286+
Name = aseName
287+
};
288+
}
278289

279290
return WrappedWebsitesClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, appServicePlanName, serverFarm);
280291
}

0 commit comments

Comments
 (0)