Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
cc6ca8d
Make first iteration
Jul 15, 2025
eedaf7b
Create more commands
Jul 15, 2025
3390314
Remove uselss commands
Jul 15, 2025
5336c75
Auth commands work
Jul 15, 2025
6a9a825
Fix login output issue
Jul 15, 2025
1a102e0
Add storage account command
Jul 15, 2025
2cdff12
Small
Jul 15, 2025
f482a49
Fix auth and add some local commands (still untested)
Jul 15, 2025
8488f17
Fix params
Jul 15, 2025
416604a
Fix Job ID
Jul 15, 2025
938a32c
Begin code cleanup
Jul 15, 2025
e5f8a49
Replace subprocess with rn_cmd
Jul 16, 2025
524b500
Small code cleanups
Jul 16, 2025
a88817e
Small fix
Jul 16, 2025
1db1b87
Small fix
Jul 16, 2025
5aecc2b
Cleanup
Jul 16, 2025
9613f08
Update readme
Jul 16, 2025
d4e632f
Register commands
Jul 17, 2025
77dfaf5
Small
Jul 17, 2025
a4caee4
FINALLY got the command to work
Jul 17, 2025
00613ec
Get auth commands to work
Jul 17, 2025
f4c384b
get-discovered-servers-table works
Jul 17, 2025
1eb61ba
init-local works
Jul 17, 2025
b6390cf
Create replication command working
Jul 17, 2025
9066d5f
get job command works
Jul 17, 2025
3ca124d
Clean up additional output
Jul 23, 2025
1fd9199
Fix powershell output
Jul 23, 2025
e3498ad
Merge branch 'Azure:dev' into dev
saifaldin14 Jul 23, 2025
c15c7ae
Add new commands
Jul 28, 2025
14f9fef
Fix powershell
Jul 29, 2025
e013700
Small fix
Sep 2, 2025
1472bd2
Merge branch 'Azure:dev' into dev
saifaldin14 Sep 2, 2025
7161121
Add missing commands
Sep 2, 2025
ef47ab4
Merge branch 'dev' of https://github.com/saifaldin14/azure-cli into dev
Sep 2, 2025
695f097
Update help documentation
Sep 2, 2025
5c62eb7
Workflow documentation
Sep 2, 2025
33954a0
Create unit tests
Sep 2, 2025
3de57f2
Delete empty file
Sep 2, 2025
1a85cd2
Create unit tests
Sep 2, 2025
f9d5b94
Remove useless files
Sep 2, 2025
bcdca86
Clean up tests
Sep 3, 2025
7524326
Small
Sep 3, 2025
7691c42
Remove readme
Sep 3, 2025
bf80801
Rename file
Sep 3, 2025
c82a0b2
Small
Sep 3, 2025
fe19c96
Add update command
Sep 4, 2025
7ece539
Fix some commands
Sep 5, 2025
8c2816a
Merge branch 'Azure:dev' into dev
saifaldin14 Sep 5, 2025
4ad19c7
Remove unused commands
Sep 9, 2025
5f5ac59
Remove useless help commands
Sep 9, 2025
84585ca
Update documentation with removed commands
Sep 9, 2025
a36f4c1
Remove deleted commands from tests
Sep 9, 2025
4174400
Merge branch 'Azure:dev' into dev
saifaldin14 Sep 9, 2025
b569ee3
Clean up
Sep 9, 2025
18a96f6
Small
Sep 9, 2025
ce4f170
Clean up params
Sep 9, 2025
ddaddeb
Small
Sep 9, 2025
22d78ea
Clean up readme
Sep 9, 2025
68eba4f
Test fix
Sep 9, 2025
d25b559
Small
Sep 9, 2025
ca6402d
Remove foreground redundancy
Sep 16, 2025
f9095bd
Update module command working correctly
Sep 16, 2025
1cdf721
Add validated flag to commands that I have checked
Sep 16, 2025
499e9e3
Fix check_azure_authentication and make it more natural
Sep 16, 2025
3591576
Fix auth commands
Sep 16, 2025
4132d65
Merge branch 'Azure:dev' into dev
saifaldin14 Sep 16, 2025
7003d27
New set of commands
Oct 1, 2025
792c7a0
Create get discovered server command [Just returns the bare bones JSON]
Oct 2, 2025
88159fd
Properly fetch discovered servers and display the correct output
Oct 2, 2025
8339883
Create first copy of initialize infrasture command
Oct 2, 2025
ee57a2f
Init replication is better (but still not complete)
Oct 2, 2025
f5d253f
Finish replication init command
Oct 3, 2025
ad9db7e
Change display style to match other az commands
Oct 3, 2025
a863778
First version of new replication command
Oct 3, 2025
7115ad3
First draft of new replication command
Oct 7, 2025
aaa268c
Small
Oct 7, 2025
2fa2e0a
Fix 404 existing protected item issue
Oct 7, 2025
a46c4e1
The last step still fails
Oct 7, 2025
fa51a43
Create replication
Oct 9, 2025
ef0292e
Create help documentation
Oct 9, 2025
2d94262
Delete get protected item command
Oct 9, 2025
ff2259a
Fix get request
Oct 9, 2025
7083d34
Clean up replication infrastructre command
Oct 14, 2025
a4fc8d8
Remove debug statements
Oct 14, 2025
39572ed
Fix initialize command
Oct 15, 2025
a94b583
Add back new command
Oct 15, 2025
e448ed3
Fix init command
Oct 16, 2025
c73a7ba
Add back new replication command
Oct 16, 2025
1dd4aa5
Cleanup print statements
Oct 16, 2025
e29b4bf
Merge branch 'Azure:dev' into user/saif/newVersion
saifaldin14 Oct 16, 2025
530c4ec
Delete useless tests
Oct 17, 2025
a60aaf1
Wrote unit test environment
Oct 17, 2025
95b3ced
Merge branch 'user/saif/newVersion' of https://github.com/saifaldin14…
Oct 17, 2025
a73ac45
Update src/azure-cli/azure/cli/command_modules/migrate/README.md
saifaldin14 Oct 20, 2025
9ff5c80
Update src/azure-cli/azure/cli/command_modules/migrate/tests/latest/t…
saifaldin14 Oct 20, 2025
5c7614e
Update src/azure-cli/azure/cli/command_modules/migrate/README.md
saifaldin14 Oct 20, 2025
407ef33
Add service name
Oct 20, 2025
2d8607b
Merge branch 'user/saif/newVersion' of https://github.com/saifaldin14…
Oct 20, 2025
8cf05b5
Small
Oct 20, 2025
d7978d1
Create scenario tests
Oct 20, 2025
95abee5
Fix lint issues
Oct 20, 2025
29245bd
Lint errors in param names
Oct 20, 2025
ab50ba2
Small
Oct 20, 2025
06d2955
Small
Oct 20, 2025
a859316
Fix lines too long error message
Oct 20, 2025
1915fe4
Split up code into helper functions
Oct 21, 2025
8ca3a99
Fix remaining lint errors
Oct 21, 2025
a0023cb
Fix all formatting issues
Oct 22, 2025
8909017
Small help fix
Oct 22, 2025
b712b8c
Parse yaml correctly
Oct 22, 2025
d2f44d9
Exclude
Oct 22, 2025
a51ba49
Small fixes
Oct 22, 2025
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@
/src/azure-cli/azure/cli/command_modules/util/ @jiasli @zhoxing-ms @evelyn-ys
/src/azure-cli/azure/cli/command_modules/vm/ @zhoxing-ms @jsntcy @wangzelin007 @yanzhudd @Drewm3 @TravisCragg-MSFT @nikhilpatel909 @sandeepraichura @hilaryw29 @GabstaMSFT @ramankumarlive @ushnaarshadkhan
/src/azure-cli/azure/cli/command_modules/containerapp/ @zhoxing-ms @yanzhudd @ruslany @sanchitmehta @ebencarek @JennyLawrance @howang-ms @vinisoto @chinadragon0515 @vturecek @torosent @pagariyaalok @Juliehzl @jijohn14 @Greedygre @ShichaoQiu
/src/azure-cli/azure/cli/command_modules/migrate/ @saifaldin14
3 changes: 2 additions & 1 deletion doc/sphinx/azhelpgen/doc_source_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
"term": "src/azure-cli/azure/cli/command_modules/marketplaceordering/_help.py",
"util": "src/azure-cli/azure/cli/command_modules/util/_help.py",
"vm": "src/azure-cli/azure/cli/command_modules/vm/_help.py",
"vmss": "src/azure-cli/azure/cli/command_modules/vm/_help.py"
"vmss": "src/azure-cli/azure/cli/command_modules/vm/_help.py",
"migrate": "src/azure-cli/azure/cli/command_modules/migrate/_help.py"
}
1 change: 1 addition & 0 deletions src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods
MGMT_DATALAKE_ANALYTICS = ('azure.cli.command_modules.dla.vendored_sdks.azure_mgmt_datalake_analytics', None)
MGMT_DATALAKE_STORE = ('azure.mgmt.datalake.store', None)
MGMT_DATAMIGRATION = ('azure.mgmt.datamigration', None)
MGMT_MIGRATE = ('azure.mgmt.migrate', None)
MGMT_EVENTGRID = ('azure.mgmt.eventgrid', None)
MGMT_MAPS = ('azure.mgmt.maps', None)
MGMT_POLICYINSIGHTS = ('azure.mgmt.policyinsights', None)
Expand Down
282 changes: 282 additions & 0 deletions src/azure-cli/azure/cli/command_modules/migrate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
# Azure CLI Migration Module

