TOX fixes
This commit is contained in:
parent
79a5f5e06d
commit
5fd9c7358b
8 changed files with 54 additions and 58 deletions
14
README.md
14
README.md
|
|
@ -58,17 +58,17 @@ network:
|
||||||
# You can use these to change the roles.
|
# You can use these to change the roles.
|
||||||
#
|
#
|
||||||
#device:
|
#device:
|
||||||
# chassis_role: "Server Chassis"
|
# chassis_role: "Server Chassis"
|
||||||
# blade_role: "Blade"
|
# blade_role: "Blade"
|
||||||
# server_role: "Server"
|
# server_role: "Server"
|
||||||
# tags: server, blade, ,just a comma,delimited,list
|
# tags: server, blade, ,just a comma,delimited,list
|
||||||
|
|
||||||
#
|
#
|
||||||
# Can use this to set the tenant
|
# This sets the tenant
|
||||||
#
|
#
|
||||||
tenant:
|
tenant:
|
||||||
driver: "file:/tmp/tenant"
|
driver: "file:/tmp/tenant"
|
||||||
regex: "(.*)"
|
regex: "(.*)"
|
||||||
|
|
||||||
datacenter_location:
|
datacenter_location:
|
||||||
driver: "cmd:cat /etc/qualification | tr [a-z] [A-Z]"
|
driver: "cmd:cat /etc/qualification | tr [a-z] [A-Z]"
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,13 @@ def get_config():
|
||||||
p.add_argument('--netbox.token', help='Netbox API Token')
|
p.add_argument('--netbox.token', help='Netbox API Token')
|
||||||
p.add_argument('--hostname_cmd', default=None,
|
p.add_argument('--hostname_cmd', default=None,
|
||||||
help="Command to output hostname, used as Device's name in netbox")
|
help="Command to output hostname, used as Device's name in netbox")
|
||||||
p.add_argument('--device.tags', default=r'',
|
p.add_argument('--device.tags', default=r'',
|
||||||
help='tags to use for a device')
|
help='tags to use for a device')
|
||||||
p.add_argument('--device.blade_role', default=r'Blade',
|
p.add_argument('--device.blade_role', default=r'Blade',
|
||||||
help='device_role to use for blade servers')
|
help='device_role to use for blade servers')
|
||||||
p.add_argument('--device.chassis_role', default=r'Server Chassis',
|
p.add_argument('--device.chassis_role', default=r'Server Chassis',
|
||||||
help='device_role to use for a chassis')
|
help='device_role to use for a chassis')
|
||||||
p.add_argument('--device.server_role', default=r'Server',
|
p.add_argument('--device.server_role', default=r'Server',
|
||||||
help='device_role to use for a server')
|
help='device_role to use for a server')
|
||||||
p.add_argument('--tenant.driver',
|
p.add_argument('--tenant.driver',
|
||||||
help='tenant driver, ie: cmd, file')
|
help='tenant driver, ie: cmd, file')
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
import re
|
import re
|
||||||
from shutil import which
|
from shutil import which
|
||||||
from pprint import pprint
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# Originally from https://github.com/opencoff/useful-scripts/blob/master/linktest.py
|
# Originally from https://github.com/opencoff/useful-scripts/blob/master/linktest.py
|
||||||
|
|
||||||
# 'Connector':'connector',
|
|
||||||
# 'Transceiver type': 'transciever_type',
|
|
||||||
|
|
||||||
module_map = {
|
module_map = {
|
||||||
'Identifier' : 'identifier',
|
'Identifier': 'identifier',
|
||||||
'Extended identifier': 'extended_identifier',
|
'Extended identifier': 'extended_identifier',
|
||||||
'Vendor name': 'vendor',
|
'Vendor name': 'vendor',
|
||||||
'Vendor PN': 'partnumber',
|
'Vendor PN': 'partnumber',
|
||||||
|
|
@ -76,7 +72,9 @@ class Ethtool():
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
def _parse_ethtool_info_output(self):
|
def _parse_ethtool_info_output(self):
|
||||||
status, output = subprocess.getstatusoutput('sudo /usr/sbin/ethtool -i {}'.format(self.interface))
|
status, output = subprocess.getstatusoutput(
|
||||||
|
'sudo /usr/sbin/ethtool -i {}'.format(self.interface)
|
||||||
|
)
|
||||||
|
|
||||||
if status != 0:
|
if status != 0:
|
||||||
return {}
|
return {}
|
||||||
|
|
@ -93,7 +91,7 @@ class Ethtool():
|
||||||
fields[field] = output
|
fields[field] = output
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
def _parse_ethtool_module_output(self):
|
def _parse_ethtool_module_output(self):
|
||||||
"""
|
"""
|
||||||
ethtool output is a mess.. good for human reading, bad for parsing.
|
ethtool output is a mess.. good for human reading, bad for parsing.
|
||||||
|
|
@ -101,7 +99,10 @@ class Ethtool():
|
||||||
ie, connector and type, plus dropping un needed information.
|
ie, connector and type, plus dropping un needed information.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
status, output = subprocess.getstatusoutput('sudo /usr/sbin/ethtool -m {}'.format(self.interface))
|
status, output = subprocess.getstatusoutput(
|
||||||
|
'sudo /usr/sbin/ethtool -m {}'.format(self.interface)
|
||||||
|
)
|
||||||
|
|
||||||
if status != 0:
|
if status != 0:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ from netbox_agent.ethtool import Ethtool
|
||||||
INVENTORY_TAG = {
|
INVENTORY_TAG = {
|
||||||
'cpu': {'name': 'hw:cpu', 'slug': 'hw-cpu'},
|
'cpu': {'name': 'hw:cpu', 'slug': 'hw-cpu'},
|
||||||
'disk': {'name': 'hw:disk', 'slug': 'hw-disk'},
|
'disk': {'name': 'hw:disk', 'slug': 'hw-disk'},
|
||||||
'gbic': {'name': 'hw:gbic', 'slug': 'hw-gbic' },
|
'gbic': {'name': 'hw:gbic', 'slug': 'hw-gbic'},
|
||||||
'interface': {'name': 'hw:interface', 'slug': 'hw-interface'},
|
'interface': {'name': 'hw:interface', 'slug': 'hw-interface'},
|
||||||
'memory': {'name': 'hw:memory', 'slug': 'hw-memory'},
|
'memory': {'name': 'hw:memory', 'slug': 'hw-memory'},
|
||||||
'motherboard': {'name': 'hw:motherboard', 'slug': 'hw-motherboard'},
|
'motherboard': {'name': 'hw:motherboard', 'slug': 'hw-motherboard'},
|
||||||
|
|
@ -177,15 +177,19 @@ class Inventory():
|
||||||
manufacturer=manufacturer.id,
|
manufacturer=manufacturer.id,
|
||||||
discovered=True,
|
discovered=True,
|
||||||
tags=[INVENTORY_TAG['gbic']['name']],
|
tags=[INVENTORY_TAG['gbic']['name']],
|
||||||
name="{}/GBIC in interface {}".format(info.get('identifier'),iface.get('name')),
|
name="{}/GBIC in interface {}".format(info.get('identifier'), iface.get('name')),
|
||||||
part_id="{}".format(info.get('partnumber')),
|
part_id="{}".format(info.get('partnumber')),
|
||||||
serial='{}'.format(info.get('serialnumber')),
|
serial='{}'.format(info.get('serialnumber')),
|
||||||
description='{}/{} connector GBIC/{}'.format(info.get('transciever_type'), info.get('connector'), info.get('identifier'))
|
description='{}/{} connector GBIC/{}'.format(
|
||||||
|
info.get('transciever_type'),
|
||||||
|
info.get('connector'),
|
||||||
|
info.get('identifier')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_netbox_interface(self, iface):
|
def create_netbox_interface(self, iface):
|
||||||
if "Controller" in iface['product']:
|
if "Controller" in iface['product']:
|
||||||
iface['product'] = iface['product'].replace(" Controller", "")
|
iface['product'] = iface['product'].replace(" Controller", "")
|
||||||
|
|
||||||
print("length %d" % len(iface["product"]))
|
print("length %d" % len(iface["product"]))
|
||||||
manufacturer = self.find_or_create_manufacturer(iface["vendor"])
|
manufacturer = self.find_or_create_manufacturer(iface["vendor"])
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class LSHW():
|
||||||
if "(XXXXXX)" in self.hw_info["product"]:
|
if "(XXXXXX)" in self.hw_info["product"]:
|
||||||
self.product = self.hw_info['product'].replace(" (XXXXXX)", "")
|
self.product = self.hw_info['product'].replace(" (XXXXXX)", "")
|
||||||
else:
|
else:
|
||||||
self.product = self.hw_info["product"]
|
self.product = self.hw_info["product"]
|
||||||
self.chassis_serial = self.hw_info["serial"]
|
self.chassis_serial = self.hw_info["serial"]
|
||||||
self.motherboard_serial = self.hw_info["children"][0].get("serial", "No S/N")
|
self.motherboard_serial = self.hw_info["children"][0].get("serial", "No S/N")
|
||||||
self.motherboard = self.hw_info["children"][0].get("product", "Motherboard")
|
self.motherboard = self.hw_info["children"][0].get("product", "Motherboard")
|
||||||
|
|
@ -89,8 +89,9 @@ class LSHW():
|
||||||
|
|
||||||
elif "nvme" in obj["configuration"]["driver"]:
|
elif "nvme" in obj["configuration"]["driver"]:
|
||||||
nvme = json.loads(
|
nvme = json.loads(
|
||||||
subprocess.check_output(["sudo", "/usr/sbin/nvme", '-list', '-o', 'json'],
|
subprocess.check_output(
|
||||||
encoding='utf8')) # noqa: E128
|
["sudo", "/usr/sbin/nvme", '-list', '-o', 'json'],
|
||||||
|
encoding='utf8')) # noqa: E128
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
d["vendor"] = obj["vendor"]
|
d["vendor"] = obj["vendor"]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import re
|
||||||
|
|
||||||
from netaddr import IPAddress, IPNetwork
|
from netaddr import IPAddress, IPNetwork
|
||||||
import netifaces
|
import netifaces
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from netbox_agent.config import netbox_instance as nb, config
|
from netbox_agent.config import netbox_instance as nb, config
|
||||||
from netbox_agent.ethtool import Ethtool
|
from netbox_agent.ethtool import Ethtool
|
||||||
|
|
@ -124,12 +123,12 @@ class Network():
|
||||||
}
|
}
|
||||||
|
|
||||||
if nic["vlan"] is None:
|
if nic["vlan"] is None:
|
||||||
if nic["ovs"] != None:
|
if nic["ovs"] is not None:
|
||||||
ovs_info = nic.get("ovs")
|
ovs_info = nic.get("ovs")
|
||||||
nic["vlan"] = ovs_info.get("vlan")
|
nic["vlan"] = ovs_info.get("vlan")
|
||||||
|
|
||||||
if nic["ovs"] != None:
|
if nic["ovs"] is not None:
|
||||||
nic["description"] = "OVS internal interface"
|
nic["description"] = "OVS internal interface"
|
||||||
|
|
||||||
self.nics.append(nic)
|
self.nics.append(nic)
|
||||||
|
|
||||||
|
|
@ -159,7 +158,7 @@ class Network():
|
||||||
|
|
||||||
def get_netbox_network_card(self, nic):
|
def get_netbox_network_card(self, nic):
|
||||||
if self.device is None:
|
if self.device is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if nic['mac'] is None:
|
if nic['mac'] is None:
|
||||||
interface = nb.dcim.interfaces.get(
|
interface = nb.dcim.interfaces.get(
|
||||||
|
|
@ -269,7 +268,7 @@ class Network():
|
||||||
def create_or_update_ipmi(self):
|
def create_or_update_ipmi(self):
|
||||||
ipmi = self.get_ipmi()
|
ipmi = self.get_ipmi()
|
||||||
if "MAC Address" not in ipmi:
|
if "MAC Address" not in ipmi:
|
||||||
return
|
return
|
||||||
mac = ipmi['MAC Address']
|
mac = ipmi['MAC Address']
|
||||||
ip = ipmi['IP Address']
|
ip = ipmi['IP Address']
|
||||||
netmask = ipmi['Subnet Mask']
|
netmask = ipmi['Subnet Mask']
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,12 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from shutil import which
|
from shutil import which
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from netbox_agent.misc import is_tool
|
|
||||||
|
|
||||||
|
|
||||||
class OVS():
|
class OVS():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.fields = {}
|
self.fields = {}
|
||||||
field = ''
|
|
||||||
|
|
||||||
if which('ovs-vsctl') is None:
|
if which('ovs-vsctl') is None:
|
||||||
print("could not find ovs-vsctl")
|
print("could not find ovs-vsctl")
|
||||||
|
|
@ -30,30 +23,29 @@ class OVS():
|
||||||
r = line.split(" ")[-2:]
|
r = line.split(" ")[-2:]
|
||||||
|
|
||||||
if len(r) < 2:
|
if len(r) < 2:
|
||||||
self.fields["info"] = {}
|
self.fields["info"] = {}
|
||||||
self.fields["info"]["switch_uuid"] = r[0]
|
self.fields["info"]["switch_uuid"] = r[0]
|
||||||
|
|
||||||
if "Bridge" in r[0]:
|
if "Bridge" in r[0]:
|
||||||
bridge = r[1]
|
bridge = r[1]
|
||||||
if "Port" in r[0]:
|
if "Port" in r[0]:
|
||||||
port = r[1]
|
port = r[1]
|
||||||
self.fields[port] = {}
|
self.fields[port] = {}
|
||||||
self.fields[port]["port"] = r[1]
|
self.fields[port]["port"] = r[1]
|
||||||
self.fields[port]["bridge"] = bridge
|
self.fields[port]["bridge"] = bridge
|
||||||
if "tag" in r[0]:
|
if "tag" in r[0]:
|
||||||
self.fields[port]["vlan"] = r[1]
|
self.fields[port]["vlan"] = r[1]
|
||||||
if "Interface" in r[0]:
|
if "Interface" in r[0]:
|
||||||
self.fields[port]["interface"] = r[1]
|
self.fields[port]["interface"] = r[1]
|
||||||
if "type" in r[0]:
|
if "type" in r[0]:
|
||||||
self.fields[port]["type"] = r[1]
|
self.fields[port]["type"] = r[1]
|
||||||
if "options" in r[0]:
|
if "options" in r[0]:
|
||||||
self.fields[port]["options"] = r[1]
|
self.fields[port]["options"] = r[1]
|
||||||
if "ovs_version" in r[0]:
|
if "ovs_version" in r[0]:
|
||||||
self.fields["info"]["ovs_version"] = r[1]
|
self.fields["info"]["ovs_version"] = r[1]
|
||||||
|
|
||||||
|
|
||||||
def get_info(self, interface):
|
def get_info(self, interface):
|
||||||
for iface in self.fields:
|
for iface in self.fields:
|
||||||
if "interface" in self.fields[iface]:
|
if "interface" in self.fields[iface]:
|
||||||
if interface in self.fields[iface]["interface"]:
|
if interface in self.fields[iface]["interface"]:
|
||||||
return(self.fields[iface])
|
return(self.fields[iface])
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@ class ServerBase():
|
||||||
slug=tag
|
slug=tag
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_tenant(self):
|
def get_tenant(self):
|
||||||
tenant = Tenant()
|
tenant = Tenant()
|
||||||
return tenant.get()
|
return tenant.get()
|
||||||
|
|
@ -126,7 +125,7 @@ class ServerBase():
|
||||||
Return the Service Tag from dmidecode info
|
Return the Service Tag from dmidecode info
|
||||||
"""
|
"""
|
||||||
if "Default string" in self.system[0]['Serial Number']:
|
if "Default string" in self.system[0]['Serial Number']:
|
||||||
self.system[0]['Serial Number'] = "000000"
|
self.system[0]['Serial Number'] = "000000"
|
||||||
return self.system[0]['Serial Number'].strip()
|
return self.system[0]['Serial Number'].strip()
|
||||||
|
|
||||||
def get_hostname(self):
|
def get_hostname(self):
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue