Several minor fixes #47

Merged
ThomasADavis merged 8 commits from fixes-1 into master 2019-08-29 17:33:28 +02:00
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))
Solvik commented 2019-08-28 18:03:00 +02:00 (Migrated from github.com)
Review

ip6_addr isn't defined, we cant +=

`ip6_addr` isn't defined, we cant `+=`
Solvik commented 2019-08-28 18:04:36 +02:00 (Migrated from github.com)
Review

I've tried to reproduce this case during my testing, but it was unsuccessful. It's good you caught this!
We should do the same thing for addr and remove %.* no ?

I've tried to reproduce this case during my testing, but it was unsuccessful. It's good you caught this! We should do the same thing for `addr` and remove `%.*` no ?
Solvik commented 2019-08-28 18:05:42 +02:00 (Migrated from github.com)
Review

ok you've just fixed that :)

ok you've just fixed that :)
ThomasADavis commented 2019-08-28 18:37:19 +02:00 (Migrated from github.com)
Review

yup. once you fix the netmask and ipv6 address, it goes right in.

yup. once you fix the netmask and ipv6 address, it goes right in.
Solvik commented 2019-08-29 10:39:43 +02:00 (Migrated from github.com)
Review

There's still the following error:

File "/tmp/netbox_agent/netbox_agent/network.py", line 80, in scan
    for addr in ip6_addr:
TypeError: 'NoneType' object is not iterable

Just add this and it'll be good to go!

            ip6_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET6, [])
There's still the following error: ``` File "/tmp/netbox_agent/netbox_agent/network.py", line 80, in scan for addr in ip6_addr: TypeError: 'NoneType' object is not iterable ``` Just add this and it'll be good to go! ```suggestion ip6_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET6, []) ```
ThomasADavis commented 2019-08-29 17:19:45 +02:00 (Migrated from github.com)
Review

pushed up a fix.

pushed up a fix.
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, [])
Solvik commented 2019-08-27 21:56:23 +02:00 (Migrated from github.com)
Review

or we could go:

            ip_addr += netifaces.ifaddresses(interface).get(netifaces.AF_INET6, [])
or we could go: ```suggestion ip_addr += netifaces.ifaddresses(interface).get(netifaces.AF_INET6, []) ```
ThomasADavis commented 2019-08-27 23:05:29 +02:00 (Migrated from github.com)
Review
  File "/usr/local/bin/netbox_agent", line 11, in <module>
    load_entry_point('netbox-agent==0.1', 'console_scripts', 'netbox_agent')()
  File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 41, in main
    return run(args)
  File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 27, in run
    server.netbox_update()
  File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/server.py", line 275, in netbox_update
    self.network = Network(server=self)
  File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 49, in __init__
    self.scan()
  File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 63, in scan
    ip_addr += netifaces.ifaddresses(interface).get(netifaces.AF_INET6, [])
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'list'
[root@d8-r13-c5-n1 ~]# 
eno1.50: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.84.97  netmask 255.255.252.0  broadcast 192.168.87.255
        inet6 fe80::ec4:7aff:fe59:ec4a  prefixlen 64  scopeid 0x20<link>
        ether 0c:c4:7a:59:ec:4a  txqueuelen 1000  (Ethernet)
        RX packets 41180169  bytes 2674792656 (2.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10087607  bytes 5226819088 (4.8 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```Traceback (most recent call last): File "/usr/local/bin/netbox_agent", line 11, in <module> load_entry_point('netbox-agent==0.1', 'console_scripts', 'netbox_agent')() File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 41, in main return run(args) File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 27, in run server.netbox_update() File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/server.py", line 275, in netbox_update self.network = Network(server=self) File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 49, in __init__ self.scan() File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 63, in scan ip_addr += netifaces.ifaddresses(interface).get(netifaces.AF_INET6, []) TypeError: unsupported operand type(s) for +=: 'NoneType' and 'list' [root@d8-r13-c5-n1 ~]# eno1.50: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.84.97 netmask 255.255.252.0 broadcast 192.168.87.255 inet6 fe80::ec4:7aff:fe59:ec4a prefixlen 64 scopeid 0x20<link> ether 0c:c4:7a:59:ec:4a txqueuelen 1000 (Ethernet) RX packets 41180169 bytes 2674792656 (2.4 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10087607 bytes 5226819088 (4.8 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ```
ThomasADavis commented 2019-08-27 23:14:40 +02:00 (Migrated from github.com)
Review

Oh, wait, I found the problem.. both need the [] ; but that causes another problem.

{17: [{'addr': '0c:c4:7a:59:ec:4a', 'broadcast': 'ff:ff:ff:ff:ff:ff'}], 10: [{'addr': 'fe80::ec4:7aff:fe59:ec4a%eno1', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]}
ip_addr= []
Traceback (most recent call last):
File "/usr/local/bin/netbox_agent", line 11, in
load_entry_point('netbox-agent==0.1', 'console_scripts', 'netbox_agent')()
File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 41, in main
return run(args)
File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 27, in run
server.netbox_update()
File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/server.py", line 275, in netbox_update
self.network = Network(server=self)
File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 49, in init
self.scan()
File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 90, in scan
] if ip_addr else None, # FIXME: handle IPv6 addresses
File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 89, in
) for x in ip_addr
File "/usr/local/lib/python3.6/site-packages/netaddr-0.7.19-py3.6.egg/netaddr/ip/init.py", line 280, in init
% self.class.name)
ValueError: IPAddress() does not support netmasks or subnet prefixes! See documentation for details.

Oh, wait, I found the problem.. both need the [] ; but that causes another problem. {17: [{'addr': '0c:c4:7a:59:ec:4a', 'broadcast': 'ff:ff:ff:ff:ff:ff'}], 10: [{'addr': 'fe80::ec4:7aff:fe59:ec4a%eno1', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]} ip_addr= [] Traceback (most recent call last): File "/usr/local/bin/netbox_agent", line 11, in <module> load_entry_point('netbox-agent==0.1', 'console_scripts', 'netbox_agent')() File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 41, in main return run(args) File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/cli.py", line 27, in run server.netbox_update() File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/server.py", line 275, in netbox_update self.network = Network(server=self) File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 49, in __init__ self.scan() File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 90, in scan ] if ip_addr else None, # FIXME: handle IPv6 addresses File "/usr/local/lib/python3.6/site-packages/netbox_agent-0.1-py3.6.egg/netbox_agent/network.py", line 89, in <listcomp> ) for x in ip_addr File "/usr/local/lib/python3.6/site-packages/netaddr-0.7.19-py3.6.egg/netaddr/ip/__init__.py", line 280, in __init__ % self.__class__.__name__) ValueError: IPAddress() does not support netmasks or subnet prefixes! See documentation for details.
Solvik commented 2019-08-28 12:05:52 +02:00 (Migrated from github.com)
Review
ip_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET, [])
ip_addr += netifaces.ifaddresses(interface).get(netifaces.AF_INET6, [])

works like a charm on a VM without any IPs, not your case?

``` ip_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET, []) ip_addr += netifaces.ifaddresses(interface).get(netifaces.AF_INET6, []) ``` works like a charm on a VM without any IPs, not your case?
# 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

@ -2,8 +2,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):
# No supermicro on hands