handle ethtool not installed and add known limitations to README

This commit is contained in:
Solvik Blum 2019-08-04 23:24:51 +02:00
parent 15faf59182
commit 0c5ca003a6
No known key found for this signature in database
GPG key ID: CC12B3DC262B6C47
3 changed files with 10 additions and 0 deletions

View file

@ -11,6 +11,11 @@ The goal is to generate an existing infrastructure on Netbox and have the abilit
* Create physical network interfaces with IPs
* Generic ability to guess datacenters through drivers (`cmd` and `file` and custom ones)
# Known limitations
* The project is only compatible with Linux.
Since it uses `ethtool` and parses `/sys/` directory, it's not compatible with *BSD distributions.
# Configuration
```

View file

@ -1,5 +1,6 @@
import re
import subprocess
from shutil import which
# Originally from https://github.com/opencoff/useful-scripts/blob/master/linktest.py
@ -64,6 +65,8 @@ class Ethtool():
return {'form_factor': r.groups()[0]}
def parse(self):
if which('ethtool') is None:
return None
return {
**self._parse_ethtool_output(),
**self._parse_ethtool_module_output(),

View file

@ -65,6 +65,8 @@ class Network():
return self.nics
def get_netbox_type_for_nic(self, nic):
if nic.get('ethtool') is None:
return IFACE_TYPE_OTHER
if nic['ethtool']['speed'] == '10000Mb/s':
if nic['ethtool']['port'] == 'FIBRE':
return IFACE_TYPE_10GE_SFP_PLUS