Skip to content

Commit f904d89

Browse files
authored
Merge pull request #10798 from Tiano2017/tiano-deployment-refactor
Refactor template deployment cmdlets.
2 parents 3cf6204 + 2f6f657 commit f904d89

File tree

107 files changed

+253878
-219065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+253878
-219065
lines changed

src/Blueprint/Blueprint.Test/Blueprint.Test.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@
2525
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2626
</None>
2727
</ItemGroup>
28-
2928
</Project>

src/Resources/ResourceManager/Components/Constants.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public static class Constants
3434
/// </summary>
3535
public static readonly string MicrosoftManagementNamespace = "Microsoft.Management";
3636

37+
/// <summary>
38+
/// The string literal <c>ManagementGroups</c>
39+
/// </summary>
40+
public static readonly string ManagementGroups = "managementGroups";
41+
42+
/// <summary>
43+
/// The management group id prefix.
44+
/// </summary>
45+
public static readonly string ManagementGroupIdPrefix = $"/providers/{Constants.MicrosoftManagementNamespace}/{Constants.ManagementGroups}/";
46+
3747
/// <summary>
3848
/// The <c>Microsoft.Solutions</c> namespace.
3949
/// </summary>
@@ -144,11 +154,6 @@ public static class Constants
144154
/// </summary>
145155
public static readonly string MicrosoftAuthorizationPolicyAssignmentType = Constants.MicrosoftAuthorizationNamespace + "/policyassignments";
146156

147-
/// <summary>
148-
/// The management group resource type.
149-
/// </summary>
150-
public static readonly string MicrosoftManagementGroupDefinitionType = Constants.MicrosoftManagementNamespace + "/managementgroups";
151-
152157
/// <summary>
153158
/// The application definition resource type.
154159
/// </summary>

src/Resources/ResourceManager/Components/ResourceIdUtility.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ public static string GetProviderNamespace(string resourceId)
179179
return ResourceIdUtility.GetNextSegmentAfter(resourceId: resourceId, segmentName: Constants.Providers);
180180
}
181181

182+
/// <summary>
183+
/// Gets the management group id from the resource id.
184+
/// </summary>
185+
/// <param name="resourceId">The resource id.</param>
186+
public static string GetManagementGroupId(string resourceId)
187+
{
188+
return resourceId.StartsWithInsensitively(Constants.ManagementGroupIdPrefix)
189+
? ResourceIdUtility.GetNextSegmentAfter(resourceId: resourceId, segmentName: Constants.ManagementGroups)
190+
: null;
191+
}
192+
182193
/// <summary>
183194
/// Gets the subscription id from the resource id.
184195
/// </summary>
@@ -247,6 +258,15 @@ public static string GetResourceName(string resourceId)
247258
return ResourceIdUtility.GetResourceTypeOrName(resourceId: resourceId, getResourceName: true);
248259
}
249260

261+
/// <summary>
262+
/// Gets the deployment name
263+
/// </summary>
264+
/// <param name="resourceId">The resource Id.</param>
265+
public static string GetDeploymentName(string resourceId)
266+
{
267+
return ResourceIdUtility.GetResourceTypeOrName(resourceId: resourceId, getResourceName: true, useLastSegment: true);
268+
}
269+
250270
/// <summary>
251271
/// Gets the extension provider namespace from the resource id.
252272
/// </summary>

src/Resources/ResourceManager/Implementation/CmdletBase/ResourceWithParameterCmdletBase.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.Common.Authentication;
16-
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
18-
using Microsoft.WindowsAzure.Commands.Common;
19-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2015
using System;
2116
using System.Collections;
2217
using System.Collections.Generic;
2318
using System.Linq;
2419
using System.Management.Automation;
20+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
21+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
22+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2523