This module provides server discovery and replication capabilities for Azure resources and workloads through Azure CLI commands, with special focus on Azure Local (Azure Stack HCI) migrations.

## Features

- **Server discovery**: Discover servers from various sources
- **Replication management**: Initialize and create new replications for supported workloads

## Prerequisites

- Azure CLI 2.0+
- Valid Azure subscription
- Appropriate permissions for migration operations
- For Azure Local: Azure Stack HCI environment with proper networking

## Command Overview

The Azure CLI migrate module provides the following commands:

### Server Discovery
```bash
# Get discovered servers
az migrate get-discovered-server --resource-group myRG --project-name myProject
# Create server replication
az migrate server create-replication --resource-group myRG --project-name myProject --target-vm-name myVM --target-resource-group targetRG --target-network targetNet

# Show replication status
az migrate server show-replication-status --resource-group myRG --project-name myProject --vm-name myVM

# Update replication properties
az migrate server update-replication --resource-group myRG --project-name myProject --vm-name myVM

# Check cross-platform environment
az migrate server check-environment
```
### Azure Local (Stack HCI) Migration Commands
```bash
# Initialize Azure Local replication infrastructure
az migrate local init --resource-group myRG --project-name myProject

# Create disk mapping for fine-grained control
az migrate local create-disk-mapping --disk-id "disk001" --is-os-disk --size-gb 64 --format-type VHDX

# Create NIC mapping for network configuration
az migrate local create-nic-mapping --nic-id "nic001" \
--target-virtual-switch-id "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.AzureStackHCI/logicalnetworks/network001"

# Create basic replication
az migrate local create-replication --resource-group myRG --project-name myProject \
--server-index 0 --target-vm-name migratedVM \
--target-storage-path-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/storageContainers/container001" \
--target-virtual-switch-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/logicalnetworks/network001" \
--target-resource-group-id "/subscriptions/xxx/resourceGroups/targetRG"

# Create replication with custom disk and NIC mappings
az migrate local create-replication-with-mappings --resource-group myRG --project-name myProject \
--discovered-machine-id "/subscriptions/xxx/machines/machine001" \
--target-vm-name migratedVM \
--target-storage-path-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/storageContainers/container001" \
--target-resource-group-id "/subscriptions/xxx/resourceGroups/targetRG" \
--disk-mappings '[{"DiskID": "disk001", "IsOSDisk": true, "Size": 64, "Format": "VHDX"}]' \
--nic-mappings '[{"NicID": "nic001", "TargetVirtualSwitchId": "/subscriptions/xxx/logicalnetworks/network001"}]'

# Get replication job details
az migrate local get-job --resource-group myRG --project-name myProject --job-id "job-12345"

# Get Azure Local specific job
az migrate local get-azure-local-job --resource-group myRG --project-name myProject --job-id "job-12345"

# Start migration (planned failover)
az migrate local start-migration --target-object-id "/subscriptions/xxx/replicationProtectedItems/item001" \
--turn-off-source-server

# Remove replication after successful migration
az migrate local remove-replication --target-object-id "/subscriptions/xxx/replicationProtectedItems/item001"
```

