handle the case where nb_mgmt_ip is None gracefully and prevent the AttributeError from occurring.
This commit is contained in:
parent
a07b56bddc
commit
0ae67f44e6
1 changed files with 5 additions and 4 deletions
|
@ -540,10 +540,8 @@ class ServerNetwork(Network):
|
||||||
nb_mgmt_ip = nb.ipam.ip_addresses.get(
|
nb_mgmt_ip = nb.ipam.ip_addresses.get(
|
||||||
address=switch_ip,
|
address=switch_ip,
|
||||||
)
|
)
|
||||||
if not nb_mgmt_ip:
|
# Add the check here
|
||||||
logging.error('Switch IP {} cannot be found in Netbox'.format(switch_ip))
|
if nb_mgmt_ip is not None:
|
||||||
return nb_server_interface
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nb_switch = nb_mgmt_ip.assigned_object.device
|
nb_switch = nb_mgmt_ip.assigned_object.device
|
||||||
logging.info('Found a switch in Netbox based on LLDP infos: {} (id: {})'.format(
|
logging.info('Found a switch in Netbox based on LLDP infos: {} (id: {})'.format(
|
||||||
|
@ -557,6 +555,9 @@ class ServerNetwork(Network):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return nb_server_interface
|
return nb_server_interface
|
||||||
|
else:
|
||||||
|
logging.error('No NetBox IP found for switch IP {}'.format(switch_ip))
|
||||||
|
return nb_server_interface
|
||||||
|
|
||||||
switch_interface = self.lldp.get_switch_port(nb_server_interface.name)
|
switch_interface = self.lldp.get_switch_port(nb_server_interface.name)
|
||||||
nb_switch_interface = nb.dcim.interfaces.get(
|
nb_switch_interface = nb.dcim.interfaces.get(
|
||||||
|
|
Loading…
Reference in a new issue