2624
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2725
{
@@ -39,7 +37,6 @@ public abstract class ResourceWithParameterCmdletBase : ResourceManagerCmdletBas
3937
protected const string TemplateUriParameterFileParameterSetName = "ByTemplateUriAndParameterFile";
4038
protected const string TemplateUriParameterUriParameterSetName = "ByTemplateUriAndParameterUri";
4139

42-
protected const string ParameterlessGalleryTemplateParameterSetName = "ByGalleryWithNoParameters";
4340
protected const string ParameterlessTemplateObjectParameterSetName = "ByTemplateObjectWithNoParameters";
4441
protected const string ParameterlessTemplateFileParameterSetName = "ByTemplateFileWithNoParameters";
4542
protected const string ParameterlessTemplateUriParameterSetName = "ByTemplateUriWithNoParameters";
@@ -126,8 +123,7 @@ public object GetDynamicParameters()
126123
{
127124
if (!this.IsParameterBound(c => c.SkipTemplateParameterPrompt))
128125
{
129-
if (TemplateObject != null &&
130-
TemplateObject != templateObject)
126+
if (TemplateObject != null && TemplateObject != templateObject)
131127
{
132128
templateObject = TemplateObject;
133129
if (string.IsNullOrEmpty(TemplateParameterUri))
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.ResourceManager.Cmdlets.Components;
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
18+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
19+
using Microsoft.Azure.Commands.ResourceManager.Common;
20+
21+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
22+
{
23+
/// <summary>
24+
/// Get deployments.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, AzureRMConstants.AzureRMPrefix + "ManagementGroupDeployment", DefaultParameterSetName = GetAzureManagementGroupDeploymentCmdlet.DeploymentNameParameterSet), OutputType(typeof(PSDeployment))]
27+
public class GetAzureManagementGroupDeploymentCmdlet : ResourceManagerCmdletBase
28+
{
29+
/// <summary>
30+
/// The deployment Id parameter set.
31+
/// </summary>
32+
internal const string DeploymentIdParameterSet = "GetByDeploymentId";
33+
34+
/// <summary>
35+
/// The deployment name parameter set.
36+
/// </summary>
37+
internal const string DeploymentNameParameterSet = "GetByDeploymentName";
38+
39+
[Parameter(Position = 0, ParameterSetName = GetAzureManagementGroupDeploymentCmdlet.DeploymentNameParameterSet, Mandatory = true,
40+
HelpMessage = "The management group id.")]
41+
[ValidateNotNullOrEmpty]
42+
public string ManagementGroupId { get; set; }
43+
44+
[Alias("DeploymentName")]
45+
[Parameter(Position = 1, ParameterSetName = GetAzureManagementGroupDeploymentCmdlet.DeploymentNameParameterSet, Mandatory = false,
46+
HelpMessage = "The name of deployment.")]
47+
[ValidateNotNullOrEmpty]
48+
public string Name { get; set; }
49+
50+
[Alias("DeploymentId", "ResourceId")]
51+
[Parameter(ParameterSetName = GetAzureManagementGroupDeploymentCmdlet.DeploymentIdParameterSet, Mandatory = true,
52+
HelpMessage = "The fully qualified resource Id of the deployment. example: /providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Resources/deployments/{deploymentName}")]
53+
[ValidateNotNullOrEmpty]
54+
public string Id { get; set; }
55+
56+
public override void ExecuteCmdlet()
57+
{
58+
FilterDeploymentOptions options = new FilterDeploymentOptions(DeploymentScopeType.ManagementGroup)
59+
{
60+
ManagementGroupId = this.ManagementGroupId ?? ResourceIdUtility.GetManagementGroupId(this.Id),
61+
DeploymentName = this.Name ?? (string.IsNullOrEmpty(this.Id) ? null : ResourceIdUtility.GetDeploymentName(this.Id))
62+
};
63+
64+
WriteObject(ResourceManagerSdkClient.FilterDeployments(options), true);
65+
}
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.Implementation
16+
{
17+
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
19+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
20+
using Microsoft.Azure.Commands.ResourceManager.Common;
21+
22+
/// <summary>
23+
/// Gets the deployment operation.
24+
/// </summary>
25+
[Cmdlet(VerbsCommon.Get, AzureRMConstants.AzureRMPrefix + "ManagementGroupDeploymentOperation",
26+
DefaultParameterSetName = GetAzureManagementGroupDeploymentOperationCmdlet.DeploymentNameParameterSet), OutputType(typeof(PSDeploymentOperation))]
27+
public class GetAzureManagementGroupDeploymentOperationCmdlet : ResourceManagerCmdletBase
28+
{
29+
/// <summary>
30+
/// The deployment name parameter set.
31+
/// </summary>
32+
internal const string DeploymentNameParameterSet = "GetByDeploymentName";
33+
34+
/// <summary>
35+
/// The deployment object parameter set.
36+
/// </summary>
37+
internal const string DeploymentObjectParameterSet = "GetByDeploymentObject";
38+
39+
/// <summary>
40+
/// Gets or sets the management group id parameter.
41+
/// </summary>
42+
[Parameter(ParameterSetName = GetAzureManagementGroupDeploymentOperationCmdlet.DeploymentNameParameterSet,
43+
Mandatory = true, HelpMessage = "The management group id.")]
44+
[ValidateNotNullOrEmpty]
45+
public string ManagementGroupId { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the deployment name parameter.
49+
/// </summary>
50+
[Parameter(ParameterSetName = GetAzureManagementGroupDeploymentOperationCmdlet.DeploymentNameParameterSet,
51+
Mandatory = true, HelpMessage = "The deployment name.")]
52+
[ValidateNotNullOrEmpty]
53+
public string DeploymentName { get; set; }
54+
55+
/// <summary>
56+
/// Gets or sets the deployment operation Id.
57+
/// </summary>
58+
[Parameter(ParameterSetName = GetAzureManagementGroupDeploymentOperationCmdlet.DeploymentNameParameterSet,
59+
Mandatory = false, HelpMessage = "The deployment operation Id.")]
60+
public string OperationId { get; set; }
61+
62+
[Parameter(ParameterSetName = GetAzureManagementGroupDeploymentOperationCmdlet.DeploymentObjectParameterSet,
63+
Mandatory = true, ValueFromPipeline = true, HelpMessage = "The deployment object.")]
64+
public PSDeployment DeploymentObject { get; set; }
65+
66+
public override void ExecuteCmdlet()
67+
{
68+
var options = new FilterDeploymentOptions(DeploymentScopeType.ManagementGroup)
69+
{
70+
ManagementGroupId = !string.IsNullOrEmpty(this.ManagementGroupId) ? this.ManagementGroupId : this.DeploymentObject.ManagementGroupId,
71+
DeploymentName = !string.IsNullOrEmpty(this.DeploymentName) ? this.DeploymentName : this.DeploymentObject.DeploymentName
72+
};
73+
74+
var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtManagementGroup(
75+
options.ManagementGroupId, options.DeploymentName, this.OperationId);
76+
77+
WriteObject(deploymentOperations, true);
78+
}
79+
}
80+
}

src/Resources/ResourceManager/Implementation/Deployments/GetAzureDeploymentCmdlet.cs renamed to src/Resources/ResourceManager/Implementation/Deployments/GetAzureSubscriptionDeploymentCmdlet.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
using System.Management.Automation;
1616
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
1717
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
18-
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
18+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
19+
using Microsoft.Azure.Commands.ResourceManager.Common;
1920

2021
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2122
{
2223
/// <summary>
2324
/// Get deployments.
2425
/// </summary>
25-
[CmdletDeprecation(ReplacementCmdletName = "Get-AzSubscriptionDeployment")]
26-
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Deployment", DefaultParameterSetName = GetAzureDeploymentCmdlet.DeploymentNameParameterSet), OutputType(typeof(PSDeployment))]
27-
public class GetAzureDeploymentCmdlet : ResourceManagerCmdletBase
26+
[Cmdlet(VerbsCommon.Get, AzureRMConstants.AzureRMPrefix + "Deployment", DefaultParameterSetName = GetAzureSubscriptionDeploymentCmdlet.DeploymentNameParameterSet), OutputType(typeof(PSDeployment))]
27+
[Alias("Get-AzSubscriptionDeployment")]
28+
public class GetAzureSubscriptionDeploymentCmdlet : ResourceManagerCmdletBase
2829
{
2930
/// <summary>
3031
/// The deployment Id parameter set.
@@ -37,25 +38,25 @@ public class GetAzureDeploymentCmdlet : ResourceManagerCmdletBase
3738
internal const string DeploymentNameParameterSet = "GetByDeploymentName";
3839

3940
[Alias("DeploymentName")]
40-
[Parameter(Position = 0, ParameterSetName = GetAzureDeploymentCmdlet.DeploymentNameParameterSet, Mandatory = false,
41+
[Parameter(Position = 0, ParameterSetName = GetAzureSubscriptionDeploymentCmdlet.DeploymentNameParameterSet, Mandatory = false,
4142
HelpMessage = "The name of deployment.")]
4243
[ValidateNotNullOrEmpty]
4344
public string Name { get; set; }
4445

4546
[Alias("DeploymentId", "ResourceId")]
46-
[Parameter(ParameterSetName = GetAzureDeploymentCmdlet.DeploymentIdParameterSet, Mandatory = false,
47+
[Parameter(ParameterSetName = GetAzureSubscriptionDeploymentCmdlet.DeploymentIdParameterSet, Mandatory = true,
4748
HelpMessage = "The fully qualified resource Id of the deployment. example: /subscriptions/{subId}/providers/Microsoft.Resources/deployments/{deploymentName}")]
4849
[ValidateNotNullOrEmpty]
4950
public string Id { get; set; }
5051

5152
public override void ExecuteCmdlet()
5253
{
53-
FilterDeploymentOptions options = new FilterDeploymentOptions()
54+
FilterDeploymentOptions options = new FilterDeploymentOptions(DeploymentScopeType.Subscription)
5455
{
55-
DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id))
56+
DeploymentName = this.Name ?? (string.IsNullOrEmpty(this.Id) ? null : ResourceIdUtility.GetResourceName(this.Id))
5657
};
5758

58-
WriteObject(ResourceManagerSdkClient.FilterDeploymentsAtSubscriptionScope(options), true);
59+
WriteObject(ResourceManagerSdkClient.FilterDeployments(options), true);
5960
}
6061
}
6162
}

src/Resources/ResourceManager/Implementation/Deployments/GetAzureDeploymentOperationCmdlet.cs renamed to src/Resources/ResourceManager/Implementation/Deployments/GetAzureSubscriptionDeploymentOperationCmdlet.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1616
{
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
19-
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
2019

2120
/// <summary>
2221
/// Gets the deployment operation.
2322
/// </summary>
24-
[CmdletDeprecation(ReplacementCmdletName = "Get-AzSubscriptionDeploymentOperation")]
25-
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "DeploymentOperation", DefaultParameterSetName = GetAzureDeploymentOperationCmdlet.DeploymentNameParameterSet), OutputType(typeof(PSDeploymentOperation))]
26-
public class GetAzureDeploymentOperationCmdlet : ResourceManagerCmdletBase
23+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "DeploymentOperation", DefaultParameterSetName = GetAzureSubscriptionDeploymentOperationCmdlet.DeploymentNameParameterSet), OutputType(typeof(PSDeploymentOperation))]
24+
[Alias("Get-AzSubscriptionDeploymentOperation")]
25+
public class GetAzureSubscriptionDeploymentOperationCmdlet : ResourceManagerCmdletBase
2726
{
2827
/// <summary>
2928
/// The deployment name parameter set.
@@ -38,17 +37,17 @@ public class GetAzureDeploymentOperationCmdlet : ResourceManagerCmdletBase
3837
/// <summary>
3938
/// Gets or sets the deployment name parameter.
4039
/// </summary>
41-
[Parameter(ParameterSetName = GetAzureDeploymentOperationCmdlet.DeploymentNameParameterSet, Mandatory = true, HelpMessage = "The deployment name.")]
40+
[Parameter(ParameterSetName = GetAzureSubscriptionDeploymentOperationCmdlet.DeploymentNameParameterSet, Mandatory = true, HelpMessage = "The deployment name.")]
4241
[ValidateNotNullOrEmpty]
4342
public string DeploymentName { get; set; }
4443

4544
/// <summary>
4645
/// Gets or sets the deployment operation Id.
4746
/// </summary>
48-
[Parameter(ParameterSetName = GetAzureDeploymentOperationCmdlet.DeploymentNameParameterSet, Mandatory = false, HelpMessage = "The deployment operation Id.")]
47+
[Parameter(ParameterSetName = GetAzureSubscriptionDeploymentOperationCmdlet.DeploymentNameParameterSet, Mandatory = false, HelpMessage = "The deployment operation Id.")]
4948
public string OperationId { get; set; }
5049

51-
[Parameter(ParameterSetName = GetAzureDeploymentOperationCmdlet.DeploymentObjectParameterSet, Mandatory = true,
50+
[Parameter(ParameterSetName = GetAzureSubscriptionDeploymentOperationCmdlet.DeploymentObjectParameterSet, Mandatory = true,
5251
ValueFromPipeline = true, HelpMessage = "The deployment object.")]
5352
public PSDeployment DeploymentObject { get; set; }
5453

0 commit comments

Comments
 (0)