Skip to content

Commit 592eaf7

Browse files
committed
Added New cmdlets
1 parent 36de8c3 commit 592eaf7

File tree

7 files changed

+297
-15
lines changed

7 files changed

+297
-15
lines changed

src/Resources/ResourceManager/Implementation/DeploymentStacks/GetAzDeploymentStack.cs renamed to src/Resources/ResourceManager/Implementation/DeploymentStacks/GetAzResourceGroupDeploymentStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Deploy
2020
using System.Text;
2121

2222
[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "DeploymentStack",
23-
DefaultParameterSetName = GetAzDeploymentStack.ListDeploymentStack), OutputType(typeof(PSDeploymentStack))]
24-
public class GetAzDeploymentStack : DeploymentStacksCmdletBase
23+
DefaultParameterSetName = GetAzResourceGroupDeploymentStack.ListDeploymentStack), OutputType(typeof(PSDeploymentStack))]
24+
public class GetAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
2525
{
2626
#region Cmdlet Parameters and Parameter Set Definitions
2727

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzDeploymentStack.cs renamed to src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzResourceGroupDeploymentStack.cs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
22
{
33
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
4+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
45
using System;
6+
using System.Collections;
57
using System.Collections.Generic;
8+
using System.IO;
69
using System.Management.Automation;
710
using System.Text;
11+
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
812

9-
[Cmdlet("New", Common.AzureRMConstants.AzureRMPrefix + "DeploymentStack",
10-
SupportsShouldProcess = true, DefaultParameterSetName = NewAzDeploymentStack.ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSDeploymentStack))]
11-
public class NewAzDeploymentStack : DeploymentStacksCmdletBase
13+
[Cmdlet("New", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStack",
14+
SupportsShouldProcess = true, DefaultParameterSetName = NewAzResourceGroupDeploymentStack.ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSDeploymentStack))]
15+
public class NewAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
1216
{
1317

1418
#region Cmdlet Parameters and Parameter Set Definitions
@@ -88,15 +92,48 @@ public override void ExecuteCmdlet()
8892
{
8993
try
9094
{
95+
Hashtable parameters = new Hashtable();
9196
switch (ParameterSetName)
9297
{
93-
default:
94-
throw new PSNotSupportedException();
98+
case ParameterlessTemplateFileParameterSetName:
99+
case ParameterUriTemplateFileParameterSetName:
100+
string filePath = this.TryResolvePath(TemplateFile);
101+
if(!File.Exists(filePath))
102+
{
103+
throw new PSInvalidOperationException(
104+
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
105+
}
106+
break;
107+
case ParameterFileTemplateSpecParameterSetName:
108+
case ParameterFileTemplateUriParameterSetName:
109+
parameters = this.GetParameterObject(ParameterFile);
110+
break;
111+
case ParameterFileTemplateFileParameterSetName:
112+
string templatePath = this.TryResolvePath(TemplateFile);
113+
if (!File.Exists(templatePath))
114+
{
115+
throw new PSInvalidOperationException(
116+
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
117+
}
118+
parameters = this.GetParameterObject(ParameterFile);
119+
break;
95120
}
121+
122+
var deploymentStack = DeploymentStacksSdkClient.ResourceGroupCreateOrUpdateDeploymentStack(
123+
Name,
124+
ResourceGroupName,
125+
TemplateUri,
126+
TemplateSpec,
127+
ParameterUri,
128+
parameters,
129+
Description
130+
);
131+
WriteObject(deploymentStack);
132+
96133
}
97-
catch
134+
catch (Exception ex)
98135
{
99-
136+
WriteExceptionError(ex);
100137
}
101138
}
102139

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2+
{
3+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
4+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
5+
using System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Management.Automation;
10+
using System.Text;
11+
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
12+
13+
[Cmdlet("New", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStack",
14+
SupportsShouldProcess = true, DefaultParameterSetName = NewAzSubscriptionDeploymentStack.ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSDeploymentStack))]
15+
public class NewAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
16+
{
17+
18+
#region Cmdlet Parameters and Parameter Set Definitions
19+
20+
internal const string ParameterlessTemplateFileParameterSetName = "ByTemplateFileWithNoParameters";
21+
internal const string ParameterlessTemplateUriParameterSetName = "ByTemplateUriWithNoParameters";
22+
internal const string ParameterlessTemplateSpecParameterSetName = "ByTemplateSpecWithNoParameters";
23+
24+
internal const string ParameterFileTemplateFileParameterSetName = "ByTemplateFileWithParameterFile";
25+
internal const string ParameterFileTemplateUriParameterSetName = "ByTemplateUriWithParameterFile";
26+
internal const string ParameterFileTemplateSpecParameterSetName = "ByTemplateSpecWithParameterFile";
27+
28+
internal const string ParameterUriTemplateFileParameterSetName = "ByTemplateFileWithParameterUri";
29+
internal const string ParameterUriTemplateUriParameterSetName = "ByTemplateUriWithParameterUri";
30+
internal const string ParameterUriTemplateSpecParameterSetName = "ByTemplateSpecWithParameterUri";
31+
32+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
33+
HelpMessage = "The name of the deploymentStack to create")]
34+
[ValidateNotNullOrEmpty]
35+
public string Name { get; set; }
36+
37+
[Parameter(Position = 1, ParameterSetName = ParameterFileTemplateFileParameterSetName,
38+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack")]
39+
[Parameter(Position = 1, ParameterSetName = ParameterUriTemplateFileParameterSetName,
40+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack")]
41+
[Parameter(Position = 1, ParameterSetName = ParameterlessTemplateFileParameterSetName,
42+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack")]
43+
public string TemplateFile { get; set; }
44+
45+
[Parameter(Position = 1, ParameterSetName = ParameterFileTemplateUriParameterSetName,
46+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack")]
47+
[Parameter(Position = 1, ParameterSetName = ParameterUriTemplateUriParameterSetName,
48+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack")]
49+
[Parameter(Position = 1, ParameterSetName = ParameterlessTemplateUriParameterSetName,
50+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack")]
51+
public string TemplateUri { get; set; }
52+
53+
[Parameter(Position = 1, ParameterSetName = ParameterFileTemplateSpecParameterSetName,
54+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack")]
55+
[Parameter(Position = 1, ParameterSetName = ParameterUriTemplateSpecParameterSetName,
56+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack")]
57+
[Parameter(Position = 1, ParameterSetName = ParameterlessTemplateSpecParameterSetName,
58+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack")]
59+
public string TemplateSpec { get; set; }
60+
61+
[Parameter(Position = 2, ParameterSetName = ParameterFileTemplateFileParameterSetName,
62+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template")]
63+
[Parameter(Position = 2, ParameterSetName = ParameterFileTemplateUriParameterSetName,
64+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template")]
65+
[Parameter(Position = 2, ParameterSetName = ParameterFileTemplateSpecParameterSetName,
66+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template")]
67+
public string ParameterFile { get; set; }
68+
69+
[Parameter(Position = 2, ParameterSetName = ParameterUriTemplateFileParameterSetName,
70+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template")]
71+
[Parameter(Position = 2, ParameterSetName = ParameterUriTemplateUriParameterSetName,
72+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template")]
73+
[Parameter(Position = 2, ParameterSetName = ParameterUriTemplateSpecParameterSetName,
74+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template")]
75+
public string ParameterUri { get; set; }
76+
77+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
78+
HelpMessage = "Description for the stack")]
79+
public string Description { get; set; }
80+
81+
#endregion
82+
83+
#region Cmdlet Overrides
84+
85+
public override void ExecuteCmdlet()
86+
{
87+
try
88+
{
89+
Hashtable parameters = new Hashtable();
90+
switch (ParameterSetName)
91+
{
92+
case ParameterlessTemplateFileParameterSetName:
93+
case ParameterUriTemplateFileParameterSetName:
94+
string filePath = this.TryResolvePath(TemplateFile);
95+
if (!File.Exists(filePath))
96+
{
97+
throw new PSInvalidOperationException(
98+
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
99+
}
100+
break;
101+
case ParameterFileTemplateSpecParameterSetName:
102+
case ParameterFileTemplateUriParameterSetName:
103+
parameters = this.GetParameterObject(ParameterFile);
104+
break;
105+
case ParameterFileTemplateFileParameterSetName:
106+
string templatePath = this.TryResolvePath(TemplateFile);
107+
if (!File.Exists(templatePath))
108+
{
109+
throw new PSInvalidOperationException(
110+
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
111+
}
112+
parameters = this.GetParameterObject(ParameterFile);
113+
break;
114+
}
115+
116+
var deploymentStack = DeploymentStacksSdkClient.SubscriptionCreateOrUpdateDeploymentStack(
117+
Name,
118+
TemplateUri,
119+
TemplateSpec,
120+
ParameterUri,
121+
parameters,
122+
Description
123+
);
124+
WriteObject(deploymentStack);
125+
126+
}
127+
catch (Exception ex)
128+
{
129+
WriteExceptionError(ex);
130+
}
131+
}
132+
133+
#endregion
134+
135+
}
136+
}

src/Resources/ResourceManager/ResourceManager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="AutoMapper" Version="6.2.2" />
16-
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.14.0-stacks" />
16+
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.14.2-stacks" />
1717
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
1818
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
1919
</ItemGroup>

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Microsoft.Azure.Management.ResourceManager.Models;
1313
using Newtonsoft.Json.Linq;
1414
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Json;
15+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
16+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1517

1618
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient
1719
{
@@ -41,11 +43,11 @@ public DeploymentStacksSdkClient(IAzureContext context)
4143
this.azureContext = context;
4244
}
4345

44-
public PSDeploymentStack GetDeploymentStack(string subscriptionName,
46+
public PSDeploymentStack GetResourceGroupDeploymentStack(
4547
string resourceGroupName,
4648
string deploymentStackName = null)
4749
{
48-
var deploymentStack = DeploymentStacksClient.DeploymentStacks.GetAtResourceGroup(subscriptionName, resourceGroupName, deploymentStackName);
50+
var deploymentStack = DeploymentStacksClient.DeploymentStacks.GetAtResourceGroup(resourceGroupName, deploymentStackName);
4951

5052
return new PSDeploymentStack(deploymentStack);
5153
}
@@ -99,7 +101,114 @@ string description
99101
: null;
100102
}
101103

102-
var deploymentStack = DeploymentStacksClient.DeploymentStacks.BeginCreateOrUpdateAtResourceGroup("subId", resourceGroupName, deploymentStackName, deploymentStackModel);
104+
105+
106+
var deploymentStack = DeploymentStacksClient.DeploymentStacks.BeginCreateOrUpdateAtResourceGroup(resourceGroupName, deploymentStackName, deploymentStackModel);
107+
return new PSDeploymentStack(deploymentStack);
108+
}
109+
110+
public PSDeploymentStack SubscriptionCreateOrUpdateDeploymentStack(
111+
string deploymentStackName,
112+
string templateUri,
113+
string templateSpec,
114+
string parameterUri,
115+
Hashtable parameters,
116+
string description
117+
)
118+
{
119+
var deploymentStackModel = new DeploymentStack
120+
{
121+
Description = description
122+
};
123+
124+
DeploymentStacksTemplateLink templateLink = new DeploymentStacksTemplateLink();
125+
if (templateSpec != null)
126+
{
127+
templateLink.Id = templateSpec;
128+
deploymentStackModel.TemplateLink = templateLink;
129+
}
130+
else if (Uri.IsWellFormedUriString(templateUri, UriKind.Absolute))
131+
{
132+
templateLink.Uri = templateUri;
133+
deploymentStackModel.TemplateLink = templateLink;
134+
}
135+
else
136+
{
137+
deploymentStackModel.Template = JObject.Parse(FileUtilities.DataStore.ReadFileAsText(templateUri));
138+
}
139+
140+
if (Uri.IsWellFormedUriString(parameterUri, UriKind.Absolute))
141+
{
142+
DeploymentStacksParametersLink parametersLink = new DeploymentStacksParametersLink();
143+
parametersLink.Uri = parameterUri;
144+
deploymentStackModel.ParametersLink = parametersLink;
145+
}
146+
147+
else if (parameters != null)
148+
{
149+
Dictionary<string, object> parametersDictionary = parameters?.ToDictionary(false);
150+
string parametersContent = parametersDictionary != null
151+
? PSJsonSerializer.Serialize(parametersDictionary)
152+
: null;
153+
deploymentStackModel.Parameters = !string.IsNullOrEmpty(parametersContent)
154+
? JObject.Parse(parametersContent)
155+
: null;
156+
}
157+
158+
var deploymentStack = DeploymentStacksClient.DeploymentStacks.BeginCreateOrUpdateAtSubscription(deploymentStackName, deploymentStackModel);
159+
return new PSDeploymentStack(deploymentStack);
160+
}
161+
162+
public PSDeploymentStack UpdateResourceGroupDeploymentStack(
163+
string deploymentStackName,
164+
string resourceGroupName,
165+
string templateUri,
166+
string templateSpec,
167+
string parameterUri,
168+
Hashtable parameters,
169+
string description
170+
)
171+
{
172+
var deploymentStackModel = new DeploymentStack
173+
{
174+
Description = description
175+
};
176+
177+
DeploymentStacksTemplateLink templateLink = new DeploymentStacksTemplateLink();
178+
if (templateSpec != null)
179+
{
180+
templateLink.Id = templateSpec;
181+
deploymentStackModel.TemplateLink = templateLink;
182+
}
183+
else if (Uri.IsWellFormedUriString(templateUri, UriKind.Absolute))
184+
{
185+
templateLink.Uri = templateUri;
186+
deploymentStackModel.TemplateLink = templateLink;
187+
}
188+
else
189+
{
190+
deploymentStackModel.Template = JObject.Parse(FileUtilities.DataStore.ReadFileAsText(templateUri));
191+
}
192+
193+
if (Uri.IsWellFormedUriString(parameterUri, UriKind.Absolute))
194+
{
195+
DeploymentStacksParametersLink parametersLink = new DeploymentStacksParametersLink();
196+
parametersLink.Uri = parameterUri;
197+
deploymentStackModel.ParametersLink = parametersLink;
198+
}
199+
200+
else if (parameters != null)
201+
{
202+
Dictionary<string, object> parametersDictionary = parameters?.ToDictionary(false);
203+
string parametersContent = parametersDictionary != null
204+
? PSJsonSerializer.Serialize(parametersDictionary)
205+
: null;
206+
deploymentStackModel.Parameters = !string.IsNullOrEmpty(parametersContent)
207+
? JObject.Parse(parametersContent)
208+
: null;
209+
}
210+
211+
var deploymentStack = DeploymentStacksClient.DeploymentStacks.BeginCreateOrUpdateAtResourceGroup(resourceGroupName, deploymentStackName, deploymentStackModel);
103212
return new PSDeploymentStack(deploymentStack);
104213
}
105214
}

src/Resources/Resources.Test/Resources.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</ItemGroup>
3333

3434
<ItemGroup>
35-
<PackageReference Update="Microsoft.Azure.Management.ResourceManager" Version="3.14.0-stacks" />
35+
<PackageReference Update="Microsoft.Azure.Management.ResourceManager" Version="3.14.2-stacks" />
3636
</ItemGroup>
3737
<ItemGroup>
3838
<PackageReference Include="FluentAssertions" Version="5.9.0" />

src/Resources/Resources/Resources.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.8.0-preview" />
1515
<PackageReference Include="Microsoft.Azure.Management.Authorization" Version="2.12.0-preview" />
1616
<PackageReference Include="Microsoft.Azure.Management.ManagementGroups" Version="1.1.1-preview" />
17-
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.14.0-stacks" />
17+
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.14.2-stacks" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

0 commit comments

Comments
 (0)