-
Hey all, currently writing a script that will automatically generate OpenBSD interface configs for devices. I've got a script that allows you to select a device and then an interface to generate for. However once the script is ran, I am not sure how to grab all IPs associated to the selected device_id for use within the config. Here's my current WIP code: class InterfaceDataScript(Script):
class Meta:
name = "Interface Data"
description = "Test"
commit_default = False
device = ObjectVar(
Device
)
interface = ObjectVar(
Interface,
query_params={
'device_id': '$device'
}
)
def run(self, data, commit):
device = data['device']
ipaddress = IPAddress.objects.filter(assigned_object_id=device.id)
interface = data['interface']
label = interface.label
file = f"/etc/hostname.{label}"
enabled = ""
if interface.enabled:
enabled = "up"
return f"""DEBUG:
{vars(interface)}
{vars(device)}
{vars(ipaddress)}
# {label}
{enabled}
""" I will add in logic to detect whether IP addresses are even assigned to the device later, but for now I just want all IP related data for the device saved into the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I guess another way of phrasing it is 'How to I get the same data as hitting the API endpoint |
Beta Was this translation helpful? Give feedback.
Answering my own question:
You don't even need the id:
Unfortunately, you can't do the following: