Merge pull request #266 from Varriount/patch-2
Simplify `is_vm` function
This commit is contained in:
commit
7259c7602d
1 changed files with 19 additions and 12 deletions
|
@ -10,19 +10,26 @@ from netbox_agent.network import VirtualNetwork
|
||||||
|
|
||||||
|
|
||||||
def is_vm(dmi):
|
def is_vm(dmi):
|
||||||
bios = dmidecode.get_by_type(dmi, 'BIOS')
|
bios = dmidecode.get_by_type(dmi, 'BIOS')[0]
|
||||||
system = dmidecode.get_by_type(dmi, 'System')
|
system = dmidecode.get_by_type(dmi, 'System')[0]
|
||||||
|
|
||||||
if 'Hyper-V' in bios[0]['Version'] or \
|
return (
|
||||||
'Xen' in bios[0]['Version'] or \
|
(
|
||||||
'Google Compute Engine' in system[0]['Product Name'] or \
|
'Hyper-V' in bios['Version'] or
|
||||||
('Amazon EC2' in system[0]['Manufacturer'] and not system[0]['Product Name'].endswith('.metal')) or \
|
'Xen' in bios['Version'] or
|
||||||
'RHEV Hypervisor' in system[0]['Product Name'] or \
|
'Google Compute Engine' in system['Product Name']
|
||||||
'QEMU' in system[0]['Manufacturer'] or \
|
) or
|
||||||
'VirtualBox' in bios[0]['Version'] or \
|
(
|
||||||
'VMware' in system[0]['Manufacturer']:
|
(
|
||||||
return True
|
'Amazon EC2' in system['Manufacturer'] and
|
||||||
return False
|
not system['Product Name'].endswith('.metal')
|
||||||
|
) or
|
||||||
|
'RHEV Hypervisor' in system['Product Name'] or
|
||||||
|
'QEMU' in system['Manufacturer'] or
|
||||||
|
'VirtualBox' in bios['Version'] or
|
||||||
|
'VMware' in system['Manufacturer']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class VirtualMachine(object):
|
class VirtualMachine(object):
|
||||||
|
|
Loading…
Add table
Reference in a new issue