netbox-agent/netbox_agent/cli.py

38 lines
1,015 B
Python
Raw Normal View History

import netbox_agent.dmidecode as dmidecode
2019-09-03 13:16:37 +02:00
from netbox_agent.config import config
2020-02-02 20:08:56 +01:00
from netbox_agent.logging import logging # NOQA
from netbox_agent.vendors.dell import DellHost
2019-08-26 15:38:44 +02:00
from netbox_agent.vendors.hp import HPHost
2019-08-26 16:39:36 +02:00
from netbox_agent.vendors.qct import QCTHost
2019-08-26 15:38:44 +02:00
from netbox_agent.vendors.supermicro import SupermicroHost
MANUFACTURERS = {
2020-02-02 20:08:56 +01:00
'Dell Inc.': DellHost,
'HP': HPHost,
'HPE': HPHost,
'Supermicro': SupermicroHost,
'Quanta Cloud Technology Inc.': QCTHost,
}
2019-09-03 13:16:37 +02:00
def run(config):
manufacturer = dmidecode.get_by_type('Chassis')[0].get('Manufacturer')
server = MANUFACTURERS[manufacturer](dmi=dmidecode)
2019-09-03 13:16:37 +02:00
if config.debug:
server.print_debug()
2019-09-03 13:16:37 +02:00
if config.register:
server.netbox_create(config)
if config.update_all or config.update_network or config.update_location or \
2019-09-05 13:47:10 +02:00
config.update_inventory or config.update_psu:
2019-09-03 13:16:37 +02:00
server.netbox_update(config)
return True
def main():
2019-09-03 13:16:37 +02:00
return run(config)
if __name__ == '__main__':
main()