automatic guess for virtual
This commit is contained in:
parent
c2406ec9eb
commit
aa2e412524
3 changed files with 15 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ from netbox_agent.vendors.generic import GenericHost
|
||||||
from netbox_agent.vendors.hp import HPHost
|
from netbox_agent.vendors.hp import HPHost
|
||||||
from netbox_agent.vendors.qct import QCTHost
|
from netbox_agent.vendors.qct import QCTHost
|
||||||
from netbox_agent.vendors.supermicro import SupermicroHost
|
from netbox_agent.vendors.supermicro import SupermicroHost
|
||||||
from netbox_agent.virtualmachine import VirtualMachine
|
from netbox_agent.virtualmachine import VirtualMachine, is_vm
|
||||||
|
|
||||||
MANUFACTURERS = {
|
MANUFACTURERS = {
|
||||||
'Dell Inc.': DellHost,
|
'Dell Inc.': DellHost,
|
||||||
|
|
@ -21,7 +21,9 @@ MANUFACTURERS = {
|
||||||
def run(config):
|
def run(config):
|
||||||
dmi = dmidecode.parse()
|
dmi = dmidecode.parse()
|
||||||
|
|
||||||
if config.virtual.enabled:
|
if config.virtual.enabled or is_vm(dmi):
|
||||||
|
if not config.virtual.cluster_name:
|
||||||
|
raise Exception('virtual.cluster_name parameter is mandatory because it\'s a VM')
|
||||||
server = VirtualMachine(dmi=dmi)
|
server = VirtualMachine(dmi=dmi)
|
||||||
else:
|
else:
|
||||||
manufacturer = dmidecode.get_by_type(dmi, 'Chassis')[0].get('Manufacturer')
|
manufacturer = dmidecode.get_by_type(dmi, 'Chassis')[0].get('Manufacturer')
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ class Network(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_netbox_type_for_nic(self, nic):
|
def get_netbox_type_for_nic(self, nic):
|
||||||
if config.virtual.enabled:
|
if self.get_network_type() == 'virtual':
|
||||||
return self.dcim_choices['interface:type']['Virtual']
|
return self.dcim_choices['interface:type']['Virtual']
|
||||||
|
|
||||||
if nic.get('bonding'):
|
if nic.get('bonding'):
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,15 @@ from netbox_agent.logging import logging # NOQA
|
||||||
from netbox_agent.misc import get_hostname
|
from netbox_agent.misc import get_hostname
|
||||||
from netbox_agent.network import VirtualNetwork
|
from netbox_agent.network import VirtualNetwork
|
||||||
|
|
||||||
|
def is_vm(dmi):
|
||||||
|
bios = dmidecode.get_by_type(dmi, 'BIOS')
|
||||||
|
system = dmidecode.get_by_type(dmi, 'System')
|
||||||
|
if 'Hyper-V' in bios[0]['Version'] or \
|
||||||
|
'Xen' in bios[0]['Version'] or \
|
||||||
|
'VirtualBox' in bios[0]['Version'] or \
|
||||||
|
'VMware' in system[0]['Manufacturer']:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class VirtualMachine(object):
|
class VirtualMachine(object):
|
||||||
def __init__(self, dmi=None):
|
def __init__(self, dmi=None):
|
||||||
|
|
@ -38,6 +47,7 @@ class VirtualMachine(object):
|
||||||
return cluster
|
return cluster
|
||||||
|
|
||||||
def netbox_create_or_update(self, config):
|
def netbox_create_or_update(self, config):
|
||||||
|
logging.debug('It\'s a virtual machine')
|
||||||
created = False
|
created = False
|
||||||
updated = 0
|
updated = 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue