Skip to content

Preserve interface name and NetworkAddress on Windows migrations#416

Open
mihaelabalutoiu wants to merge 1 commit intocloudbase:masterfrom
mihaelabalutoiu:preserve-net-adapter-name
Open

Preserve interface name and NetworkAddress on Windows migrations#416
mihaelabalutoiu wants to merge 1 commit intocloudbase:masterfrom
mihaelabalutoiu:preserve-net-adapter-name

Conversation

@mihaelabalutoiu
Copy link
Copy Markdown
Member

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.

…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 = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be DEVICE_CLASS_BASE_PATH_FORMAT. Please rename it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please log this result output?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants