You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just had to do this and figured I would provide everyone else a snippet for nbshell to do this as well.
If you use sites for anything other then sites, and you need to convert to the new locations, the script down below is going to be what you want.
First, what will this do?
Create a Site with a rooms parent region name
Create a Location with a rooms name
Copy over the description from that room (site) to the location
Move over only devices, racks, rack groups
What will this not do?
Not copy over custom fields (but you can edit it)
Not copy over any description from the parent regions to the new Site
Not copy over any contact, address or location information from the Site to the Location
Not move over power panels (do this manually first or modify to handle this)
Not modify Virtualization clusters (do this manually first or modify to handle this)
Not modify circuits (could be altered to handle this)
Not modify vlans (could be altered to handle this)
Not modify prefixes (could be altered to handle this)
What do you need to do?
Tag all your "room" sites as "Room"
Run the script
If you don't remove the exception at the end, remove the exception and run again if everything is clean
Cleanup the regions
sites = Site.objects.filter(tags__name="Room")
with transaction.atomic():
for room in sites:
name = f'Room: {room.name}'
slug = f'room-{room.slug}'
print(f'Creating: {name}|{room.slug}')
if room.region is not None:
try:
region = Site.objects.get(name=room.region.name)
except Site.DoesNotExist:
if room.region.parent is not None:
parent = room.region.parent
else:
parent = None
region = Site(name=room.name, slug=room.slug, region=parent)
new_site.save()
location = Location(name=name, site=region, slug=slug, description=room.description)
location.full_clean()
location.save()
print(f'\tCreated: {name}')
print(f'Processing: {name}')
for rackgroup in room.locations.all():
print(f'\tMoving {rackgroup.name} to Site {location.site.name} and Location {location.name}')
rackgroup.site = location.site
rackgroup.location = location
rackgroup.full_clean()
rackgroup.save()
print(f'\t\tMoved {rackgroup.name} to Site {location.site.name} and Location {location.name}')
for rack in room.racks.all():
print(f'\tMoving {rack.name} to Site {location.site.name} and Location {location.name}')
rack.site = location.site
if rack.location is None:
rack.location = location
rack.full_clean()
rack.save()
print(f'\t\tMoved {rack.name} to Site {location.site.name} and Location {location.name}')
for device in room.devices.all():
print(f'\tMoving {device.name} to Site {location.site.name} and Location {location.name}')
device.site = location.site
device.location = location
if device.rack is None:
device.face = ""
device.position = None
device.full_clean()
device.save()
print(f'\t\tMoved {device.name} to Site {location.site.name} and Location {location.name}')
room.delete()
raise Exception("Rolling Back")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Howdy all,
I just had to do this and figured I would provide everyone else a snippet for nbshell to do this as well.
If you use sites for anything other then sites, and you need to convert to the new locations, the script down below is going to be what you want.
First, what will this do?
What will this not do?
What do you need to do?
Beta Was this translation helpful? Give feedback.
All reactions