Script linking Interface and IPAddress #8986
-
Using scripting I'm having some trouble figuring out how to link an Interface to an IPAddress. I'm creating an Interface new_int = Interface(
device=device,
name=f'Loopback{interface_id}',
description=description,
type=InterfaceTypeChoices.TYPE_VIRTUAL,
enabled=True
)
new_int.save() I'm creating an IPAddress new_ip = IPAddress(
address=str(core_router_ip) + "/30",
vrf=vrf,
tenant=tenant,
role=IPAddressRoleChoices.ROLE_LOOPBACK,
status=IPAddressStatusChoices.STATUS_ACTIVE,
description=description,
)
new_ip.save() I've tried adding 'interface=new_int,' into the arguments to create IPAddress I've tried: new_ip.interface.add(new_nbn_int)
new_ip.interface.only(new_nbn_int) It'll be something I'll kick myself over I'm sure, and I need to do some Django training. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
When you're not sure how to interact with an object, first reference the model's source code: More of than not it will have all the clues you need. You can find the source for the IPAddress model in You can see that there's no
Hope that helps! *IIRC there was an |
Beta Was this translation helpful? Give feedback.
When you're not sure how to interact with an object, first reference the model's source code: More of than not it will have all the clues you need. You can find the source for the IPAddress model in
ipam/models/ip.py
.You can see that there's no
interface
field on the IPAddress model.* Instead, we see a generic foreign key namedassigned_object
. This field can be set to assign an IP address to a device interface, a VM interface, or an FHRP group.Hope that helps!
*IIRC there was an
interface
field on the IPAddress model some time ago, but it was replaced with a generic foreign key when we split device and VM interfaces into separate models (…