Preserve interface name and NetworkAddress on Windows migrations#416
Preserve interface name and NetworkAddress on Windows migrations#416mihaelabalutoiu wants to merge 1 commit intocloudbase:masterfrom
interface name and NetworkAddress on Windows migrations#416Conversation
…IP migration When set_dhcp is false, extract DriverDesc and NetworkAddress from the offline registry and use Rename-NetAdapter to restore the source adapter name on the destination.
| INTERFACES_PATH_FORMAT = ( | ||
| "HKLM:\\%s\\ControlSet001\\Services\\Tcpip\\Parameters\\Interfaces") | ||
|
|
||
| NET_ADAPTER_CLASS_BASE_PATH_FORMAT = ( |
There was a problem hiding this comment.
This should actually be DEVICE_CLASS_BASE_PATH_FORMAT. Please rename it.
There was a problem hiding this comment.
Also, this apperently is the wrong path.
Apologies for that, I've mistaken the Interface name with the interface description. We're looking for interface name actually, that's the thing that needs to be kept.
You will find it in:
HKLM:\SYSTEM\ControlSet001\Control\Network\{SOME_RANDOM_WINDOWS_GUID}\{NetGUID}\Connection
Key Name
There was a problem hiding this comment.
We'll look into finding the MAC address somewhere else as well, it seems like that's not the relevant location either.
| if ($nic.PSObject.Properties['interface_name'] -and $nic.interface_name) { | ||
| $conflictAdapter = Get-NetAdapter -Name $nic.interface_name -ErrorAction SilentlyContinue | ||
| if ($conflictAdapter -and $conflictAdapter.IfIndex -ne $interface.IfIndex) { | ||
| Write-Host "Cannot rename adapter '$($interface.Name)' to '$($nic.interface_name)': name already in use by another adapter" |
There was a problem hiding this comment.
This will almost always fail. We have to also delete the original NIC after we successfully gather all the information about it.
Deleting the source NIC will also help with Windows warnings like "Static IP conflict" that appears on the UI when the same static IP is set on the destination NIC.
| "$ErrorActionPreference = 'SilentlyContinue'; " | ||
| "$classBase = '%(base)s'; " | ||
| "$netClassGuid = (Get-ChildItem $classBase " | ||
| "-ErrorAction SilentlyContinue | " |
There was a problem hiding this comment.
Do we have to pass the error action twice?
| "{ \"$($p.NetCfgInstanceId)|$($p.DriverDesc)|" | ||
| "$($p.NetworkAddress)\" } }; " | ||
| "exit 0" % {'base': class_base_path}) | ||
| result = self._conn.exec_ps_command(ps_command) |
There was a problem hiding this comment.
Can you please log this result output?
When
set_dhcpis false, extractDriverDescandNetworkAddressfrom the offline registry and useRename-NetAdapterto restore the source adapter name on the destination.