### Authentication Management
```bash
# Check Azure authentication status
az migrate auth check

# Login to Azure (interactive)
az migrate auth login

# Login with device code
az migrate auth login --device-code

# Login with service principal
az migrate auth login --app-id "app-id" --secret "secret" --tenant-id "tenant-id"

# Set Azure context
az migrate auth set-context --subscription-id "00000000-0000-0000-0000-000000000000"

# Show current context
az migrate auth show-context

# Logout
az migrate auth logout
```

### PowerShell Module Management
```bash
# Check PowerShell module availability
az migrate powershell check-module --module-name Az.Migrate

# Update PowerShell modules
az migrate powershell update-modules --modules Az.Migrate
```

## Architecture

The migration module consists of several key components:

1. **Cross-Platform PowerShell Integration**: Executes PowerShell cmdlets across Windows, Linux, and macOS
2. **Azure Local Migration**: Specialized support for Azure Stack HCI migration scenarios
3. **Authentication Management**: Azure authentication and context management
4. **Server Discovery and Replication**: Discovery and replication of source machines

## Common Workflows

### Setting up Azure Local Migration

```bash
# 1. Check prerequisites
az migrate check-prerequisites

# 2. Set up environment with PowerShell
az migrate setup-env --install-powershell

# 3. Authenticate to Azure
az migrate auth login

# 4. Set subscription context
az migrate auth set-context --subscription-id "your-subscription-id"

# 5. Verify setup
az migrate verify-setup --resource-group "migration-rg" --project-name "azure-local-migration"

# 6. Initialize Azure Local replication infrastructure
az migrate local init \
--resource-group "migration-rg" \
--project-name "azure-local-migration"

# 7. List discovered servers
az migrate server list-discovered \
--resource-group "migration-rg" \
--project-name "azure-local-migration" \
--source-machine-type VMware

# 8. Create replication for a specific server
az migrate local create-replication \
--resource-group "migration-rg" \
--project-name "azure-local-migration" \
--server-index 0 \
--target-vm-name "WebServer-Migrated" \
--target-storage-path-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/storageContainers/migration-storage" \
--target-virtual-switch-id "/subscriptions/xxx/providers/Microsoft.AzureStackHCI/logicalnetworks/migration-network" \
--target-resource-group-id "/subscriptions/xxx/resourceGroups/azure-local-vms"

# 9. Monitor replication progress
az migrate local get-job --resource-group "migration-rg" --project-name "azure-local-migration" --job-id "job-id"

# 10. Start migration when ready
az migrate local start-migration --target-object-id "replication-id" --turn-off-source-server

# 11. Monitor migration job
az migrate local get-azure-local-job --resource-group "migration-rg" --project-name "azure-local-migration" --job-id "job-id"
```

