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'm somewhat experienced with VBA and such, so i just jumped right in and tried to do some "coding" by copy, paste, try and error... This is in many cases a great way to learn for me.
Unfortunaly it doesn't work as good as I hoped so I was trying to find some "basic info" and will try to learn.
My need for the first Script was to inherit Tenants.
Most of our Clients (Schools) have a own Site, but there are some small Schools who use Sites together. For easier Filtering etc. it would be great if the Tenant is named in the device. To make it easier for me to collect all data i would like to inherit the Tenants from parents so i can just add all the infrastructure and let the Script run afterwards.
The building of the form worked well so far. There was just the question if there are some more information about the availiable choices, models etc.?! I was using some but don't have a real clue why.
class TestInherition(Script):
class Meta:
name = "Inherition of Tenants"
description = "Inherit the Tenants of an parent Site/Rack"
field_order = ['site', 'rack', 'device']
commit_default = False
site = ObjectVar(
model=Site,
required=False,
query_params={
'tenant__n' : 'null'
}
)
rack = MultiObjectVar(
model=Rack,
required=False,
query_params={
'site_id' : '$site[id]',
'tenant' : 'null'
}
)
device = MultiObjectVar(
model=Device,
required=False,
query_params={
'rack_id' : '$rack[id]',
'tenant' : 'null'
}
)
def run(self, data, commit):
self.log_success(f"Site: {data['site']}")
This brings me up the option to select a site with tenant and a rack and a device without a tenant inside it. This works very fine. The Log is just for testing purpose.
Now we come to the part where I need some more knowledge - just trying to describe what I would like to do:
I would like to have the form to select something special. When nothing is selected it should work with all data. This seem to be some kind of standard, as if i don't select a site i can select all the racks and devices in the form.
I would like to select all the devices according to the criteria above and inherit semi automatic the tenant.
I see two approaches:
Get all the racks, look if the parent has a tenant; when tenant is null it should be ignored, when there is a tenant it should be copied. After the loop (All Racks / filtered by site when specified) it should continue to all devices without a tenant and inherit from parent Rack (when with tenant).
This was my first idea.
The second one was: Select Tenants, look what they own and go "down" to inherit it to device. Open for both options...
Bonus: Make a selection or probably a second script where I can overwrite Data, i.e. if there is a change in Tenantship. But i think that i can figure this out by myself when understood the main task ;-)
It would be great if someone can give me a hint where to find training resources or probably a code snippet to analyse or a helping hand.
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
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I'm just new to the netbox-django-python thing.
I'm somewhat experienced with VBA and such, so i just jumped right in and tried to do some "coding" by copy, paste, try and error... This is in many cases a great way to learn for me.
Unfortunaly it doesn't work as good as I hoped so I was trying to find some "basic info" and will try to learn.
My need for the first Script was to inherit Tenants.
Most of our Clients (Schools) have a own Site, but there are some small Schools who use Sites together. For easier Filtering etc. it would be great if the Tenant is named in the device. To make it easier for me to collect all data i would like to inherit the Tenants from parents so i can just add all the infrastructure and let the Script run afterwards.
The building of the form worked well so far. There was just the question if there are some more information about the availiable choices, models etc.?! I was using some but don't have a real clue why.
This brings me up the option to select a site with tenant and a rack and a device without a tenant inside it. This works very fine. The Log is just for testing purpose.
Now we come to the part where I need some more knowledge - just trying to describe what I would like to do:
I would like to have the form to select something special. When nothing is selected it should work with all data. This seem to be some kind of standard, as if i don't select a site i can select all the racks and devices in the form.
I would like to select all the devices according to the criteria above and inherit semi automatic the tenant.
I see two approaches:
Get all the racks, look if the parent has a tenant; when tenant is null it should be ignored, when there is a tenant it should be copied. After the loop (All Racks / filtered by site when specified) it should continue to all devices without a tenant and inherit from parent Rack (when with tenant).
This was my first idea.
The second one was: Select Tenants, look what they own and go "down" to inherit it to device. Open for both options...
Bonus: Make a selection or probably a second script where I can overwrite Data, i.e. if there is a change in Tenantship. But i think that i can figure this out by myself when understood the main task ;-)
It would be great if someone can give me a hint where to find training resources or probably a code snippet to analyse or a helping hand.
Kind Regards, really looking forward
Christian
Beta Was this translation helpful? Give feedback.
All reactions