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

Commit 1923fbf

Browse files
Custom Resource Tagging Feature (#404)
* Custom Resource Tagging Feature * refactor and input changed * tagging logic changed, code refactored * logs comment edited
1 parent 6294943 commit 1923fbf

File tree

3 files changed

+202
-5
lines changed

3 files changed

+202
-5
lines changed

azure-migrate/migrate-at-scale-vmware-agentles/Agentless VMware automation/AzMigrate_StartReplication.ps1

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,106 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
5454
return
5555
}
5656

57+
$tagKeys = $csvItem.TAG_KEY
58+
$tagValues = $csvItem.TAG_VALUE
59+
$tagDict = @{}
60+
61+
if ([string]::IsNullOrEmpty($tagKeys) -or [string]::IsNullOrEmpty($tagValues)) {
62+
$processor.Logger.LogTrace("Tag Key/Value not mentioned for: '$($sourceMachineName)'")
63+
$reportItem.AdditionalInformation = "Tag Key/Value not mentioned for: '$($sourceMachineName)'"
64+
}
65+
else{
66+
$tagKeys = $tagKeys -split ","
67+
$tagValues = $tagValues -split ","
68+
# check if the count is equal for keys and values
69+
if ($tagKeys.Count -ne $tagValues.Count) {
70+
$processor.Logger.LogTrace("Tag Key/Value count mismatch for: '$($sourceMachineName)'")
71+
$reportItem.AdditionalInformation = "Tag Key/Value count mismatch for: '$($sourceMachineName)'"
72+
return
73+
}
74+
else{
75+
for ($i = 0; $i -lt $tagKeys.Count; $i++) {
76+
$tagDict.Add($tagKeys[$i], $tagValues[$i])
77+
}
78+
$params.Add("Tag", $tagDict)
79+
}
80+
}
81+
82+
$vmTagKeys = $csvItem.VM_TAG_KEY
83+
$vmTagValues = $csvItem.VM_TAG_VALUE
84+
$vmTagDict = @{}
85+
86+
if ([string]::IsNullOrEmpty($vmTagKeys) -or [string]::IsNullOrEmpty($vmTagValues)) {
87+
$processor.Logger.LogTrace("VM Tag Key/Value not mentioned for: '$($sourceMachineName)'")
88+
$reportItem.AdditionalInformation = "VM Tag Key/Value not mentioned for: '$($sourceMachineName)'"
89+
}
90+
else{
91+
$vmTagKeys = $vmTagKeys -split ","
92+
$vmTagValues = $vmTagValues -split ","
93+
# check if the count is equal for keys and values
94+
if ($vmTagKeys.Count -ne $vmTagValues.Count) {
95+
$processor.Logger.LogTrace("VM Tag Key/Value count mismatch for: '$($sourceMachineName)'")
96+
$reportItem.AdditionalInformation = "VM Tag Key/Value count mismatch for: '$($sourceMachineName)'"
97+
return
98+
}
99+
else{
100+
for ($i = 0; $i -lt $vmTagKeys.Count; $i++) {
101+
$vmTagDict.Add($vmTagKeys[$i], $vmTagValues[$i])
102+
}
103+
$params.Add("VmTag", $vmTagDict)
104+
}
105+
}
106+
107+
$diskTagKeys = $csvItem.DISK_TAG_KEY
108+
$diskTagValues = $csvItem.DISK_TAG_VALUE
109+
$diskTagDict = @{}
110+
111+
if ([string]::IsNullOrEmpty($diskTagKeys) -or [string]::IsNullOrEmpty($diskTagValues)) {
112+
$processor.Logger.LogTrace("Disk Tag Key/Value not mentioned for: '$($sourceMachineName)'")
113+
$reportItem.AdditionalInformation = "Disk Tag Key/Value not mentioned for: '$($sourceMachineName)'"
114+
}
115+
else{
116+
$diskTagKeys = $diskTagKeys -split ","
117+
$diskTagValues = $diskTagValues -split ","
118+
# check if the count is equal for keys and values
119+
if ($diskTagKeys.Count -ne $diskTagValues.Count) {
120+
$processor.Logger.LogTrace("Disk Tag Key/Value count mismatch for: '$($sourceMachineName)'")
121+
$reportItem.AdditionalInformation = "Disk Tag Key/Value count mismatch for: '$($sourceMachineName)'"
122+
return
123+
}
124+
else{
125+
for ($i = 0; $i -lt $diskTagKeys.Count; $i++) {
126+
$diskTagDict.Add($diskTagKeys[$i], $diskTagValues[$i])
127+
}
128+
$params.Add("DiskTag", $diskTagDict)
129+
}
130+
}
131+
132+
$nicTagKey = $csvItem.NIC_TAG_KEY
133+
$nicTagValue = $csvItem.NIC_TAG_VALUE
134+
$nicTagDict = @{}
135+
136+
if ([string]::IsNullOrEmpty($nicTagKey) -or [string]::IsNullOrEmpty($nicTagValue)) {
137+
$processor.Logger.LogTrace("NIC Tag Key/Value not mentioned for: '$($sourceMachineName)'")
138+
$reportItem.AdditionalInformation = "NIC Tag Key/Value not mentioned for: '$($sourceMachineName)'"
139+
}
140+
else{
141+
$nicTagKey = $nicTagKey -split ","
142+
$nicTagValue = $nicTagValue -split ","
143+
# check if the count is equal for keys and values
144+
if ($nicTagKey.Count -ne $nicTagValue.Count) {
145+
$processor.Logger.LogTrace("NIC Tag Key/Value count mismatch for: '$($sourceMachineName)'")
146+
$reportItem.AdditionalInformation = "NIC Tag Key/Value count mismatch for: '$($sourceMachineName)'"
147+
return
148+
}
149+
else{
150+
for ($i = 0; $i -lt $nicTagKey.Count; $i++) {
151+
$nicTagDict.Add($nicTagKey[$i], $nicTagValue[$i])
152+
}
153+
$params.Add("NicTag", $nicTagDict)
154+
}
155+
}
156+
57157
#Code added to accommodate for Target Subscription if the replicated machine is suppose to land in a different Target subscription
58158
$targetSubscriptionID = $csvItem.TARGET_SUBSCRIPTION_ID
59159
if ([string]::IsNullOrEmpty($targetSubscriptionID)) {

azure-migrate/migrate-at-scale-vmware-agentles/Agentless VMware automation/AzMigrate_UpdateMachineProperties.ps1

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,106 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
101101
$params.Add("TargetResourceGroupID", $Target_RG.ResourceId)
102102
}
103103
}
104+
105+
$updateTagKey = $csvItem.UPDATED_TAG_KEY
106+
$updateTagValue = $csvItem.UPDATED_TAG_VALUE
107+
$updateTagOperation = $csvItem.UPDATED_TAG_OPERATION
108+
$updateTagDict = @{}
109+
if ([string]::IsNullOrEmpty($updateTagKey) -or [string]::IsNullOrEmpty($updateTagValue) -or [string]::IsNullOrEmpty($updateTagOperation)) {
110+
$processor.Logger.LogTrace("UPDATED_TAG_KEY or UPDATED_TAG_VALUE or UPDATED_TAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
111+
}
112+
else {
113+
$updateTagKeys = $updateTagKey.Split(",")
114+
$updateTagValues = $updateTagValue.Split(",")
115+
116+
if ($updateTagKeys.Count -ne $updateTagValues.Count) {
117+
$processor.Logger.LogTrace("UPDATED_TAG_KEY and UPDATED_TAG_VALUE count is not same for: '$($sourceMachineName)'")
118+
$reportItem.AdditionalInformation = "UPDATED_TAG_KEY and UPDATED_TAG_VALUE count is not same for: '$($sourceMachineName)'"
119+
return
120+
}
121+
else {
122+
for ($i=0; $i -lt $updateTagKeys.Count; $i++) {
123+
$updateTagDict.Add($updateTagKeys[$i], $updateTagValues[$i])
124+
}
125+
$params.Add("UpdateTag", $updateTagDict)
126+
$params.Add("UpdateTagOperation", $updateTagOperation)
127+
}
128+
}
129+
130+
$updateVmTagKey = $csvItem.UPDATED_VMTAG_KEY
131+
$updateVmTagValue = $csvItem.UPDATED_VMTAG_VALUE
132+
$updateVmTagOperation = $csvItem.UPDATED_VMTAG_OPERATION
133+
$updateVmTagDict = @{}
134+
if ([string]::IsNullOrEmpty($updateVmTagKey) -or [string]::IsNullOrEmpty($updateVmTagValue) -or [string]::IsNullOrEmpty($updateVmTagOperation)) {
135+
$processor.Logger.LogTrace("UPDATED_VM_TAG_KEY or UPDATED_VM_TAG_VALUE or UPDATED_VMTAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
136+
}
137+
else {
138+
$updateVmTagKeys = $updateVmTagKey.Split(",")
139+
$updateVmTagValues = $updateVmTagValue.Split(",")
140+
141+
if ($updateVmTagKeys.Count -ne $updateVmTagValues.Count) {
142+
$processor.Logger.LogTrace("UPDATED_VM_TAG_KEY and UPDATED_VM_TAG_VALUE count is not same for: '$($sourceMachineName)'")
143+
$reportItem.AdditionalInformation = "UPDATED_VM_TAG_KEY and UPDATED_VM_TAG_VALUE count is not same for: '$($sourceMachineName)'"
144+
return
145+
}
146+
else {
147+
for ($i=0; $i -lt $updateVmTagKeys.Count; $i++) {
148+
$updateVmTagDict.Add($updateVmTagKeys[$i], $updateVmTagValues[$i])
149+
}
150+
$params.Add("UpdateVmTag", $updateVmTagDict)
151+
$params.Add("UpdateVmTagOperation", $updateVmTagOperation)
152+
}
153+
}
154+
155+
$updateDiskTagKey = $csvItem.UPDATED_DISKTAG_KEY
156+
$updateDiskTagValue = $csvItem.UPDATED_DISKTAG_VALUE
157+
$updateDiskTagOperation = $csvItem.UPDATED_DISKTAG_OPERATION
158+
$updateDiskTagDict = @{}
159+
if ([string]::IsNullOrEmpty($updateDiskTagKey) -or [string]::IsNullOrEmpty($updateDiskTagValue) -or [string]::IsNullOrEmpty($updateDiskTagOperation)) {
160+
$processor.Logger.LogTrace("UPDATED_DISKTAG_KEY or UPDATED_DISKTAG_VALUE or UPDATED_DISKTAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
161+
}
162+
else {
163+
$updateDiskTagKeys = $updateDiskTagKey.Split(",")
164+
$updateDiskTagValues = $updateDiskTagValue.Split(",")
165+
166+
if ($updateDiskTagKeys.Count -ne $updateDiskTagValues.Count) {
167+
$processor.Logger.LogTrace("UPDATED_DISKTAG_KEY and UPDATED_DISKTAG_VALUE count is not same for: '$($sourceMachineName)'")
168+
$reportItem.AdditionalInformation = "UPDATED_DISKTAG_KEY and UPDATED_DISKTAG_VALUE count is not same for: '$($sourceMachineName)'"
169+
return
170+
}
171+
else {
172+
for ($i=0; $i -lt $updateDiskTagKeys.Count; $i++) {
173+
$updateDiskTagDict.Add($updateDiskTagKeys[$i], $updateDiskTagValues[$i])
174+
}
175+
$params.Add("UpdateDiskTag", $updateDiskTagDict)
176+
$params.Add("UpdateDiskTagOperation", $updateDiskTagOperation)
177+
}
178+
}
179+
180+
$updateNicTagKey = $csvItem.UPDATED_NICTAG_KEY
181+
$updateNicTagValue = $csvItem.UPDATED_NICTAG_VALUE
182+
$updateNicTagOperation = $csvItem.UPDATED_NICTAG_OPERATION
183+
$updateNicTagDict = @{}
184+
if ([string]::IsNullOrEmpty($updateNicTagKey) -or [string]::IsNullOrEmpty($updateNicTagValue) -or [string]::IsNullOrEmpty($updateNicTagOperation)) {
185+
$processor.Logger.LogTrace("UPDATED_NICTAG_KEY or UPDATED_NICTAG_VALUE or UPDATED_NICTAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
186+
}
187+
else {
188+
$updateNicTagKeys = $updateNicTagKey.Split(",")
189+
$updateNicTagValues = $updateNicTagValue.Split(",")
190+
191+
if ($updateNicTagKeys.Count -ne $updateNicTagValues.Count) {
192+
$processor.Logger.LogTrace("UPDATED_NICTAG_KEY and UPDATED_NICTAG_VALUE count is not same for: '$($sourceMachineName)'")
193+
$reportItem.AdditionalInformation = "UPDATED_NICTAG_KEY and UPDATED_NICTAG_VALUE count is not same for: '$($sourceMachineName)'"
194+
return
195+
}
196+
else {
197+
for ($i=0; $i -lt $updateNicTagKeys.Count; $i++) {
198+
$updateNicTagDict.Add($updateNicTagKeys[$i], $updateNicTagValues[$i])
199+
}
200+
$params.Add("UpdateNicTag", $updateNicTagDict)
201+
$params.Add("UpdateNicTagOperation", $updateNicTagOperation)
202+
}
203+
}
104204

105205

106206
#Get the Target VirtualNetwork Name where we want to provision the VM in Azure
@@ -302,9 +402,6 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
302402
}
303403
#endregion
304404

305-
306-
307-
308405
# Start replication for a discovered VM in an Azure Migrate project
309406
$processor.Logger.LogTrace( "Starting Update Job for source '$($sourceMachineName)'")
310407
$UpdateJob = Set-AzMigrateServerReplication @params
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
AZMIGRATEPROJECT_SUBSCRIPTION_ID,AZMIGRATEPROJECT_RESOURCE_GROUP_NAME,AZMIGRATEPROJECT_NAME,SOURCE_MACHINE_NAME,AZMIGRATEASSESSMENT_NAME,AZMIGRATEGROUP_NAME,SQL_SERVER_LICENSE_TYPE,TARGET_SUBSCRIPTION_ID,TARGET_RESOURCE_GROUP_NAME,TARGET_VNET_NAME,TARGET_SUBNET_NAME,TARGET_MACHINE_NAME,TARGET_MACHINE_SIZE,LICENSE_TYPE,OS_DISK_ID,TARGET_DISKTYPE,AVAILABILITYZONE_NUMBER,AVAILABILITYSET_NAME,TURNOFF_SOURCESERVER,TESTMIGRATE_VNET_NAME,UPDATED_TARGET_RESOURCE_GROUP_NAME,UPDATED_TARGET_VNET_NAME,UPDATED_TARGET_MACHINE_NAME,UPDATED_TARGET_MACHINE_SIZE,UPDATED_AVAILABILITYZONE_NUMBER,UPDATED_AVAILABILITYSET_NAME,UPDATED_NIC1_ID,UPDATED_TARGET_NIC1_SELECTIONTYPE,UPDATED_TARGET_NIC1_SUBNET_NAME,UPDATED_TARGET_NIC1_IP,UPDATED_NIC2_ID,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
2-
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,srcrg-ecy,ECYPROJ,testvm-cvm3,,srcrg-ecy,PAYG,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,sv-target-ecy-rg,vnet-name,default,testvm-1,,NoLicenseType,,,,,Y,vnet-ecy,,,testvm-sv-1,,,,,,,,,,,,Y,Y,Y,Y,Y,Y,Y
1+
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
2+
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

0 commit comments

Comments
 (0)