2019-08-04 01:11:53 +02:00
|
|
|
import pynetbox
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
with open('/etc/netbox_agent.yaml', 'r') as ymlfile:
|
|
|
|
# FIXME: validate configuration file
|
|
|
|
config = yaml.load(ymlfile)
|
|
|
|
|
|
|
|
netbox_instance = pynetbox.api(
|
|
|
|
url=config['netbox']['url'],
|
|
|
|
token=config['netbox']['token']
|
|
|
|
)
|
|
|
|
|
2019-08-07 10:32:23 +02:00
|
|
|
LOG_LEVEL = config.get('log_level', 'debug')
|
|
|
|
|
2019-08-05 11:54:06 +02:00
|
|
|
DATACENTER_LOCATION_DRIVER_FILE = None
|
|
|
|
DATACENTER_LOCATION = None
|
|
|
|
DATACENTER_LOCATION_REGEX = None
|
|
|
|
RACK_LOCATION_DRIVER_FILE = None
|
|
|
|
RACK_LOCATION = None
|
|
|
|
RACK_LOCATION_REGEX = None
|
2019-08-29 16:13:04 +02:00
|
|
|
SLOT_LOCATION_DRIVER_FILE = None
|
|
|
|
SLOT_LOCATION = None
|
|
|
|
SLOT_LOCATION_REGEX = None
|
2019-08-04 01:11:53 +02:00
|
|
|
|
2019-08-05 11:54:06 +02:00
|
|
|
if config.get('datacenter_location'):
|
|
|
|
dc_loc = config.get('datacenter_location')
|
|
|
|
DATACENTER_LOCATION_DRIVER_FILE = dc_loc.get('driver_file')
|
|
|
|
DATACENTER_LOCATION = dc_loc.get('driver')
|
|
|
|
DATACENTER_LOCATION_REGEX = dc_loc.get('regex')
|
|
|
|
|
|
|
|
if config.get('rack_location'):
|
|
|
|
rack_location = config['rack_location']
|
|
|
|
RACK_LOCATION_DRIVER_FILE = rack_location.get('driver_file')
|
|
|
|
RACK_LOCATION = rack_location.get('driver')
|
|
|
|
RACK_LOCATION_REGEX = rack_location.get('regex')
|
2019-08-09 12:08:11 +02:00
|
|
|
|
2019-08-29 16:13:04 +02:00
|
|
|
if config.get('slot_location'):
|
|
|
|
slot_location = config['slot_location']
|
|
|
|
SLOT_LOCATION_DRIVER_FILE = slot_location.get('driver_file')
|
|
|
|
SLOT_LOCATION = slot_location.get('driver')
|
|
|
|
SLOT_LOCATION_REGEX = slot_location.get('regex')
|
|
|
|
|
|
|
|
|
2019-08-09 12:08:11 +02:00
|
|
|
NETWORK_IGNORE_INTERFACES = None
|
|
|
|
NETWORK_IGNORE_IPS = None
|
2019-08-26 11:05:41 +02:00
|
|
|
NETWORK_LLDP = None
|
2019-08-09 12:08:11 +02:00
|
|
|
if config.get('network'):
|
2019-08-09 13:26:51 +02:00
|
|
|
NETWORK_IGNORE_INTERFACES = config['network'].get('ignore_interfaces')
|
|
|
|
NETWORK_IGNORE_IPS = config['network'].get('ignore_ips')
|
2019-08-26 11:05:41 +02:00
|
|
|
NETWORK_LLDP = config['network'].get('lldp') is True
|
2019-08-26 16:54:48 +02:00
|
|
|
|
|
|
|
INVENTORY_ENABLED = config.get('inventory') is True
|