-
Notifications
You must be signed in to change notification settings - Fork 378
Add createmigrateproject action to AzureMigrate PlatformLandingZone Request Command #1724
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
Open
akshayrohilla
wants to merge
7
commits into
main
Choose a base branch
from
users/akshayrohilla/addCreateMigrateProjectAction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
14db788
Add createmigrateproject action to AzureMigrate Platform Landing Zone…
5f1f996
Add parameters and role assignments for Azure Migrate project in test…
bb351d7
Merge branch 'main' into users/akshayrohilla/addCreateMigrateProjectA…
akshayrohilla 89a4e00
Recorded the tests
2fd3c4f
Merge branch 'users/akshayrohilla/addCreateMigrateProjectAction' of h…
ccd2973
Merge branch 'main' of https://github.com/microsoft/mcp into users/ak…
de055b4
Add LiveServerFixture to AzureMigrateCommandTests constructor
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
servers/Azure.Mcp.Server/changelog-entries/akshayrohilla-add-createazuremigrate-action.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| changes: | ||
| - section: "Features Added" | ||
| description: "Add createmigrateproject action in azmcp_azuremigrate_platformlandingzone_request command to create a new Azure Migrate project if one doesn't exist" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
tools/Azure.Mcp.Tools.AzureMigrate/src/Helpers/AzureMigrateProjectHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Core; | ||
| using Azure.Mcp.Core.Options; | ||
| using Azure.Mcp.Core.Services.Azure; | ||
| using Azure.Mcp.Core.Services.Azure.Subscription; | ||
| using Azure.Mcp.Core.Services.Azure.Tenant; | ||
| using Azure.Mcp.Tools.AzureMigrate.Models; | ||
| using Azure.ResourceManager; | ||
|
|
||
| namespace Azure.Mcp.Tools.AzureMigrate.Helpers; | ||
|
|
||
| /// <summary> | ||
| /// Helper for creating Azure Migrate projects. | ||
| /// </summary> | ||
| public sealed class AzureMigrateProjectHelper( | ||
| ISubscriptionService subscriptionService, | ||
| ITenantService tenantService) | ||
| : BaseAzureResourceService(subscriptionService, tenantService) | ||
| { | ||
| private readonly ISubscriptionService _subscriptionService = subscriptionService; | ||
|
|
||
| private const string MigrateProjectResourceType = "Microsoft.Migrate/MigrateProjects"; | ||
| private const string MigrateProjectApiVersion = "2020-06-01-preview"; | ||
|
|
||
| /// <summary> | ||
| /// Creates an Azure Migrate project in the specified resource group. | ||
| /// </summary> | ||
| public async Task<MigrateProjectResult> CreateAzureMigrateProjectAsync( | ||
| string projectName, | ||
| string resourceGroup, | ||
| string location, | ||
| string subscription, | ||
| string? tenant = null, | ||
| RetryPolicyOptions? retryPolicy = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| ValidateRequiredParameters( | ||
| (nameof(projectName), projectName), | ||
| (nameof(resourceGroup), resourceGroup), | ||
| (nameof(location), location), | ||
| (nameof(subscription), subscription)); | ||
|
|
||
| try | ||
| { | ||
| ArmClient armClient = await CreateArmClientWithApiVersionAsync( | ||
| MigrateProjectResourceType, | ||
| MigrateProjectApiVersion, | ||
| null, | ||
| retryPolicy); | ||
|
|
||
| var subscriptionResource = await _subscriptionService.GetSubscription(subscription, cancellationToken: cancellationToken); | ||
| ResourceIdentifier projectId = new ResourceIdentifier( | ||
| $"/subscriptions/{subscriptionResource.Data.SubscriptionId}/resourceGroups/{resourceGroup}/providers/{MigrateProjectResourceType}/{projectName}"); | ||
|
|
||
| var createContent = new MigrateProjectCreateContent | ||
| { | ||
| Location = location, | ||
| Properties = new MigrateProjectProperties() | ||
| }; | ||
|
|
||
| var result = await CreateOrUpdateGenericResourceAsync( | ||
| armClient, | ||
| projectId, | ||
| location, | ||
| createContent, | ||
| AzureMigrateSerializerContext.Default.MigrateProjectCreateContent); | ||
|
|
||
| if (!result.HasData) | ||
| { | ||
| return new MigrateProjectResult( | ||
| HasData: false, | ||
| Id: null, | ||
| Name: null, | ||
| Type: null, | ||
| Location: null, | ||
| Properties: null); | ||
| } | ||
|
|
||
| return new MigrateProjectResult( | ||
| HasData: true, | ||
| Id: result.Data.Id.ToString(), | ||
| Name: result.Data.Name, | ||
| Type: result.Data.ResourceType.ToString(), | ||
| Location: result.Data.Location, | ||
| Properties: null); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| throw new InvalidOperationException($"Error creating Azure Migrate project '{projectName}': {ex.Message}", ex); | ||
| } | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
tools/Azure.Mcp.Tools.AzureMigrate/src/Helpers/AzureMigrateSerializerContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
| using Azure.Mcp.Tools.AzureMigrate.Models; | ||
|
|
||
| namespace Azure.Mcp.Tools.AzureMigrate.Helpers; | ||
|
|
||
| [JsonSerializable(typeof(MigrateProjectCreateContent))] | ||
| [JsonSerializable(typeof(MigrateProjectProperties))] | ||
| [JsonSerializable(typeof(MigrateProjectResult))] | ||
| [JsonSerializable(typeof(Dictionary<string, object>))] | ||
| [JsonSourceGenerationOptions( | ||
| PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
| internal partial class AzureMigrateSerializerContext : JsonSerializerContext; |
31 changes: 31 additions & 0 deletions
31
tools/Azure.Mcp.Tools.AzureMigrate/src/Models/MigrateProjectCreateContent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Azure.Mcp.Tools.AzureMigrate.Models; | ||
|
|
||
| /// <summary> | ||
| /// Content for creating or updating an Azure Migrate project. | ||
| /// </summary> | ||
| public sealed class MigrateProjectCreateContent | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the Azure location for the migrate project. | ||
| /// </summary> | ||
| [JsonPropertyName("location")] | ||
| public string? Location { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the properties of the migrate project. | ||
| /// </summary> | ||
| [JsonPropertyName("properties")] | ||
| public MigrateProjectProperties? Properties { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Properties for an Azure Migrate project. | ||
| /// </summary> | ||
| public sealed class MigrateProjectProperties | ||
| { | ||
| } |
15 changes: 15 additions & 0 deletions
15
tools/Azure.Mcp.Tools.AzureMigrate/src/Models/MigrateProjectResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Azure.Mcp.Tools.AzureMigrate.Models; | ||
|
|
||
| /// <summary> | ||
| /// Result of a Migrate Project operation. | ||
| /// </summary> | ||
| public sealed record MigrateProjectResult( | ||
| bool HasData, | ||
| string? Id, | ||
| string? Name, | ||
| string? Type, | ||
| string? Location, | ||
| IDictionary<string, object>? Properties); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.