Skip to content
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

Fix for Subnets not in same Vnet #55

Open
wants to merge 2 commits into
base: generation
Choose a base branch
from
Open
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
39 changes: 38 additions & 1 deletion src/Migrate/custom/Start-AzMigrateTestMigration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ function Start-AzMigrateTestMigration {
$FabricName = $MachineIdArray[10]
$ProtectionContainerName = $MachineIdArray[12]
$MachineName = $MachineIdArray[14]


$null = $PSBoundParameters.Add("ResourceGroupName", $ResourceGroupName)
$null = $PSBoundParameters.Add("ResourceName", $VaultName)
Expand All @@ -126,6 +125,44 @@ function Start-AzMigrateTestMigration {
$null = $PSBoundParameters.Add("ProtectionContainerName", $ProtectionContainerName)

$ReplicationMigrationItem = Az.Migrate.internal\Get-AzMigrateReplicationMigrationItem @PSBoundParameters
$AvSetId = $ReplicationMigrationItem.ProviderSpecificDetail.TargetAvailabilitySetId
if ($AvSetId)
{
Import-module -Name Az.Compute
Import-module -Name Az.Network
$AvSetName = $AvSetId.Split("/")[-1];
singhabh27 marked this conversation as resolved.
Show resolved Hide resolved
$AvSetRg = $AvSetId.Split("/")[-5];
$AvSet = Get-AzAvailabilitySet -ResourceGroupName $AvSetRg -Name $AvSetName -ErrorVariable notPresent -ErrorAction SilentlyContinue
if (!$AvSet)
{
throw "Availability Set '$($AvSetId)' does not exist."
}
if ($AvSet.VirtualMachineReferences -And ($AvSet.VirtualMachineReferences.Count -gt 0))
{
$VminAvSet = $AvSet.VirtualMachinesReferences[0].Id
if ($VminAvSet)
{
$VmNameinAvSet = $VminAvSet.Split("/")[-1]
$VM = Get-AzVM -ResourceGroupName $AvSetRg -Name $VmNameinAvSet -ErrorVariable notPresent -ErrorAction SilentlyContinue
if ($VM)
{
$NicId = $VM.NetworkProfile.NetworkInterfaces[0].Id
$Nic = Get-Aznetworkinterface -resourceid $NicId -ErrorVariable notPresent -ErrorAction SilentlyContinue
Copy link
Owner

Choose a reason for hiding this comment

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

N,I capital.

if($Nic -And ($Nic.IpConfigurations) -And ($Nic.IpConfigurations[0].Subnet) -And ($Nic.IpConfigurations[0].Subnet.Id))
{
$Subnet = $Nic.IpConfigurations[0].Subnet.Id.Split("/")
$VnetID = "/$($Subnet[1])/$($Subnet[2])/$($Subnet[3])/$($Subnet[4])/$($Subnet[5])/$($Subnet[6])/$($Subnet[7])/$($Subnet[8])"
}

if ($TestNetworkID -ne $VnetID)
{
throw "Virtual Machines in the availability set '$AvSetName' can only be connected to virtual network '$VnetID'. Change the virtual network selected for the test or update the availability set for the machines, and retry the operation."
}
}
}
}
}

if ($ReplicationMigrationItem -and ($ReplicationMigrationItem.ProviderSpecificDetail.InstanceType -eq 'VMwarecbt') -and ($ReplicationMigrationItem.AllowedOperation -contains 'TestMigrate' )) {
$ProviderSpecificDetailInput = [Microsoft.Azure.PowerShell.Cmdlets.Migrate.Models.Api20210210.VMwareCbtTestMigrateInput]::new()
$ProviderSpecificDetailInput.InstanceType = 'VMwareCbt'
Expand Down