not failing if platform is not set

This commit is contained in:
Fredrik Bergström 2022-03-31 11:14:26 +02:00
parent a7b965a8b5
commit 2a4f24f00a
3 changed files with 9 additions and 5 deletions

View file

@ -30,6 +30,9 @@ def get_device_type(type):
def get_device_platform(config):
if config.device.platform is None:
return None
device_platform = nb.dcim.platforms.get(
name=config.device.platform
)

View file

@ -465,10 +465,11 @@ class ServerBase():
ret, server = self.update_netbox_location(server)
update += ret
if get_device_platform(config) is not None:
if server.platform != get_device_platform(config).name:
if config.device.platform is not None:
platform = get_device_platform(config)
if server.platform != platform.name:
update += 1
server.platform = get_device_platform(config).id
server.platform = platform.id
if update:
server.save()

View file

@ -95,8 +95,8 @@ class VirtualMachine(object):
vm = nb.virtualization.virtual_machines.create(
name=hostname,
cluster=cluster.id,
platform=device_platform.id,
device_platform = get_device_platform(config),
platform=device_platform.id if device_platform is not None else None,
device_platform=device_platform,
vcpus=vcpus,
memory=memory,
tenant=tenant.id if tenant else None,