### Setting up Server Discovery and Replication

```bash
# 1. Check prerequisites and setup
az migrate check-prerequisites
az migrate setup-env --install-powershell

# 2. Authenticate and set context
az migrate auth login
az migrate auth set-context --subscription-id "your-subscription-id"

# 3. Verify setup
az migrate verify-setup --resource-group "migration-rg" --project-name "server-migration-2025"

# 4. List discovered servers
az migrate server list-discovered --resource-group "migration-rg" --project-name "server-migration-2025" --source-machine-type VMware

# 5. Find specific servers
az migrate server find-by-name --resource-group "migration-rg" --project-name "server-migration-2025" --display-name "WebServer"

# 6. Create server replication
az migrate server create-replication --resource-group "migration-rg" --project-name "server-migration-2025" --target-vm-name "WebServer-Azure" --target-resource-group "target-rg" --target-network "target-vnet"

# 7. Monitor replication status
az migrate server show-replication-status --resource-group "migration-rg" --project-name "server-migration-2025" --vm-name "WebServer-Azure"
```

## PowerShell Integration

This module provides Azure CLI equivalents to PowerShell Az.Migrate cmdlets:

| PowerShell Cmdlet | Azure CLI Command |
|-------------------|-------------------|
| `Initialize-AzMigrateLocalReplicationInfrastructure` | `az migrate local init` |
| `New-AzMigrateLocalServerReplication` | `az migrate local create-replication` |
| `New-AzMigrateLocalDiskMappingObject` | `az migrate local create-disk-mapping` |
| `New-AzMigrateLocalNicMappingObject` | `az migrate local create-nic-mapping` |
| `Start-AzMigrateLocalServerMigration` | `az migrate local start-migration` |
| `Remove-AzMigrateLocalServerReplication` | `az migrate local remove-replication` |
| `Get-AzMigrateLocalJob` | `az migrate local get-azure-local-job` |
| `Get-AzMigrateDiscoveredServer` | `az migrate server list-discovered` |
| `New-AzMigrateServerReplication` | `az migrate server create-replication` |
| `Get-AzMigrateServerReplication` | `az migrate server show-replication-status` |

