f06da32fc3
Add ability to create Virtual Machine in netbox with an auto-detecting feature (currently VirtualBox, Xen, Hyper-V, VMWare, GCP) One caveat, I made the choice not to report the disk as Netbox model allow only one size but VM often have multiples. Also, lot of code refactoring to be able to use create_or_update function style, fixing a lot of corner case
39 lines
919 B
Python
39 lines
919 B
Python
import socket
|
|
import subprocess
|
|
from shutil import which
|
|
|
|
|
|
def is_tool(name):
|
|
'''Check whether `name` is on PATH and marked as executable.'''
|
|
return which(name) is not None
|
|
|
|
|
|
def get_vendor(name):
|
|
vendors = {
|
|
'PERC': 'Dell',
|
|
'SANDISK': 'SanDisk',
|
|
'DELL': 'Dell',
|
|
'ST': 'Seagate',
|
|
'CRUCIAL': 'Crucial',
|
|
'MICRON': 'Micron',
|
|
'INTEL': 'Intel',
|
|
'SAMSUNG': 'Samsung',
|
|
'EH0': 'HP',
|
|
'HGST': 'HGST',
|
|
'HUH': 'HGST',
|
|
'MB': 'Toshiba',
|
|
'MC': 'Toshiba',
|
|
'MD': 'Toshiba',
|
|
'MG': 'Toshiba',
|
|
'WD': 'WDC'
|
|
}
|
|
for key, value in vendors.items():
|
|
if name.upper().startswith(key):
|
|
return value
|
|
return name
|
|
|
|
|
|
def get_hostname(config):
|
|
if config.hostname_cmd is None:
|
|
return '{}'.format(socket.gethostname())
|
|
return subprocess.getoutput(config.hostname_cmd)
|