Custom Script "Rebuild Device From Device Type" #22914
Replies: 2 comments
|
class RebuildDeviceFromType(Script): |
|
I would not expect a native bulk-operation shortcut for this, because rebuilding from a device type is not just a field update: it can delete and recreate related objects, and that can affect interfaces, cables, IP assignments, inventory items, etc. I would keep it as a Custom Script / Job, but change the input from one
For a class RebuildDevicesFromType(Script):
device_type = ObjectVar(model=DeviceType)
site = ObjectVar(model=Site, required=False)
batch_size = IntegerVar(default=25, min_value=1, max_value=200)
def run(self, data, commit):
qs = Device.objects.filter(device_type=data["device_type"])
if data.get("site"):
qs = qs.filter(site=data["site"])
for device in qs.iterator(chunk_size=data["batch_size"]):
self.log_info(f"Would rebuild {device.name}")
if commit:
rebuild_one_device(device)The important parts I would add before running it broadly:
So yes: refactoring the script to accept a |
Uh oh!
There was an error while loading. Please reload this page.
Hi team,I am currently using a NetBox Custom Script named "Rebuild Device From Device Type" (similar to the standard Rebuild_device_from_type pattern) to push template updates down to deployed device instances.Right now, the script works perfectly, but I have to manually run it one-by-one for every single device.What is the preferred method or community best practice to scale this behavior so I can execute it all at once?Should I refactor the Custom Script to accept a DeviceType model variable and use a Python loop (Device.objects.filter) to update them all in a single execution task, or is there a native NetBox bulk-operation trick I am missing? I'd love to hear how others handle mass-syncing templates without hitting timeouts. Thanks!
All reactions