Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -25,7 +25,7 @@ public abstract class ResourceManagerCmdletBaseWithApiVersion : ResourceManagerC
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "When set, indicates the version of the resource provider API to use. If not specified, the API version is automatically determined as the latest available.")]
[ValidateNotNullOrEmpty]
public string ApiVersion { get; set; }
public virtual string ApiVersion { get; set; }

private Dictionary<string, string> GetCmdletHeaders()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ResourceIds;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
using Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01.Models;
Comment thread
isra-fel marked this conversation as resolved.
Outdated
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Newtonsoft.Json.Linq;
using System;
Expand Down Expand Up @@ -93,63 +96,90 @@ public class ExportAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVe
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
public SwitchParameter Force { get; set; }

/// <summary>
/// Gets or sets the API version.
/// </summary>
[CmdletParameterBreakingChange("ApiVersion", ChangeDescription = "Parameter is being deprecated without being replaced")]
Comment thread
isra-fel marked this conversation as resolved.
Outdated
[Parameter(Mandatory = false, HelpMessage = "When set, indicates the version of the resource provider API to use. If not specified, the API version is automatically determined as the latest available.")]
[ValidateNotNullOrEmpty]
public override string ApiVersion { get; set; }

/// <summary>
/// Executes the cmdlet.
/// </summary>
protected override void OnProcessRecord()
{
base.OnProcessRecord();
String contents;
Comment thread
isra-fel marked this conversation as resolved.
Outdated

if (ShouldProcess(ResourceGroupName, VerbsData.Export))
{

var resourceGroupId = this.GetResourceGroupId();

var apiVersion = this.ApiVersion ?? DefaultApiVersion;

var parameters = new ExportTemplateParameters
if (this.ApiVersion is null)
Comment thread
isra-fel marked this conversation as resolved.
Outdated
{
Resources = this.GetResourcesFilter(resourceGroupId: resourceGroupId),
Options = this.GetExportOptions(),
};

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

var managementUri = this.GetResourcesClient()
.GetResourceManagementRequestUri(
resourceId: resourceGroupId,
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"]);

if (JObject.Parse(resultString)["error"] != null)
var parameters = new Management.ResourceManager.Models.ExportTemplateRequest
{
Resources = this.GetResourcesFilter(resourceGroupId: resourceGroupId),
Options = this.GetExportOptions(),
};

var exportedTemplate = ResourceManagerSdkClient.ExportResourceGroup(ResourceGroupName, parameters);

@filizt Filiz Topatan (filizt) Oct 23, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you had a chance to test export async route? AFAIK, the service side goes into async operation based on the time it takes to export or based on the number of resources (I think it was >= 20 resources). It might be easier to test async route by trying more than 20 resources to export rather than trying to hit the timebound. Do you mind testing this scenario, if you haven't already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the scenario.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. We'll chat offline.


In reply to: 510976108 [](ancestors = 510976108)


var template = exportedTemplate.Template;
contents = template.ToString();

var error = exportedTemplate.Error;
Comment thread
isra-fel marked this conversation as resolved.
}
else
{
ExtendedErrorInfo error;
if (JObject.Parse(resultString)["error"].TryConvertTo(out error))
var parameters = new ExportTemplateParameters
{
Resources = this.GetResourcesFilter(resourceGroupId: resourceGroupId),
Options = this.GetExportOptions(),
};
var apiVersion = this.ApiVersion ?? DefaultApiVersion;
var operationResult = this.GetResourcesClient()

@filizt Filiz Topatan (filizt) Oct 27, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also wouldn't need this line after "this.IsParameterBound(c => c.ApiVersion"

.InvokeActionOnResource<JObject>(
resourceId: resourceGroupId,
action: Constants.ExportTemplate,
parameters: parameters.ToJToken(),
apiVersion: apiVersion,
cancellationToken: this.CancellationToken.Value)
.Result;

var managementUri = this.GetResourcesClient()
.GetResourceManagementRequestUri(
resourceId: resourceGroupId,
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"]);
contents = template.ToString();

if (JObject.Parse(resultString)["error"] != null)
{
WriteWarning(string.Format("{0} : {1}", error.Code, error.Message));
foreach (var detail in error.Details)
ExtendedErrorInfo error;
if (JObject.Parse(resultString)["error"].TryConvertTo(out error))
Comment thread
isra-fel marked this conversation as resolved.
Outdated
{
WriteWarning(string.Format("{0} : {1}", detail.Code, detail.Message));
WriteWarning(string.Format("{0} : {1}", error.Code, error.Message));
foreach (var detail in error.Details)
{
WriteWarning(string.Format("{0} : {1}", detail.Code, detail.Message));
}
}
}
}

string path = FileUtility.SaveTemplateFile(
templateName: this.ResourceGroupName,
contents: template.ToString(),
contents: contents,
outputPath:
string.IsNullOrEmpty(this.Path)
? System.IO.Path.Combine(CurrentPath(), this.ResourceGroupName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ private ResourceGroup CreateOrUpdateResourceGroup(string name, string location,
return result;
}

public ResourceGroupExportResult ExportResourceGroup(string resourceGroupName, ExportTemplateRequest properties)
{
return ResourceManagementClient.ResourceGroups.ExportTemplate(resourceGroupName, properties);
}

private void WriteVerbose(string progress)
{
if (VerboseLogger != null)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Added support for deploying Template Specs using existing deployment cmdlets (via the new -TemplateSpecId parameter)
* Updated `Get-AzResourceGroupDeploymentOperation` to use the SDK.
* Removed `-ApiVersion` parameter from `*-AzDeployment` cmdlets.
* Updated `Export-AzResourceGroup` to use the SDK.

## Version 2.5.1
* Added missing check for Set-AzRoleAssignment
Expand Down