Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Tmssfeature #413

Merged
merged 14 commits into from
Sep 22, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,34 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
}
}

$testVnetName = $csvItem.TEST_VNET_NAME
$testSubnetName = $csvItem.TEST_SUBNET_NAME

if([string]::IsNullOrEmpty($testVnetName)){
$processor.Logger.LogTrace("TEST_VNET_NAME is not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "TEST_VNET_NAME is not mentioned for: '$($sourceMachineName)'"
}
else {
#Get the Test VirtualNetwork Name where we want to provision the VM in Azure
$Test_VNet = Get-AzVirtualNetwork -Name $testVnetName
if (-not $Test_VNet) {
$processor.Logger.LogError("VNET could not be retrieved for: '$($testVnetName)'")
$reportItem.AdditionalInformation = "VNET could not be retrieved for: '$($testVnetName)'"
return
}
else {
$params.Add("TestNetworkId", $Test_VNet.Id)
if([string]::IsNullOrEmpty($testSubnetName)){
$processor.Logger.LogTrace("TEST_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "TEST_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'"
return
} else {
$params.Add("TestSubnetName", $testSubnetName)
}
}
}


$targetSubnetName = $csvItem.TARGET_SUBNET_NAME
if ([string]::IsNullOrEmpty($targetSubnetName)) {
#using default for subnet if not specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,89 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
$reportItem.AdditionalInformation = "VNET could not be retrieved for: '$($targetVnetName)'"
return
}

#region NICMapping
# NIC parameters to pass to New-AzMigrateServerReplication
$NicMapping = @()
$paramsNIC1 = @{}
$UpdatedNIC1ID = $csvItem.TFO_NIC1_ID
if ([string]::IsNullOrEmpty($UpdatedNIC1ID)) {
$processor.Logger.LogTrace("UPDATED_NIC1_ID is not mentioned for: '$($sourceMachineName)'")
if ([string]::IsNullOrEmpty($ReplicatingServermachine.ProviderSpecificDetail.VMNic[0].NicId))
{
$processor.Logger.LogTrace("We didn't find NicId at the first VMNic in replicating server for: '$($sourceMachineName)'")
}
else {
$processor.Logger.LogTrace("We found NicId at the first VMNic in replicating server, so we are going to use this for: '$($sourceMachineName)'")
$paramsNIC1.Add("NicId", $ReplicatingServermachine.ProviderSpecificDetail.VMNic[0].NicId)
}
}
else {
$paramsNIC1.Add("NicId", $UpdatedNIC1ID)
}

$NIC1_TEST_SUBNET_NAME = $csvItem.TFO_NIC1_TEST_SUBNET_NAME
if ([string]::IsNullOrEmpty($NIC1_TEST_SUBNET_NAME)) {
$processor.Logger.LogTrace("TFO_NIC1_TEST_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$paramsNIC1.Add("TestNicSubnet", $NIC1_TEST_SUBNET_NAME)
}

# NIC parameters to pass to New-AzMigrateServerReplication
$params = @{}
$paramsNIC2 = @{}
$UpdatedNIC2ID = $csvItem.TFO_NIC2_ID
if ([string]::IsNullOrEmpty($UpdatedNIC2ID)) {
$processor.Logger.LogTrace("UPDATED_NIC2_ID is not mentioned for: '$($sourceMachineName)'")
if ([string]::IsNullOrEmpty($ReplicatingServermachine.ProviderSpecificDetail.VMNic[1].NicId))
{
$processor.Logger.LogTrace("We didn't find NicId at the second VMNic in replicating server for: '$($sourceMachineName)'")
}
else {
$processor.Logger.LogTrace("We found NicId at the second VMNic in replicating server, so we are going to use this for: '$($sourceMachineName)'")
$paramsNIC2.Add("NicId", $ReplicatingServermachine.ProviderSpecificDetail.VMNic[1].NicId)
}
}
else {
$paramsNIC2.Add("NicId", $UpdatedNIC2ID)
}

$NIC2_TEST_SUBNET_NAME = $csvItem.TFO_NIC2_TEST_SUBNET_NAME
if ([string]::IsNullOrEmpty($NIC2_TEST_SUBNET_NAME)) {
$processor.Logger.LogTrace("TFO_NIC2_TEST_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$paramsNIC2.Add("TestNicSubnet", $NIC2_TEST_SUBNET_NAME)
}

#Assumption is that if $UpdatedNIC1ID is not provided then probably it doesnt need to be added
# we can also add the below code when we check this for the first time but it will be in a nested fashion so doing it here for simplicity
if (-not ([string]::IsNullOrEmpty($UpdatedNIC1ID) -and [string]::IsNullOrEmpty($ReplicatingServermachine.ProviderSpecificDetail.VMNic[0].NicId)) -and -not([string]::IsNullOrEmpty($NIC1_TEST_SUBNET_NAME))) {
$Nic1Mapping = New-AzMigrateTestNicMapping @paramsNIC1
if(-not $Nic1Mapping){
$processor.Logger.LogTrace("Nic1Mapping is not initialized for: '$($sourceMachineName)'")
}
else {
$NicMapping += $Nic1Mapping
}
}
#Assumption is that if $UpdatedNIC2ID is not provided then probably it doesnt need to be added
# we can also add the below code when we check this for the first time but it will be in a nested fashion so doing it here for simplicity
if (-not ([string]::IsNullOrEmpty($UpdatedNIC2ID) -and [string]::IsNullOrEmpty($ReplicatingServermachine.ProviderSpecificDetail.VMNic[1].NicId)) -and -not([string]::IsNullOrEmpty($NIC2_TEST_SUBNET_NAME))) {
$Nic2Mapping = New-AzMigrateTestNicMapping @paramsNIC2
if(-not $Nic2Mapping){
$processor.Logger.LogTrace("Nic2Mapping is not initialized for: '$($sourceMachineName)'")
}
else {
$NicMapping += $Nic2Mapping
}
}


if ($NicMapping.Count -gt 0) {
$params.Add("NicToUpdate", $NicMapping)
}

#Code added to accommodate for Target Subscription if the replicated machine is suppose to land in a different Target subscription
#We are reverting to Azure Migrate Subscription
Expand All @@ -110,10 +192,10 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
if([string]::IsNullOrEmpty($osUpgradeVersion)){
$processor.Logger.LogTrace("OS_UPGRADE_VERSION is not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "OS_VERSION_UPGRADE is not mentioned for: '$($sourceMachineName)'"
$TestMigrationJob = Start-AzMigrateTestMigration -InputObject $ReplicatingServermachine -TestNetworkID $Target_VNet.Id
$TestMigrationJob = Start-AzMigrateTestMigration -InputObject $ReplicatingServermachine -TestNetworkID $Target_VNet.Id @params
}
else{
$TestMigrationJob = Start-AzMigrateTestMigration -InputObject $ReplicatingServermachine -TestNetworkID $Target_VNet.Id -OsUpgradeVersion $osUpgradeVersion
$TestMigrationJob = Start-AzMigrateTestMigration -InputObject $ReplicatingServermachine -TestNetworkID $Target_VNet.Id -OsUpgradeVersion $osUpgradeVersion @params
}

if (-not $TestMigrationJob){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
}
$params.Add("SqlServerLicenseType", $sqlServerLicenseType)
}

$testVnetName = $csvItem.UPDATED_TEST_VNET_NAME
if ([string]::IsNullOrEmpty($testVnetName)) {
$processor.Logger.LogTrace("UPDATED_TEST_VNET_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$Test_VNet = Get-AzVirtualNetwork -Name $testVnetName
if (-not $Test_VNet) {
$processor.Logger.LogError("Updated VNET could not be retrieved for: '$($testVnetName)'")
$reportItem.AdditionalInformation = "Updated VNET could not be retrieved for: '$($testVnetName)'"
return
}
else {
$params.Add("TestNetworkId", $Test_VNet.Id)
}
}

#Code added to accommodate for Target Subscription if the replicated machine is suppose to land in a different Target subscription
$targetSubscriptionID = $csvItem.TARGET_SUBSCRIPTION_ID
Expand Down Expand Up @@ -368,7 +384,6 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
$processor.Logger.LogTrace("We found NicId at the first VMNic in replicating server, so we are going to use this for: '$($sourceMachineName)'")
$paramsNIC1.Add("NicId", $ReplicatingServermachine.ProviderSpecificDetail.VMNic[0].NicId)
}

}
else {
$paramsNIC1.Add("NicId", $UpdatedNIC1ID)
Expand Down Expand Up @@ -398,6 +413,15 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
return
}
}

$NIC1_TEST_SUBNET_NAME = $csvItem.UPDATED_TARGET_NIC1_TEST_SUBNET_NAME
if ([string]::IsNullOrEmpty($NIC1_TEST_SUBNET_NAME)) {
$processor.Logger.LogTrace("UPDATED_TARGET_NIC1_TEST_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$paramsNIC1.Add("TestNicSubnet", $NIC1_TEST_SUBNET_NAME)
}

$NIC1_Subnet = $csvItem.UPDATED_TARGET_NIC1_SUBNET_NAME
if ([string]::IsNullOrEmpty($NIC1_Subnet)) {$processor.Logger.LogTrace("UPDATED_TARGET_NIC1_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'")}
else {
Expand All @@ -408,6 +432,11 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
else {
$paramsNIC1.Add("TargetNicIP", $NIC1_NICIP)
}
$NIC1_TEST_IP = $csvItem.UPDATED_TARGET_NIC1_TEST_IP
if ([string]::IsNullOrEmpty($NIC1_TEST_IP)) {$processor.Logger.LogTrace("UPDATED_TARGET_NIC1_TEST_STATIC_IP is not mentioned for: '$($sourceMachineName)'")}
else {
$paramsNIC1.Add("TestNicIP", $NIC1_TEST_IP)
}

# NIC parameters to pass to New-AzMigrateServerReplication
$paramsNIC2 = @{}
Expand Down Expand Up @@ -451,6 +480,15 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
return
}
}

$NIC2_TEST_SUBNET_NAME = $csvItem.UPDATED_TARGET_NIC2_TEST_SUBNET_NAME
if ([string]::IsNullOrEmpty($NIC2_TEST_SUBNET_NAME)) {
$processor.Logger.LogTrace("UPDATED_TARGET_NIC2_TEST_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$paramsNIC2.Add("TestNicSubnet", $NIC2_TEST_SUBNET_NAME)
}

$NIC2_Subnet = $csvItem.UPDATED_TARGET_NIC2_SUBNET_NAME
if ([string]::IsNullOrEmpty($NIC2_Subnet)) {$processor.Logger.LogTrace("UPDATED_TARGET_NIC2_SUBNET_NAME is not mentioned for: '$($sourceMachineName)'")}
else {
Expand All @@ -461,6 +499,11 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
else {
$paramsNIC2.Add("TargetNicIP", $NIC2_NICIP)
}
$NIC2_TEST_NIC_IP = $csvItem.UPDATED_TARGET_NIC2_TEST_IP
if ([string]::IsNullOrEmpty($NIC2_TEST_STATIC_IP)) {$processor.Logger.LogTrace("UPDATED_TARGET_NIC2_TEST_STATIC_IP is not mentioned for: '$($sourceMachineName)'")}
else {
$paramsNIC1.Add("TestNicIP", $NIC2_TEST_NIC_IP)
}

#Assumption is that if $UpdatedNIC1ID is not provided then probably it doesnt need to be added
# we can also add the below code when we check this for the first time but it will be in a nested fashion so doing it here for simplicity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AZMIGRATEPROJECT_SUBSCRIPTION_ID,AZMIGRATEPROJECT_RESOURCE_GROUP_NAME,AZMIGRATEPROJECT_NAME,AZMIGRATE_APPLIANCE_NAME,SOURCE_MACHINE_NAME,OS_UPGRADE_VERSION,AZMIGRATEASSESSMENT_NAME,AZMIGRATEGROUP_NAME,SQL_SERVER_LICENSE_TYPE,TAG_KEY,TAG_VALUE,VM_TAG_KEY,VM_TAG_VALUE,DISK_TAG_KEY,DISK_TAG_VALUE,NIC_TAG_KEY,NIC_TAG_VALUE,TEST_NETWORK_ID,TARGET_SUBSCRIPTION_ID,TARGET_RESOURCE_GROUP_NAME,TARGET_VNET_NAME,TARGET_SUBNET_NAME,TARGET_MACHINE_NAME,TARGET_MACHINE_SIZE,LICENSE_TYPE,OS_DISK_ID,DATA_DISK1_ID,DATA_DISK2_ID,TARGET_DISKTYPE,AVAILABILITYZONE_NUMBER,AVAILABILITYSET_NAME,TURNOFF_SOURCESERVER,TESTMIGRATE_VNET_NAME,UPDATED_TAG_KEY,UPDATED_TAG_VALUE,UPDATED_TAG_OPERATION,UPDATED_VMTAG_KEY,UPDATED_VMTAG_VALUE,UPDATED_VMTAG_OPERATION,UPDATED_DISKTAG_KEY,UPDATED_DISKTAG_VALUE,UPDATED_DISKTAG_OPERATION,UPDATED_NICTAG_KEY,UPDATED_NICTAG_VALUE,UPDATED_NICTAG_OPERATION,UPDATED_TARGET_RESOURCE_GROUP_NAME,UPDATED_TARGET_VNET_NAME,UPDATED_TARGET_MACHINE_NAME,UPDATED_TARGET_DISK_NAME,UPDATED_TARGET_OS_DISK_NAME,UPDATED_TARGET_DATA_DISK1_NAME,UPDATED_TARGET_DATA_DISK2_NAME,UPDATED_TARGET_MACHINE_SIZE,UPDATED_AVAILABILITYZONE_NUMBER,UPDATED_AVAILABILITYSET_NAME,UPDATED_NIC1_ID,UPDATED_TARGET_NIC1_NAME,UPDATED_TARGET_NIC1_SELECTIONTYPE,UPDATED_TARGET_NIC1_SUBNET_NAME,UPDATED_TARGET_NIC1_IP,UPDATED_TARGET_NIC1_TEST_IP,UPDATED_TARGET_NIC1_TEST_SUBNET_NAME,UPDATED_NIC2_ID,UPDATED_TARGET_NIC2_NAME,UPDATED_TARGET_NIC2_SELECTIONTYPE,UPDATED_TARGET_NIC2_SUBNET_NAME,UPDATED_TARGET_NIC2_IP,UPDATED_TARGET_NIC2_TEST_IP,UPDATED_TARGET_NIC2_TEST_SUBNET_NAME,OK_TO_UPDATE,OK_TO_MIGRATE,OK_TO_USE_ASSESSMENT,OK_TO_TESTMIGRATE,OK_TO_RETRIEVE_REPLICATIONSTATUS,OK_TO_CLEANUP,OK_TO_TESTMIGRATE_CLEANUP
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,srcrg-ecy,ECYPROJ,ecyapp,testvm-cvm3,Microsoft Windows Server 2022 (64-bit),,srcrg-ecy,PAYG,,,"vm-tag-1,vm-tag-2","vm-tag-val-1,vm-tag-val-2","d1,d2","d1-val,d2-val",n1,n1-val,,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,sv-target-ecy-rg,vnet-name,default,testvm-1,,NoLicenseType,,,,,,,Y,vnet-ecy,,,,"up-vm-1,up-vm-2","up-vm-value-1,up-vm-value-2",Replace,disk-1,disk-1-tag,Merge,,,,,,testvm-sv-1,,,,,,,,,nic-name-updated,,,,,AzureBastionSubnet,,,,,,,,Y,Y,Y,Y,Y,Y,Y
AZMIGRATEPROJECT_SUBSCRIPTION_ID,AZMIGRATEPROJECT_RESOURCE_GROUP_NAME,AZMIGRATEPROJECT_NAME,AZMIGRATE_APPLIANCE_NAME,SOURCE_MACHINE_NAME,OS_UPGRADE_VERSION,AZMIGRATEASSESSMENT_NAME,AZMIGRATEGROUP_NAME,SQL_SERVER_LICENSE_TYPE,TAG_KEY,TAG_VALUE,VM_TAG_KEY,VM_TAG_VALUE,DISK_TAG_KEY,DISK_TAG_VALUE,NIC_TAG_KEY,NIC_TAG_VALUE,TEST_VNET_NAME,TEST_SUBNET_NAME,TARGET_SUBSCRIPTION_ID,TARGET_RESOURCE_GROUP_NAME,TARGET_VNET_NAME,TARGET_SUBNET_NAME,TARGET_MACHINE_NAME,TARGET_MACHINE_SIZE,LICENSE_TYPE,OS_DISK_ID,DATA_DISK1_ID,DATA_DISK2_ID,TARGET_DISKTYPE,AVAILABILITYZONE_NUMBER,AVAILABILITYSET_NAME,TURNOFF_SOURCESERVER,TESTMIGRATE_VNET_NAME,UPDATED_TEST_VNET_NAME,UPDATED_TAG_KEY,UPDATED_TAG_VALUE,UPDATED_TAG_OPERATION,UPDATED_VMTAG_KEY,UPDATED_VMTAG_VALUE,UPDATED_VMTAG_OPERATION,UPDATED_DISKTAG_KEY,UPDATED_DISKTAG_VALUE,UPDATED_DISKTAG_OPERATION,UPDATED_NICTAG_KEY,UPDATED_NICTAG_VALUE,UPDATED_NICTAG_OPERATION,UPDATED_TARGET_RESOURCE_GROUP_NAME,UPDATED_TARGET_VNET_NAME,UPDATED_TARGET_MACHINE_NAME,UPDATED_TARGET_DISK_NAME,UPDATED_TARGET_OS_DISK_NAME,UPDATED_TARGET_DATA_DISK1_NAME,UPDATED_TARGET_DATA_DISK2_NAME,UPDATED_TARGET_MACHINE_SIZE,UPDATED_AVAILABILITYZONE_NUMBER,UPDATED_AVAILABILITYSET_NAME,UPDATED_NIC1_ID,TFO_NIC1_ID,UPDATED_TARGET_NIC1_NAME,UPDATED_TARGET_NIC1_SELECTIONTYPE,UPDATED_TARGET_NIC1_SUBNET_NAME,UPDATED_TARGET_NIC1_IP,UPDATED_TARGET_NIC1_TEST_IP,UPDATED_TARGET_NIC1_TEST_SUBNET_NAME,TFO_NIC1_TEST_SUBNET_NAME,UPDATED_NIC2_ID,TFO_NIC2_ID,UPDATED_TARGET_NIC2_NAME,UPDATED_TARGET_NIC2_SELECTIONTYPE,UPDATED_TARGET_NIC2_SUBNET_NAME,UPDATED_TARGET_NIC2_IP,UPDATED_TARGET_NIC2_TEST_IP,UPDATED_TARGET_NIC2_TEST_SUBNET_NAME,TFO_NIC2_TEST_SUBNET_NAME,OK_TO_UPDATE,OK_TO_MIGRATE,OK_TO_USE_ASSESSMENT,OK_TO_TESTMIGRATE,OK_TO_RETRIEVE_REPLICATIONSTATUS,OK_TO_CLEANUP,OK_TO_TESTMIGRATE_CLEANUP
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx,srcrg-ecy,ECYPROJ,sv-app-2,rthapliyal-cs-01,Microsoft Windows Server 2019 (64-bit),,srcrg-ecy,PAYG,"t-1,t-2","tv-1,tv-2","vm-tag-1,vm-tag-2","vm-tag-val-1,vm-tag-val-2","d1,d2","d1-val,d2-val",n1,n1-val,vnet,testing,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx,srcrg-ecy,vnet-ecy,default,testvm-xx,,NoLicenseType,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx,,,,Y,sv-vnet,vnet,ut-1,utv-1,Merge,"up-vm-1,up-vm-2","up-vm-value-1,up-vm-value-2",Replace,disk-1,disk-1-tag,Merge,,,,,,testvm-sv-x1,t-disk-name,os-disk-name,data-disk1-name,,,,,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx,nic-name-updated,,,x.x.x.x,x.x.x.x,testMigrationSubnet,testSubnet,,,,,,,,,,Y,Y,Y,Y,Y,Y,Y