Page MenuHomePhabricator

Netbox: remove template images
Closed, ResolvedPublic

Description

The DC-Ops team as asked to remove all template images from Netbox that provides the front/rear images of devices of certain type, because it reduces the usability of the website, in particular for the https://netbox.wikimedia.org/dcim/rack-elevations/ page that they use quite often.

Unfortunately Netbox UI doesn't allow for an easy deletion of front/rear images, this is a feature request tracked at:
https://github.com/netbox-community/netbox/issues/5595

I will delete them from the Netbox internal APIs, as I've tested the procedure on netbox-next.

Event Timeline

Volans triaged this task as High priority.Mar 10 2021, 1:57 PM
Volans created this task.

This is what I got so far:

>>> null_image = DeviceType.objects.get(model='PowerEdge R430').front_image  # R430 doesn't have any image
>>> null_image
<ImageFieldFile: None>
>>> null_image.name
''
>>> devices = []
>>> for device in DeviceType.objects.all():
...     if device.front_image.name or device.rear_image.name:
...         print(device.front_image.name)
...         print(device.rear_image.name)
...         devices.append(device)
...
devicetype-images/r440_front.png
devicetype-images/r440_back.png
devicetype-images/R640_front.png
devicetype-images/R640_back.png
devicetype-images/ex4300-48p-front-high.jpg

devicetype-images/ex4600-front-high.jpg
devicetype-images/ex4600-rear-high.jpg
devicetype-images/mx204-front-high.jpg
devicetype-images/mx204-rear-high.jpg
devicetype-images/mx480-front-high.jpg
devicetype-images/mx480-rear-high.jpg
devicetype-images/qfx5100-48s-front-high.jpg
devicetype-images/qfx5100-48s-rear2-high.jpg
devicetype-images/srx300-front-high.jpg
devicetype-images/srx300-rear-high.jpg
devicetype-images/NG_front.jpeg
devicetype-images/NG_back.jpeg
devicetype-images/mini_GS348_21Mar17_front.png

devicetype-images/CM7100_Front041620_FM6zasc.jpg
devicetype-images/CM7116-2-DAC_Back.jpg
devicetype-images/CM7100_Front041620.jpg
devicetype-images/CM7148-2-DAC_Back.jpg
>>> len(devices)
12
>>> devices
[<DeviceType: PowerEdge R440>, <DeviceType: PowerEdge R640>, <DeviceType: EX4300-48T>, <DeviceType: EX4600-40F>, <DeviceType: MX204>, <DeviceType: MX480>, <DeviceType: QFX5100-48S-6Q>, <DeviceType: SRX300>, <DeviceType: FS750T2>, <DeviceType: GS348>, <DeviceType: CM7116-2-DAC>, <DeviceType: CM7148-2-DAC>]

@ayounsi if you agree with this list I'll proceed on setting the null image to all those devices at once.

Ok, all done!

>>> import os
>>> os.environ['CURL_CA_BUNDLE'] = ''
>>> for device in devices:
...     device.front_image = null_image
...     device.rear_image = null_image
...     device.save()
...
>>> for device in DeviceType.objects.all():
...     if device.front_image.name or device.rear_image.name:
...         print(device.rear_image.name)
...         print(device.front_image.name)
>>>  # No device matched

The CURL_CA_BUNDLE is needed to avoid the requests.exceptions.SSLError: HTTPSConnectionPool(host='swift.svc.eqiad.wmnet', port=443) with [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate.

All images are gone now.
@Papaul I'm resolving it, please re-open it if there is still something left.