## Error Handling

The module includes comprehensive error handling for:

- Invalid project configurations
- Permission and authentication issues
- Resource not found scenarios
- Azure service connectivity problems
- PowerShell execution errors
- Cross-platform compatibility issues

## Troubleshooting

### Common Issues

**PowerShell Not Found**
- On Windows: Install PowerShell Core or ensure Windows PowerShell is available
- On Linux/macOS: Install PowerShell Core from https://github.com/PowerShell/PowerShell
- Use `az migrate setup-env --install-powershell` for automatic installation guidance

**Authentication Issues**
- Use `az migrate auth check` to verify authentication status
- Re-authenticate using `az migrate auth login`
- Verify subscription context with `az migrate auth show-context`

**Server Discovery Issues**
- Confirm the appliance is properly configured
- Verify network connectivity from appliance to Azure
- Check that discovery is running on the appliance
- Use `az migrate server list-discovered` to check for discovered servers

**Permission Errors**
- Ensure Azure Migrate Contributor role is assigned
- Verify subscription-level permissions for creating resources
- Check resource group permissions

**Azure Local Specific Issues**
- Verify Azure Stack HCI cluster is properly registered with Azure
- Ensure proper networking between source and Azure Local target
- Check that both source and target appliances are properly configured
- Verify storage containers and logical networks are properly set up in Azure Local
- Use `az migrate local init` to initialize infrastructure

**Script Execution Errors**
- Check PowerShell execution policy
- Verify PowerShell module availability using `az migrate powershell check-module`
- Review error messages for specific guidance
- Use `az migrate check-prerequisites` to verify system requirements

## Contributing

When extending the migration module:

1. Follow Azure CLI command naming conventions
2. Implement proper error handling and validation
3. Add comprehensive help documentation
4. Include usage examples in help text
5. Update this README with new command examples
6. Ensure cross-platform PowerShell compatibility
7. Add appropriate parameter validation
8. Include integration tests for new commands

For more information on Azure Migrate, visit: https://docs.microsoft.com/azure/migrate/

## License

This project is licensed under the MIT License - see the LICENSE file for details.
37 changes: 37 additions & 0 deletions src/azure-cli/azure/cli/command_modules/migrate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azure.cli.core.profiles import ResourceType


class MigrateCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType

migrate_custom = CliCommandType(
operations_tmpl='azure.cli.command_modules.migrate.custom#{}',
)

super().__init__(
cli_ctx=cli_ctx,
custom_command_type=migrate_custom,
resource_type=ResourceType.MGMT_MIGRATE
)

def load_command_table(self, args):
from azure.cli.command_modules.migrate.commands \
import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azure.cli.command_modules.migrate._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = MigrateCommandsLoader
Loading
Loading