Skip to content

HPF PR: dev <- Azure:dev #471

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 3 commits into from
Mar 16, 2016
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 @@ -136,6 +136,7 @@
<Compile Include="Handlers\CmdletInfoHandler.cs" />
<Compile Include="Handlers\UserAgentHandler.cs" />
<Compile Include="Implementation\FindAzureResourceGroupCmdlet.cs" />
<Compile Include="Implementation\SaveAzureResourceGroupDeploymentTemplateCmdlet.cs" />
<Compile Include="Implementation\GetAzureResourceGroupDeploymentOperationCmdlet.cs" />
<Compile Include="Implementation\Lock\GetAzureResourceLockCmdlet.cs" />
<Compile Include="Implementation\InvokeAzureResourceActionCmdlet.cs" />
Expand Down Expand Up @@ -170,8 +171,14 @@
<Compile Include="Json\TimeSpanConverter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Implementation\Resource\GetAzureResourceCmdlet.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="RestClients\ResourceManagerRestClientBase.cs" />
<Compile Include="RestClients\ResourceManagerRestRestClient.cs" />
<Compile Include="Utilities\FileUtility.cs" />
<Compile Include="Utilities\HttpUtility.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -207,5 +214,12 @@
<Name>Commands.Tags</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public static class Constants
/// </summary>
public static readonly string MoveResources = "moveResources";

/// <summary>
/// The export action.
/// </summary>
public static readonly string ExportTemplate = "exportTemplate";

/// <summary>
/// The locks resource type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmdletBase
{
/// <summary>
/// Gets or sets the resource group name parameter.
/// Gets or sets the deployment name parameter.
/// </summary>
[Alias("Name")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment name.")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// ----------------------------------------------------------------------------------
//
// 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.Implementation
{
using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Newtonsoft.Json.Linq;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;

/// <summary>
/// Saves the deployment template to a file on disk.
/// </summary>
[Cmdlet(VerbsData.Save, "AzureRmResourceGroupDeploymentTemplate"), OutputType(typeof(PSObject))]
public class GetAzureResourceGroupDeploymentTemplateCmdlet : ResourceManagerCmdletBase
{
/// <summary>
/// Gets or sets the resource group name parameter.
/// </summary>
[Alias("ResourceGroup")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

/// <summary>
/// Gets or sets the deployment name parameter.
/// </summary>
[Alias("Name")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment name.")]
[ValidateNotNullOrEmpty]
public string DeploymentName { get; set; }

/// <summary>
/// Gets or sets the file path.
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The output path of the template file.")]
[ValidateNotNullOrEmpty]
public string Path { get; set; }

/// <summary>
/// Gets or sets the force parameter.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
public SwitchParameter Force { get; set; }

/// <summary>
/// Executes the cmdlet.
/// </summary>
protected override void OnProcessRecord()
{
base.OnProcessRecord();

var resourceId = this.GetResourceId();

var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;

var operationResult = this.GetResourcesClient()
.InvokeActionOnResource<JObject>(
resourceId: resourceId,
action: Constants.ExportTemplate,
apiVersion: apiVersion,
cancellationToken: this.CancellationToken.Value)
.Result;

var managementUri = this.GetResourcesClient()
.GetResourceManagementRequestUri(
resourceId: resourceId,
apiVersion: apiVersion,
action: Constants.ExportTemplate);

var activity = string.Format("POST {0}", managementUri.PathAndQuery);
var resultString = this.GetLongRunningOperationTracker(activityName: activity, isResourceCreateOrUpdate: false)
.WaitOnOperation(operationResult: operationResult);

var template = JToken.FromObject(JObject.Parse(resultString)["template"]);

string path = FileUtility.SaveTemplateFile(
deploymentName: this.DeploymentName,
contents: template.ToString(),
outputPath: string.IsNullOrEmpty(this.Path) ? System.IO.Path.Combine(CurrentPath(), this.DeploymentName) : this.TryResolvePath(this.Path),
overwrite: this.Force,
confirmAction: ConfirmAction);

WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", path));
}

/// <summary>
/// Gets the resource Id from the supplied PowerShell parameters.
/// </summary>
protected string GetResourceId()
{
return ResourceIdUtility.GetResourceId(
subscriptionId: DefaultContext.Subscription.Id,
resourceGroupName: this.ResourceGroupName,
resourceType: Constants.MicrosoftResourcesDeploymentType,
resourceName: this.DeploymentName);
}
}
}
Loading