netbox-agent/netbox_agent/cli.py

46 lines
1.3 KiB
Python
Raw Normal View History

import argparse
2019-08-26 15:38:44 +02:00
from netbox_agent.vendors.dell import DellHost
import netbox_agent.dmidecode as dmidecode
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
2019-08-07 15:37:14 +02:00
from netbox_agent.logging import logging # NOQA
MANUFACTURERS = {
'Dell Inc.': DellHost,
'HP': HPHost,
'HPE': HPHost,
2019-08-26 15:38:44 +02:00
'Supermicro': SupermicroHost,
2019-08-26 16:39:36 +02:00
'Quanta Cloud Technology Inc.': QCTHost,
}
def run(args):
manufacturer = dmidecode.get_by_type('Chassis')[0].get('Manufacturer')
server = MANUFACTURERS[manufacturer](dmi=dmidecode)
if args.debug:
server.print_debug()
if args.register:
server.netbox_create()
if args.update:
server.netbox_update()
return True
def main():
parser = argparse.ArgumentParser(description='Netbox agent command line')
parser.add_argument('-r', '--register', action='store_true',
help='Register server in Netbox')
parser.add_argument('-u', '--update', action='store_true',
help='Update server in Netbox')
parser.add_argument('-d', '--debug', action='store_true',
help='Print debug informations')
args = parser.parse_args()
return run(args)
if __name__ == '__main__':
main()