2019-08-04 00:00:22 +02:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
from netbox_agent.dell.dell import DellHost
|
|
|
|
import netbox_agent.dmidecode as dmidecode
|
|
|
|
from netbox_agent.hp.hp import HPHost
|
2019-08-07 15:37:14 +02:00
|
|
|
from netbox_agent.logging import logging # NOQA
|
2019-08-04 00:00:22 +02:00
|
|
|
|
|
|
|
MANUFACTURERS = {
|
|
|
|
'Dell Inc.': DellHost,
|
|
|
|
'HP': HPHost,
|
|
|
|
'HPE': HPHost,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def run(args):
|
|
|
|
manufacturer = dmidecode.get_by_type('Chassis')[0].get('Manufacturer')
|
|
|
|
server = MANUFACTURERS[manufacturer](dmidecode)
|
|
|
|
if args.debug:
|
|
|
|
server.print_debug()
|
|
|
|
if args.register:
|
|
|
|
server.netbox_create()
|
2019-08-05 16:03:35 +02:00
|
|
|
if args.update:
|
|
|
|
server.netbox_update()
|
2019-08-04 00:00:22 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description='Netbox agent command line')
|
2019-08-05 16:03:35 +02:00
|
|
|
parser.add_argument('-r', '--register', action='store_true',
|
2019-08-04 00:00:22 +02:00
|
|
|
help='Register server in Netbox')
|
2019-08-05 16:03:35 +02:00
|
|
|
parser.add_argument('-u', '--update', action='store_true',
|
|
|
|
help='Update server in Netbox')
|
|
|
|
parser.add_argument('-d', '--debug', action='store_true',
|
2019-08-04 00:00:22 +02:00
|
|
|
help='Print debug informations')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
return run(args)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|