Several minor fixes (#47)

Several minor fixes:
- raid_array check should return an empty array, not NoneType
- not all systems will have IPv6 defined, handle this case
- Vendor Supermicro was incomplete.
This commit is contained in:
ThomasADavis 2019-08-29 08:33:27 -07:00 committed by Solvik
parent 0faee59bde
commit 6ec08e8669
3 changed files with 31 additions and 4 deletions

View file

@ -102,7 +102,7 @@ class Inventory():
self.raid = HPRaid()
if not self.raid:
return
return []
controllers = self.raid.get_controllers()
if len(self.raid.get_controllers()):

View file

@ -59,8 +59,29 @@ class Network():
logging.debug('Ignore interface {interface}'.format(interface=interface))
continue
ip_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET)
ip_addr += netifaces.ifaddresses(interface).get(netifaces.AF_INET6)
ip_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET, [])
ip6_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET6, [])
# netifaces returns a ipv6 netmask that netaddr does not understand.
# this strips the netmask down to the correct format for netaddr,
# and remove the interface.
# ie, this:
# {
# 'addr': 'fe80::ec4:7aff:fe59:ec4a%eno1.50',
# 'netmask': 'ffff:ffff:ffff:ffff::/64'
# }
#
# becomes:
# {
# 'addr': 'fe80::ec4:7aff:fe59:ec4a',
# 'netmask': 'ffff:ffff:ffff:ffff::'
# }
#
for addr in ip6_addr:
addr["addr"] = addr["addr"].replace('%{}'.format(interface), '')
addr["netmask"] = addr["netmask"].split('/')[0]
ip_addr.append(addr)
if NETWORK_IGNORE_IPS and ip_addr:
for i, ip in enumerate(ip_addr):
if re.match(NETWORK_IGNORE_IPS, ip['addr']):

View file

@ -3,8 +3,14 @@ from netbox_agent.server import ServerBase
class SupermicroHost(ServerBase):
def __init__(self, *args, **kwargs):
super(SupermicroHost, self).__init__(*args, **kwargs)
self.manufacturer = 'Supermicro'
def is_blade(self):
return self.get_product_name().startswith('SBI')
blade = self.get_product_name().startswith('SBI')
blade |= self.get_product_name().startswith('SYS')
return blade
def get_blade_slot(self):
if self.is_blade():