Our standard configuration has the following:
- Trunk interface (highest numbered port)
- Access interface (lowest numbered port)
- Management IP on SVI
- Identity
- Named Uplink and Downlink ports
- Data VLAN
- Management VLAN
- All unused ports are disabled
We need to add these variables to our device so they can be used to generate a configuration later. The next section requires some setup to be defined in Netbox’s device type template.
- Interfaces must be names like they are in Mikrotik default names
- ether1, ether2, etc
- Mikrotik must have an interface defined for the SVI.
...
INET_VLAN_ID_ID = VLAN.objects.get(vid=900)
MGMT_VLAN_ID_ID = VLAN.objects.get(vid=107)
...
interfaces = Interface.objects.filter(device_id=device.id)
enabled_interfaces = []
mgmt_intf = interfaces.get(name="b107")
enabled_interfaces.append(mgmt_intf)
uplk_intf = interfaces.get(name="ether10")
enabled_interfaces.append(uplk_intf)
uplk_intf.mode = "tagged"
uplk_intf.tagged_vlans.set(
[
self.INET_VLAN,
self.MGMT_VLAN
]
)
uplk_intf.description = "Uplink"
uplk_intf.save()
inet_intf = interfaces.get(name="ether1")
enabled_interfaces.append(inet_intf)
inet_intf.description = "Internet"
inet_intf.mode = "access"
inet_intf.untagged_vlan=self.INET_VLAN
inet_intf.save()
mgmt_intf.save()
for intf in interfaces:
intf.enabled = False
intf.save()
for intf in enabled_interfaces:
intf.enabled = True
intf.mtu = 1500
intf.save()
available_ip = Prefix.objects.get(vlan=self.MGMT_VLAN).get_first_available_ip()
ip = IPAddress(address=available_ip, interface_id=mgmt_intf.id, family='4')
ip.save()
device.primary_ip4_id=ip.id
device.primary_ip_id=ip.id
device.save()
Similar to phase 1, we get a new device, but now our device has our standard configuration on it and an available IP has been selected from a pool of IP addresses.
And the device specific parameters have been created