Page MenuHomePhabricator

Move device attributes
Closed, ResolvedPublic

Description

It would be useful to have a script (Netbox custom script?) to move all the attributes from one host to the other.
I think at least:

  • Interfaces/ports
  • IPs
  • Cables

There have been a few use case where a new device is supposed to replace an old one and take over its duties.
For example replacing an SCS requires to delete all the cables, to then re-create them on the new device.
Some other devices, like PDUs, keep the same hostname and IP when replaced with newer models, which could lead to oversight.
Interface could be as simple as 2 text fields for the old/new device, and 3 check-boxes for interfaces/IPs/Cables. Then maybe more if the needs arise.

Event Timeline

ayounsi triaged this task as Medium priority.

This sounds completely doable, and not to big of a deal.

A hacky quick migration has been done in T267865#6624814, see there for the code executed.

Change 780845 had a related patch set uploaded (by Ayounsi; author: Ayounsi):

[operations/software/netbox-extras@master] Add script to move devices attributes

https://gerrit.wikimedia.org/r/780845

Change 780845 merged by jenkins-bot:

[operations/software/netbox-extras@master] Add script to move devices attributes

https://gerrit.wikimedia.org/r/780845

The script has been used successfully for mr1-eqsin and mr1-ulsfo.

Change 784683 had a related patch set uploaded (by Ayounsi; author: Ayounsi):

[operations/software/homer/deploy@master] wmf-netbox: remove the need for fetch_device_circuits

https://gerrit.wikimedia.org/r/784683

This revealed a limitation in Netbox. After investigation the short version is that Netbox caches the device connected to a cable for easier access. And this cache doesn't get updated when the interface moves devices:

>>> c = Cable.objects.get(id=680)
>>> c.termination_b.device
<Device: mr1-eqsin>
>>> c._termination_b_device
<Device: mr1-eqsin-old>

One workaround is https://gerrit.wikimedia.org/r/c/operations/software/homer/deploy/+/784683 which makes the code simpler as we don't need the complexity of "fetch_device_circuits".

But it doesn't solve the underlying issue (invalid data).

Change 784694 had a related patch set uploaded (by Ayounsi; author: Ayounsi):

[operations/software/netbox-extras@master] Fix for cable termination not being updated

https://gerrit.wikimedia.org/r/784694

I fixed the prod ones with in nbshell:

source_device = Device.objects.get(name="mr1-ulsfo-old")
destination_device = Device.objects.get(name="mr1-ulsfo")

ca = Cable.objects.filter(_termination_a_device=source_device)
cb = Cable.objects.filter(_termination_b_device=source_device)
for c in ca:
    c._termination_a_device = destination_device
    c._termination_a_device_id = destination_device.id
    c.save()

for c in cb:
    c._termination_b_device = destination_device
    c._termination_b_device_id = destination_device.id
    c.save()

Change 784694 merged by jenkins-bot:

[operations/software/netbox-extras@master] Fix for cable termination not being updated

https://gerrit.wikimedia.org/r/784694

Change 784683 merged by Ayounsi:

[operations/software/homer/deploy@master] wmf-netbox: remove the need for fetch_device_circuits

https://gerrit.wikimedia.org/r/784683

Change 785272 had a related patch set uploaded (by Ayounsi; author: Ayounsi):

[operations/software/netbox-extras@master] replace_device: actually save the cable modification

https://gerrit.wikimedia.org/r/785272

Change 785272 merged by jenkins-bot:

[operations/software/netbox-extras@master] replace_device: actually save the cable modification

https://gerrit.wikimedia.org/r/785272