Update VM Initializer for Netbox 2.7

The vm 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 virtual_machines.yml
file as follows:

- Make sure the status is spelled lowercase.

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:03:45 +01:00
parent 8d8b9a157e
commit f3403cd0f5
4 changed files with 22 additions and 19 deletions

View File

@ -1,13 +1,22 @@
## Possible Choices:
## status:
## - container
## - active
## - reserved
## - deprecated
##
## Examples:
# - description: prefix1
# prefix: 10.1.1.0/24
# site: AMS 1
# status: Active
# status: active
# tenant: tenant1
# vlan: vlan1
# - description: prefix2
# prefix: 10.1.2.0/24
# site: AMS 2
# status: Active
# status: active
# tenant: tenant2
# vlan: vlan2
# is_pool: true
@ -15,6 +24,6 @@
# - description: ipv6 prefix1
# prefix: 2001:db8:a000:1::/64
# site: AMS 2
# status: Active
# status: active
# tenant: tenant2
# vlan: vlan2

View File

@ -1,10 +1,18 @@
## Possible Choices:
## status:
## - active
## - offline
## - staged
##
## Examples:
# - cluster: cluster1
# comments: VM1
# disk: 200
# memory: 4096
# name: virtual machine 1
# platform: Platform 2
# status: Active
# status: active
# tenant: tenant1
# vcpus: 8
# - cluster: cluster1
@ -13,6 +21,6 @@
# memory: 2048
# name: virtual machine 2
# platform: Platform 2
# status: Active
# status: active
# tenant: tenant1
# vcpus: 8

View File

@ -1,6 +1,5 @@
from dcim.models import Site
from ipam.models import Prefix, VLAN, Role, VRF
from ipam.constants import PREFIX_STATUS_CHOICES
from tenancy.models import Tenant, TenantGroup
from extras.models import CustomField, CustomFieldValue
from ruamel.yaml import YAML
@ -38,12 +37,6 @@ with file.open('r') as stream:
params[assoc] = model.objects.get(**query)
if 'status' in params:
for prefix_status in PREFIX_STATUS_CHOICES:
if params['status'] in prefix_status:
params['status'] = prefix_status[0]
break
prefix, created = Prefix.objects.get_or_create(**params)
if created:

View File

@ -1,6 +1,5 @@
from dcim.models import Site, Platform, DeviceRole
from virtualization.models import Cluster, VirtualMachine
from virtualization.constants import VM_STATUS_CHOICES
from tenancy.models import Tenant
from extras.models import CustomField, CustomFieldValue
from ruamel.yaml import YAML
@ -43,12 +42,6 @@ with file.open('r') as stream:
params[assoc] = model.objects.get(**query)
if 'status' in params:
for vm_status in VM_STATUS_CHOICES:
if params['status'] in vm_status:
params['status'] = vm_status[0]
break
virtual_machine, created = VirtualMachine.objects.get_or_create(**params)
if created: