lint
This commit is contained in:
parent
b738f4bfef
commit
86527af1c0
6 changed files with 23 additions and 13 deletions
|
@ -1,5 +1,8 @@
|
|||
from packaging import version
|
||||
|
||||
import netbox_agent.dmidecode as dmidecode
|
||||
from netbox_agent.config import config, netbox_instance as nb
|
||||
from netbox_agent.config import config
|
||||
from netbox_agent.config import netbox_instance as nb
|
||||
from netbox_agent.logging import logging # NOQA
|
||||
from netbox_agent.vendors.dell import DellHost
|
||||
from netbox_agent.vendors.generic import GenericHost
|
||||
|
@ -8,8 +11,6 @@ from netbox_agent.vendors.qct import QCTHost
|
|||
from netbox_agent.vendors.supermicro import SupermicroHost
|
||||
from netbox_agent.virtualmachine import VirtualMachine, is_vm
|
||||
|
||||
from packaging import version
|
||||
|
||||
MANUFACTURERS = {
|
||||
'Dell Inc.': DellHost,
|
||||
'HP': HPHost,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import subprocess
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from netbox_agent.misc import is_tool
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import subprocess
|
|||
from shutil import which
|
||||
|
||||
from slugify import slugify
|
||||
|
||||
from netbox_agent.config import netbox_instance as nb
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ from netbox_agent.ethtool import Ethtool
|
|||
from netbox_agent.ipmi import IPMI
|
||||
from netbox_agent.lldp import LLDP
|
||||
|
||||
|
||||
class Network(object):
|
||||
def __init__(self, server, *args, **kwargs):
|
||||
self.nics = []
|
||||
|
@ -83,7 +84,6 @@ class Network(object):
|
|||
addr["netmask"] = addr["netmask"].split('/')[0]
|
||||
ip_addr.append(addr)
|
||||
|
||||
|
||||
mac = open('/sys/class/net/{}/address'.format(interface), 'r').read().strip()
|
||||
vlan = None
|
||||
if len(interface.split('.')) > 1:
|
||||
|
@ -227,12 +227,13 @@ class Network(object):
|
|||
interface.tagged_vlans = []
|
||||
interface.untagged_vlan = None
|
||||
# if the local interface is configured with a vlan, it's supposed to be taggued
|
||||
# if mode is either not set or not correctly configured or vlan are not correctly configured
|
||||
# we reset the vlan
|
||||
# if mode is either not set or not correctly configured or vlan are not
|
||||
# correctly configured, we reset the vlan
|
||||
elif vlan_id and (
|
||||
interface.mode is None or
|
||||
type(interface.mode) is not int and (
|
||||
hasattr(interface.mode, 'value') and interface.mode.value == self.dcim_choices['interface:mode']['Access'] or
|
||||
hasattr(interface.mode, 'value') and
|
||||
interface.mode.value == self.dcim_choices['interface:mode']['Access'] or
|
||||
len(interface.tagged_vlans) != 1 or
|
||||
int(interface.tagged_vlans[0].vid) != int(vlan_id))):
|
||||
logging.info('Resetting tagged VLAN(s) on interface {interface}'.format(
|
||||
|
@ -369,8 +370,11 @@ class Network(object):
|
|||
hasattr(netbox_ip, 'assigned_object') and netbox_ip.assigned_object is None:
|
||||
logging.info('Assigning existing IP {ip} to {interface}'.format(
|
||||
ip=ip, interface=interface))
|
||||
elif hasattr(netbox_ip, 'interface') and netbox_ip.interface.id != interface.id or \
|
||||
hasattr(netbox_ip, 'assigned_object') and netbox_ip.assigned_object_id != interface.id:
|
||||
elif hasattr(netbox_ip, 'interface') and \
|
||||
netbox_ip.interface.id != interface.id or \
|
||||
hasattr(netbox_ip, 'assigned_object') and \
|
||||
netbox_ip.assigned_object_id != interface.id:
|
||||
|
||||
old_interface = netbox_ip.assigned_object
|
||||
logging.info(
|
||||
'Detected interface change for ip {ip}: old interface is '
|
||||
|
@ -493,7 +497,6 @@ class ServerNetwork(Network):
|
|||
self.intf_type = "interface_id"
|
||||
self.assigned_object_type = "dcim.interface"
|
||||
|
||||
|
||||
def get_network_type(self):
|
||||
return 'server'
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ from netbox_agent.misc import create_netbox_tags, get_device_role, get_device_ty
|
|||
from netbox_agent.network import ServerNetwork
|
||||
from netbox_agent.power import PowerSupply
|
||||
|
||||
|
||||
class ServerBase():
|
||||
def __init__(self, dmi=None):
|
||||
if dmi:
|
||||
|
@ -27,7 +28,9 @@ class ServerBase():
|
|||
|
||||
self.network = None
|
||||
|
||||
self.tags = list(set([x.strip() for x in config.device.tags.split(',') if x.strip()])) if config.device.tags else []
|
||||
self.tags = list(set([
|
||||
x.strip() for x in config.device.tags.split(',') if x.strip()
|
||||
])) if config.device.tags else []
|
||||
self.nb_tags = list(create_netbox_tags(self.tags))
|
||||
|
||||
def get_tenant(self):
|
||||
|
|
3
netbox_agent/vendors/hp.py
vendored
3
netbox_agent/vendors/hp.py
vendored
|
@ -12,7 +12,8 @@ class HPHost(ServerBase):
|
|||
|
||||
def is_blade(self):
|
||||
blade = self.product.startswith("ProLiant BL")
|
||||
blade |= self.product.startswith("ProLiant m") and self.product.endswith("Server Cartridge")
|
||||
blade |= self.product.startswith("ProLiant m") and \
|
||||
self.product.endswith("Server Cartridge")
|
||||
return blade
|
||||
|
||||
def _find_rack_locator(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue