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.
|
||||
#
|
||||
#device:
|
||||
# chassis_role: "Server Chassis"
|
||||
# blade_role: "Blade"
|
||||
# server_role: "Server"
|
||||
# tags: server, blade, ,just a comma,delimited,list
|
||||
# chassis_role: "Server Chassis"
|
||||
# blade_role: "Blade"
|
||||
# server_role: "Server"
|
||||
# tags: server, blade, ,just a comma,delimited,list
|
||||
|
||||
#
|
||||
# Can use this to set the tenant
|
||||
# This sets the tenant
|
||||
#
|
||||
tenant:
|
||||
driver: "file:/tmp/tenant"
|
||||
regex: "(.*)"
|
||||
driver: "file:/tmp/tenant"
|
||||
regex: "(.*)"
|
||||
|
||||
datacenter_location:
|
||||
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('--hostname_cmd', default=None,
|
||||
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')
|
||||
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')
|
||||
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')
|
||||
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')
|
||||
p.add_argument('--tenant.driver',
|
||||
help='tenant driver, ie: cmd, file')
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
import re
|
||||
from shutil import which
|
||||
from pprint import pprint
|
||||
import subprocess
|
||||
|
||||
# Originally from https://github.com/opencoff/useful-scripts/blob/master/linktest.py
|
||||
|
||||
# 'Connector':'connector',
|
||||
# 'Transceiver type': 'transciever_type',
|
||||
|
||||
module_map = {
|
||||
'Identifier' : 'identifier',
|
||||
'Identifier': 'identifier',
|
||||
'Extended identifier': 'extended_identifier',
|
||||
'Vendor name': 'vendor',
|
||||
'Vendor PN': 'partnumber',
|
||||
|
|
@ -76,7 +72,9 @@ class Ethtool():
|
|||
return fields
|
||||
|
||||
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:
|
||||
return {}
|
||||
|
|
@ -93,7 +91,7 @@ class Ethtool():
|
|||
fields[field] = output
|
||||
|
||||
return fields
|
||||
|
||||
|
||||
def _parse_ethtool_module_output(self):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
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:
|
||||
return {}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from netbox_agent.ethtool import Ethtool
|
|||
INVENTORY_TAG = {
|
||||
'cpu': {'name': 'hw:cpu', 'slug': 'hw-cpu'},
|
||||
'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'},
|
||||
'memory': {'name': 'hw:memory', 'slug': 'hw-memory'},
|
||||
'motherboard': {'name': 'hw:motherboard', 'slug': 'hw-motherboard'},
|
||||
|
|
@ -177,15 +177,19 @@ class Inventory():
|
|||
manufacturer=manufacturer.id,
|
||||
discovered=True,
|
||||
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')),
|
||||
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):
|
||||
if "Controller" in iface['product']:
|
||||
iface['product'] = iface['product'].replace(" Controller", "")
|
||||
iface['product'] = iface['product'].replace(" Controller", "")
|
||||
|
||||
print("length %d" % len(iface["product"]))
|
||||
manufacturer = self.find_or_create_manufacturer(iface["vendor"])
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class LSHW():
|
|||
if "(XXXXXX)" in self.hw_info["product"]:
|
||||
self.product = self.hw_info['product'].replace(" (XXXXXX)", "")
|
||||
else:
|
||||
self.product = self.hw_info["product"]
|
||||
self.product = self.hw_info["product"]
|
||||
self.chassis_serial = self.hw_info["serial"]
|
||||
self.motherboard_serial = self.hw_info["children"][0].get("serial", "No S/N")
|
||||
self.motherboard = self.hw_info["children"][0].get("product", "Motherboard")
|
||||
|
|
@ -89,8 +89,9 @@ class LSHW():
|
|||
|
||||
elif "nvme" in obj["configuration"]["driver"]:
|
||||
nvme = json.loads(
|
||||
subprocess.check_output(["sudo", "/usr/sbin/nvme", '-list', '-o', 'json'],
|
||||
encoding='utf8')) # noqa: E128
|
||||
subprocess.check_output(
|
||||
["sudo", "/usr/sbin/nvme", '-list', '-o', 'json'],
|
||||
encoding='utf8')) # noqa: E128
|
||||
|
||||
d = {}
|
||||
d["vendor"] = obj["vendor"]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import re
|
|||
|
||||
from netaddr import IPAddress, IPNetwork
|
||||
import netifaces
|
||||
from pprint import pprint
|
||||
|
||||
from netbox_agent.config import netbox_instance as nb, config
|
||||
from netbox_agent.ethtool import Ethtool
|
||||
|
|
@ -124,12 +123,12 @@ class Network():
|
|||
}
|
||||
|
||||
if nic["vlan"] is None:
|
||||
if nic["ovs"] != None:
|
||||
if nic["ovs"] is not None:
|
||||
ovs_info = nic.get("ovs")
|
||||
nic["vlan"] = ovs_info.get("vlan")
|
||||
|
||||
if nic["ovs"] != None:
|
||||
nic["description"] = "OVS internal interface"
|
||||
if nic["ovs"] is not None:
|
||||
nic["description"] = "OVS internal interface"
|
||||
|
||||
self.nics.append(nic)
|
||||
|
||||
|
|
@ -159,7 +158,7 @@ class Network():
|
|||
|
||||
def get_netbox_network_card(self, nic):
|
||||
if self.device is None:
|
||||
return
|
||||
return
|
||||
|
||||
if nic['mac'] is None:
|
||||
interface = nb.dcim.interfaces.get(
|
||||
|
|
@ -269,7 +268,7 @@ class Network():
|
|||
def create_or_update_ipmi(self):
|
||||
ipmi = self.get_ipmi()
|
||||
if "MAC Address" not in ipmi:
|
||||
return
|
||||
return
|
||||
mac = ipmi['MAC Address']
|
||||
ip = ipmi['IP Address']
|
||||
netmask = ipmi['Subnet Mask']
|
||||
|
|
|
|||
|
|
@ -1,19 +1,12 @@
|
|||
import subprocess
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from shutil import which
|
||||
from pprint import pprint
|
||||
|
||||
from netbox_agent.misc import is_tool
|
||||
|
||||
|
||||
class OVS():
|
||||
def __init__(self):
|
||||
|
||||
self.fields = {}
|
||||
field = ''
|
||||
|
||||
if which('ovs-vsctl') is None:
|
||||
print("could not find ovs-vsctl")
|
||||
|
|
@ -30,30 +23,29 @@ class OVS():
|
|||
r = line.split(" ")[-2:]
|
||||
|
||||
if len(r) < 2:
|
||||
self.fields["info"] = {}
|
||||
self.fields["info"]["switch_uuid"] = r[0]
|
||||
self.fields["info"] = {}
|
||||
self.fields["info"]["switch_uuid"] = r[0]
|
||||
|
||||
if "Bridge" in r[0]:
|
||||
bridge = r[1]
|
||||
bridge = r[1]
|
||||
if "Port" in r[0]:
|
||||
port = r[1]
|
||||
self.fields[port] = {}
|
||||
self.fields[port]["port"] = r[1]
|
||||
self.fields[port]["bridge"] = bridge
|
||||
port = r[1]
|
||||
self.fields[port] = {}
|
||||
self.fields[port]["port"] = r[1]
|
||||
self.fields[port]["bridge"] = bridge
|
||||
if "tag" in r[0]:
|
||||
self.fields[port]["vlan"] = r[1]
|
||||
self.fields[port]["vlan"] = r[1]
|
||||
if "Interface" in r[0]:
|
||||
self.fields[port]["interface"] = r[1]
|
||||
self.fields[port]["interface"] = r[1]
|
||||
if "type" in r[0]:
|
||||
self.fields[port]["type"] = r[1]
|
||||
self.fields[port]["type"] = r[1]
|
||||
if "options" in r[0]:
|
||||
self.fields[port]["options"] = r[1]
|
||||
self.fields[port]["options"] = r[1]
|
||||
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):
|
||||
for iface in self.fields:
|
||||
if "interface" in self.fields[iface]:
|
||||
if interface in self.fields[iface]["interface"]:
|
||||
return(self.fields[iface])
|
||||
for iface in self.fields:
|
||||
if "interface" in self.fields[iface]:
|
||||
if interface in self.fields[iface]["interface"]:
|
||||
return(self.fields[iface])
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class ServerBase():
|
|||
slug=tag
|
||||
)
|
||||
|
||||
|
||||
def get_tenant(self):
|
||||
tenant = Tenant()
|
||||
return tenant.get()
|
||||
|
|
@ -126,7 +125,7 @@ class ServerBase():
|
|||
Return the Service Tag from dmidecode info
|
||||
"""
|
||||
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()
|
||||
|
||||
def get_hostname(self):
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue