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

Commit

Permalink
Custom Resource Naming (#406)
Browse files Browse the repository at this point in the history
* Custom Resource Naming Feature

* Remove Logs

* Refactoring if/else statements

* logic changed

* resolving comments

* resource naming logic changed

* added check for diskMapping Length>0

* remove log statement
  • Loading branch information
shivamverma-ms authored Aug 29, 2023
1 parent 50789f5 commit a536ea1
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,76 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
}
#End Code for Target Subscription

$targetDiskName = $csvItem.UPDATED_TARGET_DISK_NAME
if ([string]::IsNullOrEmpty($targetDiskName)) {
$processor.Logger.LogTrace("UPDATED_TARGET_DISK_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$params.Add("TargetDiskName", $targetDiskName)
}

$diskMapping = @()
$paramsDisk1 = @{}
$osDiskId = $csvItem.OS_DISK_ID
$osDiskName = $csvItem.UPDATED_TARGET_OS_DISK_NAME

if ([string]::IsNullOrEmpty($osDiskId)) {
$processor.Logger.LogTrace("OS_DISK_ID is not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "OS_DISK_ID is not mentioned for: '$($sourceMachineName)'"
}
else {
$paramsDisk1.Add("DiskId", $osDiskId)
$paramsDisk1.Add("IsOSDisk", $true)
if ([string]::IsNullOrEmpty($osDiskName)) {
$processor.Logger.LogTrace("UPDATED_TARGET_OS_DISK_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$paramsDisk1.Add("TargetDiskName", $osDiskName)
}
$diskMapping+= $paramsDisk1
}

$paramsDisk2 = @{}
$dataDisk1Id = $csvItem.DATA_DISK1_ID
$dataDisk1Name = $csvItem.UPDATED_TARGET_DATA_DISK1_NAME
if ([string]::IsNullOrEmpty($dataDisk1Id)) {
$processor.Logger.LogTrace("DATA_DISK1_ID is not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "DATA_DISK1_ID is not mentioned for: '$($sourceMachineName)'"
}
else {
$paramsDisk2.Add("DiskId", $dataDisk1Id)
$paramsDisk2.Add("IsOSDisk", $false)
if ([string]::IsNullOrEmpty($dataDisk1Name)) {
$processor.Logger.LogTrace("UPDATED_TARGET_DATA_DISK1_NAME is not mentioned for: '$($sourceMachineName)'")
}
else {
$paramsDisk2.Add("TargetDiskName", $dataDisk1Name)
}
$diskMapping+= $paramsDisk2
}

$paramsDisk3 = @{}
$dataDisk2Id = $csvItem.DATA_DISK2_ID
$dataDisk2Name = $csvItem.UPDATED_TARGET_DATA_DISK2_NAME
if ([string]::IsNullOrEmpty($dataDisk2Id)) {
$processor.Logger.LogTrace("DATA_DISK2_ID is not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "DATA_DISK2_ID is not mentioned for: '$($sourceMachineName)'"
}
else {
$paramsDisk3.Add("DiskId", $dataDisk2Id)
$paramsDisk3.Add("IsOSDisk", $false)
if ([string]::IsNullOrEmpty($dataDisk2Name)) {
$processor.Logger.LogTrace("UPDATED_TARGET_DATA_DISK2_NAME is not mentioned for: '$($sourceMachineName)'")
}else {
$paramsDisk3.Add("TargetDiskName", $dataDisk2Name)
}
$diskMapping+= $paramsDisk3
}

if ($diskMapping.Count -gt 0) {
$params.Add("DiskToUpdate", $diskMapping)
}

$targetMachineName = $csvItem.UPDATED_TARGET_MACHINE_NAME
if ([string]::IsNullOrEmpty($targetMachineName)) {
$processor.Logger.LogTrace("UPDATED_TARGET_MACHINE_NAME is not mentioned for: '$($sourceMachineName)'")
Expand Down Expand Up @@ -303,6 +373,15 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
else {
$paramsNIC1.Add("NicId", $UpdatedNIC1ID)
}

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

$NIC1_SelectionType = $csvItem.UPDATED_TARGET_NIC1_SELECTIONTYPE
#Specifies whether the NIC to be updated will be the Primary, Secondary or not migrated ("DoNotCreate")
if ([string]::IsNullOrEmpty($NIC1_SelectionType)) {
Expand Down Expand Up @@ -347,6 +426,15 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
else {
$paramsNIC2.Add("NicId", $UpdatedNIC2ID)
}

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

$NIC2_SelectionType = $csvItem.UPDATED_TARGET_NIC2_SELECTIONTYPE
#Specifies whether the NIC to be updated will be the Primary, Secondary or not migrated ("DoNotCreate")
if ([string]::IsNullOrEmpty($NIC2_SelectionType)) {
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,SOURCE_MACHINE_NAME,AZMIGRATEASSESSMENT_NAME,AZMIGRATE_APPLIANCE_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,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_NIC2_ID,UPDATED_TARGET_NIC2_NAME,UPDATED_TARGET_NIC2_SELECTIONTYPE,UPDATED_TARGET_NIC2_SUBNET_NAME,UPDATED_TARGET_NIC2_IP,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,testvm-cvm3,,sv-app-2,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-ecy,default,testvm-1,,NoLicenseType,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,,,,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,,,,,,,,,Y,Y,Y,Y,Y,Y,Y
AZMIGRATEPROJECT_SUBSCRIPTION_ID,AZMIGRATEPROJECT_RESOURCE_GROUP_NAME,AZMIGRATEPROJECT_NAME,SOURCE_MACHINE_NAME,AZMIGRATEASSESSMENT_NAME,AZMIGRATE_APPLIANCE_NAME,OS_UPGRADE_VERSION,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,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_NIC2_ID,UPDATED_TARGET_NIC2_NAME,UPDATED_TARGET_NIC2_SELECTIONTYPE,UPDATED_TARGET_NIC2_SUBNET_NAME,UPDATED_TARGET_NIC2_IP,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,test-ubun22-server-bios-lvm,,sv-app-2,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-xxxxxxxxxxx,sv-target-ecy-rg,vnet-ecy,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,,,,,,,,,Y,Y,Y,Y,Y,Y,Y

0 comments on commit a536ea1

Please sign in to comment.