/// <summary> /// Moves a number of resources from one resource group to another /// </summary> /// <param name="sourceResourceGroupName"></param> /// <param name="destinationResourceGroup"></param> /// <param name="resourceIds"></param> public virtual AzureOperationResponse MoveResources(string sourceResourceGroupName, string destinationResourceGroup, string[] resourceIds) { var resourcesMoveInfo = new ResourcesMoveInfo { Resources = resourceIds, TargetResourceGroup = destinationResourceGroup, }; return(ResourceManagementClient.Resources.MoveResources(sourceResourceGroupName, resourcesMoveInfo)); }
public void ResourcesMoveTest() { var response = new HttpResponseMessage(HttpStatusCode.Accepted) { }; response.Headers.Add("x-ms-request-id", "1"); var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK }; var client = GetResourceManagementClient(handler); var resourceToMove = new ResourcesMoveInfo(); resourceToMove.Resources = new List <string>(); resourceToMove.TargetResourceGroup = "/subscriptions/" + Uri.EscapeDataString(client.SubscriptionId) + "/resourceGroups/resourceGroup1"; var resource1 = "/subscriptions/" + Uri.EscapeDataString(client.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Web/website/website1"; resourceToMove.Resources.Add(resource1); var resource2 = "/subscriptions/" + Uri.EscapeDataString(client.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Compute/hostservice/vm1"; resourceToMove.Resources.Add(resource2); client.Resources.MoveResources("resourceGroup0", resourceToMove); // Validate headers Assert.Equal(HttpMethod.Post, handler.Method); Assert.NotNull(handler.RequestHeaders.GetValues("Authorization")); //Valid payload //Construct expected URL string expectedUrl = "/subscriptions/" + Uri.EscapeDataString(client.SubscriptionId) + "/resourceGroups/resourceGroup0/moveResources?"; expectedUrl = expectedUrl + "api-version=2014-04-01-preview"; string baseUrl = client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (expectedUrl[0] == '/') { expectedUrl = expectedUrl.Substring(1); } expectedUrl = baseUrl + "/" + expectedUrl; expectedUrl = expectedUrl.Replace(" ", "%20"); Assert.Equal(expectedUrl, handler.Uri.ToString()); }
public async Task MoveResourcesAsync( string sourceResourceGroupName, IResourceGroup targetResourceGroup, IList <string> resources, CancellationToken cancellationToken = default(CancellationToken)) { ResourcesMoveInfo moveInfo = new ResourcesMoveInfo() { TargetResourceGroup = targetResourceGroup.Id, Resources = resources, }; await Inner.MoveResourcesAsync(sourceResourceGroupName, moveInfo, cancellationToken); }
public async Task ValidateMoveResources() { ResourceGroup rg1 = await Client.DefaultSubscription.GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg")); ResourceGroup rg2 = await Client.DefaultSubscription.GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg")); var aset = await CreateGenericAvailabilitySetAsync(rg1.Id); var moveInfo = new ResourcesMoveInfo(); moveInfo.TargetResourceGroup = rg2.Id; moveInfo.Resources.Add(aset.Id); Response response = await rg1.ValidateMoveResourcesAsync(moveInfo); Assert.AreEqual(204, response.Status); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg1.ValidateMoveResourcesAsync(null)); }
public async Task StartMoveResources() { Subscription subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); var rg1Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, Recording.GenerateAssetName("testrg"), new ResourceGroupData(AzureLocation.WestUS2)); var rg2Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, Recording.GenerateAssetName("testrg"), new ResourceGroupData(AzureLocation.WestUS2)); ResourceGroup rg1 = rg1Op.Value; ResourceGroup rg2 = rg2Op.Value; var genericResources = subscription.GetGenericResourcesAsync(); var asetOp = await StartCreateGenericAvailabilitySetAsync(rg1.Id); GenericResource aset = await asetOp.WaitForCompletionAsync(); int countRg1 = await GetResourceCountAsync(rg1.GetGenericResourcesAsync()); int countRg2 = await GetResourceCountAsync(rg2.GetGenericResourcesAsync()); Assert.AreEqual(1, countRg1); Assert.AreEqual(0, countRg2); var moveInfo = new ResourcesMoveInfo(); moveInfo.TargetResourceGroup = rg2.Id; moveInfo.Resources.Add(aset.Id); var moveOp = await rg1.MoveResourcesAsync(false, moveInfo); _ = await moveOp.WaitForCompletionResponseAsync(); countRg1 = await GetResourceCountAsync(rg1.GetGenericResourcesAsync()); countRg2 = await GetResourceCountAsync(rg2.GetGenericResourcesAsync()); Assert.AreEqual(0, countRg1); Assert.AreEqual(1, countRg2); Assert.ThrowsAsync <ArgumentNullException>(async() => { var moveOp = await rg1.MoveResourcesAsync(false, null); _ = await moveOp.WaitForCompletionResponseAsync(); }); }
public async Task StartMoveResources() { var rg1Op = await Client.DefaultSubscription.GetResourceGroups().Construct(Location.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg")); var rg2Op = await Client.DefaultSubscription.GetResourceGroups().Construct(Location.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg")); ResourceGroup rg1 = await rg1Op.WaitForCompletionAsync(); ResourceGroup rg2 = await rg2Op.WaitForCompletionAsync(); var genericResources = Client.DefaultSubscription.GetGenericResources(); var asetOp = await StartCreateGenericAvailabilitySetAsync(rg1.Id); GenericResource aset = await asetOp.WaitForCompletionAsync(); int countRg1 = await GetResourceCountAsync(genericResources, rg1); int countRg2 = await GetResourceCountAsync(genericResources, rg2); Assert.AreEqual(1, countRg1); Assert.AreEqual(0, countRg2); var moveInfo = new ResourcesMoveInfo(); moveInfo.TargetResourceGroup = rg2.Id; moveInfo.Resources.Add(aset.Id); var moveOp = await rg1.StartMoveResourcesAsync(moveInfo); _ = await moveOp.WaitForCompletionResponseAsync(); countRg1 = await GetResourceCountAsync(genericResources, rg1); countRg2 = await GetResourceCountAsync(genericResources, rg2); Assert.AreEqual(0, countRg1); Assert.AreEqual(1, countRg2); Assert.ThrowsAsync <ArgumentNullException>(async() => { var moveOp = await rg1.StartMoveResourcesAsync(null); _ = await moveOp.WaitForCompletionResponseAsync(); }); }
/// <summary> The resources to move must be in the same source resource group. The target resource group may be in a different subscription. When moving resources, both the source group and the target group are locked for the duration of the operation. Write and delete operations are blocked on the groups until the move completes. </summary> /// <param name="parameters"> Parameters for moving resources. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> /// <exception cref="ArgumentNullException"> <paramref name="parameters"/> is null. </exception> public virtual ResourcesMoveResourcesOperation StartMoveResources(ResourcesMoveInfo parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = Diagnostics.CreateScope("ResourceGroupOperations.StartMoveResources"); scope.Start(); try { var originalResponse = GenericRestClient.MoveResources(Id.Name, parameters, cancellationToken); return(new ResourcesMoveResourcesOperation(Diagnostics, Pipeline, GenericRestClient.CreateMoveResourcesRequest(Id.Name, parameters).Request, originalResponse)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> This operation checks whether the specified resources can be moved to the target. The resources to move must be in the same source resource group. The target resource group may be in a different subscription. If validation succeeds, it returns HTTP response code 204 (no content). If validation fails, it returns HTTP response code 409 (Conflict) with an error message. Retrieve the URL in the Location header value to check the result of the long-running operation. </summary> /// <param name="parameters"> Parameters for moving resources. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> /// <exception cref="ArgumentNullException"> <paramref name="parameters"/> is null. </exception> public virtual Response ValidateMoveResources(ResourcesMoveInfo parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = Diagnostics.CreateScope("ResourceGroupOperations.ValidateMoveResources"); scope.Start(); try { var operation = StartValidateMoveResources(parameters, cancellationToken); return(operation.WaitForCompletion(cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> This operation checks whether the specified resources can be moved to the target. The resources to move must be in the same source resource group. The target resource group may be in a different subscription. If validation succeeds, it returns HTTP response code 204 (no content). If validation fails, it returns HTTP response code 409 (Conflict) with an error message. Retrieve the URL in the Location header value to check the result of the long-running operation. </summary> /// <param name="parameters"> Parameters for moving resources. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> /// <exception cref="ArgumentNullException"> <paramref name="parameters"/> is null. </exception> public virtual async Task <Response> ValidateMoveResourcesAsync(ResourcesMoveInfo parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = Diagnostics.CreateScope("ResourceGroupOperations.ValidateMoveResources"); scope.Start(); try { var operation = await StartValidateMoveResourcesAsync(parameters, cancellationToken).ConfigureAwait(false); return(await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual ArmOperation ValidateMoveResources(WaitUntil waitUntil, ResourcesMoveInfo parameters, CancellationToken cancellationToken = default) { Argument.AssertNotNull(parameters, nameof(parameters)); using var scope = _resourceGroupClientDiagnostics.CreateScope("ResourceGroupResource.ValidateMoveResources"); scope.Start(); try { var response = _resourceGroupRestClient.ValidateMoveResources(Id.SubscriptionId, Id.ResourceGroupName, parameters, cancellationToken); var operation = new ResourcesArmOperation(_resourceGroupClientDiagnostics, Pipeline, _resourceGroupRestClient.CreateValidateMoveResourcesRequest(Id.SubscriptionId, Id.ResourceGroupName, parameters).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) { operation.WaitForCompletionResponse(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public void ResourcesMoveTest() { var response = new HttpResponseMessage(HttpStatusCode.Accepted) { }; response.Headers.Add("x-ms-request-id", "1"); response.Headers.Add("Location", "http://foo"); var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.Accepted, SubsequentStatusCodeToReturn = HttpStatusCode.NoContent }; var client = GetResourceManagementClient(handler); var resourceToMove = new ResourcesMoveInfo(); resourceToMove.TargetResourceGroup = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup1"; var resource1 = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Web/website/website1"; resourceToMove.Resources.Add(resource1); var resource2 = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Compute/hostservice/vm1"; resourceToMove.Resources.Add(resource2); var moveResult = client.Resources.MoveResources("resourceGroup0", resourceToMove); // Validate headers Assert.Equal(HttpMethod.Get, handler.Method); Assert.NotNull(handler.RequestHeaders.GetValues("Authorization")); // Valid response Assert.Equal(moveResult.StatusCode, HttpStatusCode.NoContent); }
public async Task ValidateMoveResources() { Subscription subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); var rg1Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, Recording.GenerateAssetName("testrg"), new ResourceGroupData(AzureLocation.WestUS2)); var rg2Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, Recording.GenerateAssetName("testrg"), new ResourceGroupData(AzureLocation.WestUS2)); ResourceGroup rg1 = rg1Op.Value; ResourceGroup rg2 = rg2Op.Value; var aset = await CreateGenericAvailabilitySetAsync(rg1.Id); var moveInfo = new ResourcesMoveInfo(); moveInfo.TargetResourceGroup = rg2.Id; moveInfo.Resources.Add(aset.Id); var validateOp = await rg1.ValidateMoveResourcesAsync(true, moveInfo); Response response = validateOp.GetRawResponse(); Assert.AreEqual(204, response.Status); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg1.ValidateMoveResourcesAsync(true, null)); }
public virtual ResourceGroupValidateMoveResourcesOperation ValidateMoveResources(bool waitForCompletion, ResourcesMoveInfo parameters, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = _resourceGroupClientDiagnostics.CreateScope("ResourceGroup.ValidateMoveResources"); scope.Start(); try { var response = _resourceGroupRestClient.ValidateMoveResources(Id.SubscriptionId, Id.ResourceGroupName, parameters, cancellationToken); var operation = new ResourceGroupValidateMoveResourcesOperation(_resourceGroupClientDiagnostics, Pipeline, _resourceGroupRestClient.CreateValidateMoveResourcesRequest(Id.SubscriptionId, Id.ResourceGroupName, parameters).Request, response); if (waitForCompletion) { operation.WaitForCompletionResponse(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> This operation checks whether the specified resources can be moved to the target. The resources to move must be in the same source resource group. The target resource group may be in a different subscription. If validation succeeds, it returns HTTP response code 204 (no content). If validation fails, it returns HTTP response code 409 (Conflict) with an error message. Retrieve the URL in the Location header value to check the result of the long-running operation. </summary> /// <param name="parameters"> Parameters for moving resources. </param> /// <param name="waitForCompletion"> Waits for the completion of the long running operations. </param> /// <param name="cancellationToken"> The cancellation token to use. </param> /// <exception cref="ArgumentNullException"> <paramref name="parameters"/> is null. </exception> public virtual async Task <ResourceValidateMoveResourcesOperation> ValidateMoveResourcesAsync(ResourcesMoveInfo parameters, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = _clientDiagnostics.CreateScope("ResourceGroup.ValidateMoveResources"); scope.Start(); try { var originalResponse = await _genericRestClient.ValidateMoveResourcesAsync(Id.Name, parameters, cancellationToken).ConfigureAwait(false); var operation = new ResourceValidateMoveResourcesOperation(_clientDiagnostics, Pipeline, _genericRestClient.CreateValidateMoveResourcesRequest(Id.Name, parameters).Request, originalResponse); if (waitForCompletion) { await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Move resources within or across subscriptions. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Resources.IResourceOperations. /// </param> /// <param name='sourceResourceGroupName'> /// Required. Source resource group name. /// </param> /// <param name='parameters'> /// Required. move resources' parameters. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> MoveResourcesAsync(this IResourceOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters) { return(operations.MoveResourcesAsync(sourceResourceGroupName, parameters, CancellationToken.None)); }
/// <summary> /// Begin moving resources.To determine whether the operation has /// finished processing the request, call /// GetLongRunningOperationStatus. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Resources.IResourceOperations. /// </param> /// <param name='sourceResourceGroupName'> /// Required. Source resource group name. /// </param> /// <param name='parameters'> /// Required. move resources' parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static LongRunningOperationResponse BeginMoving(this IResourceOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters) { return(Task.Factory.StartNew((object s) => { return ((IResourceOperations)s).BeginMovingAsync(sourceResourceGroupName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Begin moving resources.To determine whether the operation has /// finished processing the request, call /// GetLongRunningOperationStatus. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Resources.IResourceOperations. /// </param> /// <param name='sourceResourceGroupName'> /// Required. Source resource group name. /// </param> /// <param name='parameters'> /// Required. move resources' parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static Task <LongRunningOperationResponse> BeginMovingAsync(this IResourceOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters) { return(operations.BeginMovingAsync(sourceResourceGroupName, parameters, CancellationToken.None)); }
public async virtual Task <ArmOperation> ValidateMoveResourcesAsync(bool waitForCompletion, ResourcesMoveInfo parameters, CancellationToken cancellationToken = default) { Argument.AssertNotNull(parameters, nameof(parameters)); using var scope = _resourceGroupClientDiagnostics.CreateScope("ResourceGroup.ValidateMoveResources"); scope.Start(); try { var response = await _resourceGroupRestClient.ValidateMoveResourcesAsync(Id.SubscriptionId, Id.ResourceGroupName, parameters, cancellationToken).ConfigureAwait(false); var operation = new ResourcesArmOperation(_resourceGroupClientDiagnostics, Pipeline, _resourceGroupRestClient.CreateValidateMoveResourcesRequest(Id.SubscriptionId, Id.ResourceGroupName, parameters).Request, response, OperationFinalStateVia.Location); if (waitForCompletion) { await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Move resources from one resource group to another. The resources being /// moved should all be in the same resource group. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sourceResourceGroupName'> /// Source resource group name. /// </param> /// <param name='parameters'> /// move resources' parameters. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task BeginMoveResourcesAsync(this IResourcesOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters, CancellationToken cancellationToken = default(CancellationToken)) { await operations.BeginMoveResourcesWithHttpMessagesAsync(sourceResourceGroupName, parameters, null, cancellationToken).ConfigureAwait(false); }
/// <summary> /// Move resources from one resource group to another. The resources being /// moved should all be in the same resource group. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sourceResourceGroupName'> /// Source resource group name. /// </param> /// <param name='parameters'> /// move resources' parameters. /// </param> public static void BeginMoveResources(this IResourcesOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters) { Task.Factory.StartNew(s => ((IResourcesOperations)s).BeginMoveResourcesAsync(sourceResourceGroupName, parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
/// <summary> /// Moves resources from one resource group to another resource group. /// </summary> /// <remarks> /// The resources to move must be in the same source resource group. The target /// resource group may be in a different subscription. When moving resources, /// both the source group and the target group are locked for the duration of /// the operation. Write and delete operations are blocked on the groups until /// the move completes. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sourceResourceGroupName'> /// The name of the resource group containing the rsources to move. /// </param> /// <param name='parameters'> /// Parameters for moving resources. /// </param> public static void BeginMoveResources(this IResourcesOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters) { operations.BeginMoveResourcesAsync(sourceResourceGroupName, parameters).GetAwaiter().GetResult(); }