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

Commit bc1ed77

Browse files
Adding Hyperv and server fabric support to dependency mapping powershell commands ( earlier limited to only VMware) (#421)
* modified: azure-migrate/dependencies-at-scale/AzMig_Dependencies.psm1 * modified: azure-migrate/dependencies-at-scale/AzMig_Dependencies.psm1
1 parent d82b06b commit bc1ed77

File tree

1 file changed

+102
-13
lines changed

1 file changed

+102
-13
lines changed

azure-migrate/dependencies-at-scale/AzMig_Dependencies.psm1

+102-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
Set-Variable -Name AMH_APIVERSION -Value "?api-version=2018-09-01-preview" -Option Constant -Scope Script -Force
55
Set-Variable -Name SDS_APIVERSION -Value "?api-version=2020-01-01" -Option Constant -Scope Script -Force
6+
Set-Variable -Name HyperVandServer_APIVERSION -Value "?api-version=2020-08-01-preview" -Option Constant -Scope Script -Force
67
Set-Variable -Name SAS_APIVERSION -Value "?api-version=2019-10-01" -Option Constant -Scope Script -Force
78
Set-Variable -Name RSV_APIVERSION -Value "?api-version=2018-07-10" -Option Constant -Scope Script -Force
89

@@ -156,16 +157,13 @@ function Get-AzMigDiscoveredVMwareVMs {
156157
throw "Server Discovery Solution missing Appliance Details. Invalid Solution."
157158
}
158159

159-
160-
161-
162160
$vmwareappliancemap = @{}
163161
#Discard non-VMware appliances
164162
#If Appliance name is passed get data only for that appliance
165163
#If Appliance name is not passed , get data for all appliances in that project
166164
if (-not $ApplianceName){
167-
$appMap.GetEnumerator() | foreach {if($_.Value -match "VMwareSites") {$vmwareappliancemap[$_.Key] = $_.Value}}}else{
168-
$appMap.GetEnumerator() | foreach {if($_.Value -match "VMwareSites" -and $_.Key -eq $ApplianceName) {$vmwareappliancemap[$_.Key] = $_.Value}}}
165+
$appMap.GetEnumerator() | foreach {if($_.Value -match "VMwareSites|HyperVSites|ServerSites") {$vmwareappliancemap[$_.Key] = $_.Value}}}else{
166+
$appMap.GetEnumerator() | foreach {if($_.Value -match "VMwareSites|HyperVSites|ServerSites" -and $_.Key -eq $ApplianceName) {$vmwareappliancemap[$_.Key] = $_.Value}}}
169167
Write-Debug $vmwareappliancemap.count
170168
if($vmwareappliancemap) {$vmwareappliancemap | Out-String | Write-Debug};
171169
if (-not $vmwareappliancemap.count) {throw "No VMware VMs discovered in project"};
@@ -176,7 +174,11 @@ function Get-AzMigDiscoveredVMwareVMs {
176174
foreach ($item in $vmwareappliancemap.GetEnumerator()) {
177175
$SiteId = $item.Value;
178176
Write-Debug "Get machines for Site $SiteId"
179-
$requesturi = $Properties['baseurl'] + $SiteId + "/machines" + $SDS_APIVERSION + "&`$top=400"
177+
if($SiteId -match "(/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" -or $SiteId -match "(/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)"){
178+
$requesturi = $Properties['baseurl'] + $SiteId + "/machines" + $HyperVandServer_APIVERSION + "&`$top=400"}
179+
if($SiteId -match "(/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)" ){
180+
$requesturi = $Properties['baseurl'] + $SiteId + "/machines" + $SDS_APIVERSION + "&`$top=400"}
181+
180182

181183
#Write-Host $requesturi
182184

@@ -209,7 +211,6 @@ function Get-AzMigDiscoveredVMwareVMs {
209211
}
210212
}
211213

212-
213214
if ($DiscoveredMachines.count -gt 0) {
214215

215216
$DiscoveredMachines | Select-Object -Property @{ expression={$_.properties.displayName}; label='VM display name'}, @{ expression={$_.properties.dependencymapping}; label='Current status'}, @{ expression={$_.id}; label='ARM ID'} | Export-Csv -NoTypeInformation -Path $OutputCsvFile
@@ -254,9 +255,11 @@ function Set-AzMigDependencyMappingAgentless {
254255

255256
if($Enable)
256257
{
257-
$ActionVerb = "Enabled"
258+
$ActionVerb = "Enabled";
259+
$EnableDependencyMapping = $true;
258260
} elseif ($Disable) {
259-
$ActionVerb = "Disabled"
261+
$ActionVerb = "Disabled";
262+
$EnableDependencyMapping = $false;
260263
} else {
261264
throw "Error"
262265
}
@@ -283,7 +286,6 @@ function Set-AzMigDependencyMappingAgentless {
283286
$currentsite = $null
284287
foreach ($machine in $VMs) {
285288
if (-not ($machine -match "(/subscriptions/.*\/VMwareSites/([^\/]*)\w{4}site)")) {
286-
Write-Debug "Skipping $machine"
287289
continue;
288290
}
289291

@@ -347,8 +349,86 @@ function Set-AzMigDependencyMappingAgentless {
347349
else {
348350
throw "Could not update dependency mapping status for input VMs on appliance: $appliancename"
349351
}
352+
}
353+
354+
#Reset jsonpayload and loop through the same machines , this time for hyperV and server fabric
355+
$jsonPayload.machines = @();
356+
357+
$currentsite = $null
358+
foreach ($machine in $VMs) {
359+
if (-not ($machine -match "(/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $machine -match "(/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" )) {
360+
continue;
361+
}
362+
363+
$sitename = $Matches[1];
364+
Write-Debug "Site: $sitename Machine: $machine";
365+
366+
if((-not $currentsite) -or ($sitename -eq $currentsite)) {
367+
$currentsite = $sitename;
368+
$tempobj= [PSCustomObject]@{
369+
machineId = $machine
370+
isDependencyMapToBeEnabled = $EnableDependencyMapping
371+
}
372+
$jsonPayload.machines += $tempobj;
373+
continue;
374+
}
375+
376+
#different site. Send update request for previous site and start building request for the new site
377+
if ($sitename -ne $currentsite) {
378+
if ($jsonPayload.machines.count) {
379+
$requestbody = $jsonPayload | ConvertTo-Json
380+
$requestbody | Write-Debug
381+
$requesturi = $Properties['baseurl'] + ${currentsite} + "/UpdateDependencyMapStatus" + $HyperVandServer_APIVERSION;
382+
Write-Debug "request uri is : $requesturi"
383+
$response = $null
384+
$response = Invoke-RestMethod -Method Post -Headers $Properties['Headers'] -Body $requestbody $requesturi -ContentType "application/json"
385+
if ($response) {
386+
$temp = $currentsite -match "\/([^\/]*)\w{4}site$" # Extract the appliance name
387+
$appliancename = $Matches[1]
388+
Write-Output "Updated dependency mapping status for input VMs on appliance: $appliancename"
389+
}
390+
else {
391+
throw "Could not update dependency mapping status"
392+
}
393+
}
394+
395+
#Reset jsonpayload
396+
$jsonPayload.machines = @();
397+
$tempobj= [PSCustomObject]@{
398+
machineId = $machine
399+
isDependencyMapToBeEnabled = $EnableDependencyMapping
400+
}
401+
$jsonPayload.machines += $tempobj;
402+
$currentsite = $sitename #update current site name
403+
}
350404
}
351405

406+
407+
#Enable/Disable dependency for unprocessed sites
408+
if ($jsonPayload.machines.count) {
409+
$requestbody = $jsonPayload | ConvertTo-Json
410+
$requestbody | Write-Debug
411+
$requesturi = $Properties['baseurl'] + ${currentsite} + "/UpdateDependencyMapStatus" + $HyperVandServer_APIVERSION;
412+
Write-Debug $requesturi
413+
$response = $null
414+
$response = Invoke-RestMethod -Method Post -Headers $Properties['Headers'] -Body $requestbody $requesturi -ContentType "application/json"
415+
$temp = $currentsite -match "\/([^\/]*)\w{4}site$" # Extract the appliance name
416+
$appliancename = $Matches[1]
417+
if ($response) {
418+
Write-Output "Updating dependency mapping status for input VMs on appliance: $appliancename"
419+
}
420+
else {
421+
throw "Could not update dependency mapping status for input VMs on appliance: $appliancename"
422+
}
423+
}
424+
425+
# Pointing out all the incorrect ARM IDs
426+
foreach ($machine in $VMs) {
427+
if (-not ($machine -match "(/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $machine -match "(/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" -or $machine -match "(/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)" )) {
428+
Write-Output "Skipping the machine : $machine . Please check the ARM ID"
429+
}
430+
}
431+
352432
}
353433
Export-ModuleMember -Function Set-AzMigDependencyMappingAgentless
354434

@@ -422,7 +502,13 @@ function Get-AzMigDependenciesAgentless {
422502
return;
423503
}
424504

425-
$url = $Properties['baseurl'] + $VMWareSiteID + "/exportDependencies?api-version=2020-01-01-preview"
505+
Write-Output $VMWareSiteID
506+
507+
if($VMWareSiteID -match "(/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)"){
508+
$url = $Properties['baseurl'] + $VMWareSiteID + "/exportDependencies?api-version=2020-01-01-preview" }
509+
510+
if($VMWareSiteID -match "(/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $VMWareSiteID -match "(/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)"){
511+
$url = $Properties['baseurl'] + $VMWareSiteID + "/exportDependencies?api-version=2020-08-01-preview" }
426512

427513
$StartTime = Get-Date
428514

@@ -446,8 +532,11 @@ $jsonPayload = @"
446532
throw "Could not retrieve the site for appliance $appliancename"
447533
}
448534

449-
450-
$url = $Properties['baseurl'] + $response.id + "?api-version=2020-01-01-preview"
535+
if($VMWareSiteID -match "(/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)"){
536+
$url = $Properties['baseurl'] + $response.id + "?api-version=2020-01-01-preview"}
537+
538+
if($VMWareSiteID -match "(/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $VMWareSiteID -match "(/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)"){
539+
$url = $Properties['baseurl'] + $response.id + "?api-version=2020-08-01-preview"}
451540

452541
Write-Host "Please wait while the dependency data is downloaded..."
453542

0 commit comments

Comments
 (0)