Update IP Initializer for Netbox 2.7

The ip address database model has changed in Netbox 2.7.
Therefore the initializer code, that was used before, broke.
As a user, you will need to update your ip_addresses.yml
file as follows:

- Make sure the status is written in lower case.

See the diff of this commit for further information how this is meant.
This commit is contained in:
Christian Mäder 2020-01-17 16:18:52 +01:00
parent 74a0e2cf6e
commit 27f671e41a
2 changed files with 24 additions and 13 deletions

View File

@ -1,26 +1,44 @@
## Possible Choices:
## status:
## - active
## - reserved
## - deprecated
## - dhcp
## role:
## - loopback
## - secondary
## - anycast
## - vip
## - vrrp
## - hsrp
## - glbp
## - carp
##
## Examples:
# - address: 10.1.1.1/24
# device: server01
# interface: to-server02
# status: Active
# status: active
# vrf: vrf1
# - address: 2001:db8:a000:1::1/64
# device: server01
# interface: to-server02
# status: Active
# status: active
# vrf: vrf1
# - address: 10.1.1.2/24
# device: server02
# interface: to-server01
# status: Active
# status: active
# - address: 2001:db8:a000:1::2/64
# device: server02
# interface: to-server01
# status: Active
# status: active
# - address: 10.1.1.10/24
# description: reserved IP
# status: Reserved
# status: reserved
# tenant: tenant1
# - address: 2001:db8:a000:1::10/64
# description: reserved IP
# status: Reserved
# status: reserved
# tenant: tenant1

View File

@ -1,5 +1,4 @@
from ipam.models import IPAddress, VRF
from ipam.constants import IPADDRESS_STATUS_CHOICES
from dcim.models import Device, Interface
from virtualization.models import VirtualMachine
from tenancy.models import Tenant
@ -49,12 +48,6 @@ with file.open('r') as stream:
query = { field: params.pop(assoc) }
params[assoc] = model.objects.get(**query)
if 'status' in params:
for ip_status in IPADDRESS_STATUS_CHOICES:
if params['status'] in ip_status:
params['status'] = ip_status[0]
break
ip_address, created = IPAddress.objects.get_or_create(**params)
if created: