Skip to content

Commit ccdbaa6

Browse files
authored
fixes null value in targets(when interf. has no ip) (#12)
1 parent ef15897 commit ccdbaa6

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

netbox_atlas_plugin/api/serializers.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,26 @@ def get_targets(vm, target):
9797
if getattr(vm, "primary_ip4", None) is not None:
9898
return [str(IPNetwork(vm.primary_ip4.address).ip)]
9999
elif target == "mgmt_only":
100-
interfaces = []
100+
targets = []
101101
if hasattr(vm, "interfaces") and vm.interfaces is not None:
102102
result = vm.interfaces.filter(mgmt_only=True)
103-
interfaces = map(get_address, result)
104-
return interfaces
103+
targets = get_interface_addresses(result)
104+
return targets
105105
elif target == "loopback10":
106-
interfaces = []
106+
targets = []
107107
if hasattr(vm, "interfaces") and vm.interfaces is not None:
108108
result = vm.interfaces.filter(name='Loopback10')
109-
interfaces = map(get_address, result)
110-
return interfaces
109+
targets = get_interface_addresses(result)
110+
return targets
111111
else:
112112
if hasattr(vm, "primary_ip") and vm.primary_ip is not None:
113113
return [str(IPNetwork(vm.primary_ip.address).ip)]
114114

115115

116-
def get_address(interface):
116+
def get_interface_addresses(interfaces):
117+
interfaces = [i for i in map(map_ip_address, interfaces) if i is not None]
118+
return interfaces
119+
120+
def map_ip_address(interface):
117121
if len(interface.ip_addresses.all()) > 0:
118122
return str(IPNetwork(interface.ip_addresses.first().address).ip)

0 commit comments

Comments
 (0)