Skip to content

Commit 0ea9a21

Browse files
committed
Add remaining cmdlets
1 parent 592eaf7 commit 0ea9a21

13 files changed

+1001
-4
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
1+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
3+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
24
using Microsoft.Azure.Commands.ResourceManager.Common;
5+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
36
using System;
7+
using System.Collections;
48
using System.Collections.Generic;
59
using System.Text;
610

@@ -32,5 +36,30 @@ public DeploymentStacksSdkClient DeploymentStacksSdkClient
3236
this.deploymentStacksSdkClient = value;
3337
}
3438
}
39+
40+
protected Hashtable GetParameterObject(string parameterFile)
41+
{
42+
var parameters = new Hashtable();
43+
string templateParameterFilePath = this.ResolvePath(parameterFile);
44+
if (parameterFile != null && FileUtilities.DataStore.FileExists(parameterFile))
45+
{
46+
var parametersFromFile = TemplateUtility.ParseTemplateParameterFileContents(templateParameterFilePath);
47+
parametersFromFile.ForEach(dp =>
48+
{
49+
var parameter = new Hashtable();
50+
if (dp.Value.Value != null)
51+
{
52+
parameter.Add("value", dp.Value.Value);
53+
}
54+
if (dp.Value.Reference != null)
55+
{
56+
parameter.Add("reference", dp.Value.Reference);
57+
}
58+
59+
parameters[dp.Key] = parameter;
60+
});
61+
}
62+
return parameters;
63+
}
3564
}
3665
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.DeploymentStacks
16+
{
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Management.Automation;
20+
using System.Text;
21+
22+
[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "DeploymentStack",
23+
DefaultParameterSetName = GetAzResourceGroupDeploymentStackSnapshot.ListDeploymentStack), OutputType(typeof(PSDeploymentStack))]
24+
public class GetAzResourceGroupDeploymentStackSnapshot : DeploymentStacksCmdletBase
25+
{
26+
#region Cmdlet Parameters and Parameter Set Definitions
27+
28+
internal const string ListDeploymentStack = "ListDeploymentStack";
29+
30+
31+
#endregion
32+
33+
}
34+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Management.Automation;
6+
using System.Text;
7+
8+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
9+
{
10+
[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStack",
11+
DefaultParameterSetName = GetAzSubscriptionDeploymentStack.ListParameterSetname), OutputType(typeof(PSDeploymentStack))]
12+
class GetAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
13+
{
14+
#region Cmdlet Parameters and Parameter Set Definitions
15+
16+
internal const string GetByStackNameParameterSetname = "GetIndividualDeploymentStack";
17+
internal const string GetByResourceIdParameterSetName = "GetDeploymentStackByResourceId";
18+
internal const string ListParameterSetname = "ListDeploymentStacks";
19+
20+
[Alias("StackName")]
21+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByStackNameParameterSetname,
22+
HelpMessage = "The name of the deploymentStack to get")]
23+
[ValidateNotNullOrEmpty]
24+
public string Name { get; set; }
25+
26+
[Alias("Id")]
27+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByResourceIdParameterSetName,
28+
HelpMessage = "ResourceId of the stack to get")]
29+
[ValidateNotNullOrEmpty]
30+
public string ResourceId { get; set; }
31+
32+
#endregion
33+
34+
#region Cmdlet Overrides
35+
36+
public override void ExecuteCmdlet()
37+
{
38+
try
39+
{
40+
switch (ParameterSetName)
41+
{
42+
case GetByStackNameParameterSetname:
43+
WriteObject(DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(Name));
44+
break;
45+
case GetByResourceIdParameterSetName:
46+
WriteObject(DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(ResourceIdUtility.GetResourceName(ResourceId)));
47+
break;
48+
case ListParameterSetname:
49+
WriteObject(DeploymentStacksSdkClient.ListSubscriptionDeploymentStack());
50+
break;
51+
default:
52+
throw new PSInvalidOperationException();
53+
}
54+
}
55+
catch (Exception ex)
56+
{
57+
WriteExceptionError(ex);
58+
}
59+
}
60+
61+
#endregion
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Management.Automation;
6+
using System.Text;
7+
8+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
9+
{
10+
[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStackSnapshot",
11+
DefaultParameterSetName = GetAzSubscriptionDeploymentStack.ListParameterSetname), OutputType(typeof(PSDeploymentStackSnapshot))]
12+
class GetAzSubscriptionDeploymentStackSnapshot : DeploymentStacksCmdletBase
13+
{
14+
#region Cmdlet Parameters and Parameter Set Definitions
15+
16+
internal const string GetByStackNameParameterSetname = "GetIndividualDeploymentStack";
17+
internal const string GetByResourceIdParameterSetName = "GetDeploymentStackByResourceId";
18+
internal const string ListParameterSetname = "ListDeploymentStacks";
19+
20+
[Alias("StackName")]
21+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByStackNameParameterSetname,
22+
HelpMessage = "The name of the deploymentStack to get")]
23+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ListParameterSetname,
24+
HelpMessage = "The name of the deploymentStack to get")]
25+
[ValidateNotNullOrEmpty]
26+
public string Name { get; set; }
27+
28+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByStackNameParameterSetname,
29+
HelpMessage = "The name of the deploymentStack to get")]
30+
[ValidateNotNullOrEmpty]
31+
public string SnapshotName { get; set; }
32+
33+
[Alias("Id")]
34+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByResourceIdParameterSetName,
35+
HelpMessage = "ResourceId of the stack to get")]
36+
[ValidateNotNullOrEmpty]
37+
public string ResourceId { get; set; }
38+
39+
#endregion
40+
41+
#region Cmdlet Overrides
42+
43+
public override void ExecuteCmdlet()
44+
{
45+
try
46+
{
47+
switch (ParameterSetName)
48+
{
49+
case GetByStackNameParameterSetname:
50+
WriteObject(DeploymentStacksSdkClient.GetSubscriptionDeploymentStackSnapshot(Name, SnapshotName));
51+
break;
52+
case GetByResourceIdParameterSetName:
53+
WriteObject(DeploymentStacksSdkClient.GetSubscriptionDeploymentStackSnapshot(ResourceIdUtility.GetResourceName(ResourceId)));
54+
break;
55+
case ListParameterSetname:
56+
WriteObject(DeploymentStacksSdkClient.ListSubscriptionDeploymentStackSnapshot(Name));
57+
break;
58+
default:
59+
throw new PSInvalidOperationException();
60+
}
61+
}
62+
catch (Exception ex)
63+
{
64+
WriteExceptionError(ex);
65+
}
66+
}
67+
68+
#endregion
69+
}
70+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Management.Automation;
5+
using System.Text;
6+
7+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
8+
{
9+
[Cmdlet("Remove", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStack",
10+
SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzResourceGroupDeploymentStack.RemoveByResourceIdParameterSetName), OutputType(typeof(bool))]
11+
public class RemoveAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
12+
{
13+
#region Cmdlet Parameters and Parameter Set Definitions
14+
15+
internal const string RemoveByResourceIdParameterSetName = "RemoveByResourceId";
16+
internal const string RemoveByResourceNameParameterSetname = "RemoveByResourceName";
17+
18+
[Alias("StackName")]
19+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByResourceNameParameterSetname,
20+
HelpMessage = "The name of the deploymentStack to delete")]
21+
[ValidateNotNullOrEmpty]
22+
public string Name { get; set; }
23+
24+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByResourceNameParameterSetname,
25+
HelpMessage = "The name of the Resource Group with the stack to delete")]
26+
[ValidateNotNullOrEmpty]
27+
public string ResourceGroupName { get; set; }
28+
29+
[Alias("Id")]
30+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByResourceIdParameterSetName,
31+
HelpMessage = "ResourceId of the stack to delete")]
32+
[ValidateNotNullOrEmpty]
33+
public string ResourceId { get; set; }
34+
35+
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
36+
public SwitchParameter Force { get; set; }
37+
38+
#endregion
39+
40+
#region Cmdlet Overrides
41+
42+
public override void ExecuteCmdlet()
43+
{
44+
try
45+
{
46+
ResourceIdentifier resourceIdentifier = (ResourceId != null)
47+
? new ResourceIdentifier(ResourceId)
48+
: null;
49+
50+
ResourceGroupName = ResourceGroupName ?? resourceIdentifier.ResourceGroupName;
51+
Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId);
52+
53+
string confirmationMessage = $"Are you sure you want to remove DeploymentStack '{Name}'";
54+
55+
ConfirmAction(
56+
Force.IsPresent,
57+
confirmationMessage,
58+
"Deleting Deployment Stack ...",
59+
Name,
60+
() => DeploymentStacksSdkClient.DeleteResourceGroupDeploymentStack(ResourceGroupName, Name)
61+
);
62+
63+
WriteObject(true);
64+
}
65+
catch (Exception ex)
66+
{
67+
WriteExceptionError(ex);
68+
}
69+
}
70+
71+
#endregion
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Management.Automation;
5+
using System.Text;
6+
7+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
8+
{
9+
[Cmdlet("Remove", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStack",
10+
SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzResourceGroupDeploymentStackSnapshot.RemoveByResourceIdParameterSetName), OutputType(typeof(bool))]
11+
public class RemoveAzResourceGroupDeploymentStackSnapshot : DeploymentStacksCmdletBase
12+
{
13+
#region Cmdlet Parameters and Parameter Set Definitions
14+
15+
internal const string RemoveByResourceIdParameterSetName = "RemoveByResourceId";
16+
internal const string RemoveByResourceNameParameterSetname = "RemoveByResourceName";
17+
18+
[Alias("StackName")]
19+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByResourceNameParameterSetname,
20+
HelpMessage = "The name of the deploymentStack to delete")]
21+
[ValidateNotNullOrEmpty]
22+
public string Name { get; set; }
23+
24+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByResourceNameParameterSetname,
25+
HelpMessage = "The name of the deploymentStack snapshot to delete")]
26+
[ValidateNotNullOrEmpty]
27+
public string SnapshotName { get; set; }
28+
29+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByResourceNameParameterSetname,
30+
HelpMessage = "The name of the Resource Group with the stack to delete")]
31+
[ValidateNotNullOrEmpty]
32+
public string ResourceGroupName { get; set; }
33+
34+
[Alias("Id")]
35+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByResourceIdParameterSetName,
36+
HelpMessage = "ResourceId of the stack to delete")]
37+
[ValidateNotNullOrEmpty]
38+
public string ResourceId { get; set; }
39+
40+
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
41+
public SwitchParameter Force { get; set; }
42+
43+
#endregion
44+
45+
#region Cmdlet Overrides
46+
47+
public override void ExecuteCmdlet()
48+
{
49+
try
50+
{
51+
ResourceIdentifier resourceIdentifier = (ResourceId != null)
52+
? new ResourceIdentifier(ResourceId)
53+
: null;
54+
55+
ResourceGroupName = ResourceGroupName ?? resourceIdentifier.ResourceGroupName;
56+
Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId);
57+
SnapshotName = SnapshotName ?? resourceIdentifier.ResourceName;
58+
59+
string confirmationMessage = $"Are you sure you want to remove snapshot '{SnapshotName}' of DeploymentStack '{Name}'";
60+
61+
ConfirmAction(
62+
Force.IsPresent,
63+
confirmationMessage,
64+
"Deleting Deployment Stack Snapshot...",
65+
Name,
66+
() => DeploymentStacksSdkClient.DeleteResourceGroupDeploymentStackSnapshot(ResourceGroupName, Name, SnapshotName)
67+
);
68+
69+
WriteObject(true);
70+
}
71+
catch (Exception ex)
72+
{
73+
WriteExceptionError(ex);
74+
}
75+
}
76+
77+
#endregion
78+
}
79+
}

0 commit comments

Comments
 (0)