Verified Commit 43655745 authored by Adrian Schollmeyer's avatar Adrian Schollmeyer
Browse files

get-aruba-ap-uplinks: Use common modules


Signed-off-by: Adrian Schollmeyer's avatarAdrian 'nex' Schollmeyer <adrian.schollmeyer@fem.tu-ilmenau.de>
parent 79c31962
#!/usr/bin/env python3
# Use Slugs!
AP_ROLE="wlan-ap"
AP_MANUFACTURER="aruba"
......@@ -4,18 +4,15 @@ import pynetbox
import argparse
import sys
import configparser
from fem_netbox import cli_common, fem_constants
DEFAULT_CONFIG_PATH="/etc/fem-netbox-user-scripts.conf"
# Use Slugs!
AP_ROLE="wlan-ap"
AP_MANUFACTURER="aruba"
DEFAULT_CONFIG_PATH=cli_common.DEFAULT_CONFIG_PATH
def main():
arg_parser = create_argument_parser()
args = arg_parser.parse_args()
config = parse_config_file(args.config)
netbox = create_netbox_instance(
config = cli_common.get_config(args.config)
netbox = cli_common.create_netbox_instance(
config.get("auth", "url"),
config.get("auth", "token")
)
......@@ -41,8 +38,7 @@ def main():
def create_argument_parser():
parser = argparse.ArgumentParser(description="Tool to fetch uplink"
"switchports of Aruba APs from netbox")
parser.add_argument("--config", "-c", type=str,
default=DEFAULT_CONFIG_PATH, help="Path to configuration file")
cli_common.add_parser_default_args(parser)
parser.add_argument("--block", "-b", type=str,
help="Fetch only uplinks in the specified house")
parser.add_argument("--switch", "-s", type=str,
......@@ -50,24 +46,10 @@ def create_argument_parser():
return parser
def parse_config_file(config_file_path):
try:
config = configparser.RawConfigParser()
config.read(config_file_path)
return config
except Exception as e:
raise Exception(f"Failed to read configuration file {config_file_path}!")
def create_netbox_instance(url, token):
netbox = pynetbox.api(url, token=token)
return netbox
def get_matching_aps(netbox, block=None):
devices = netbox.dcim.devices.filter(
role=AP_ROLE,
manufacturer=AP_MANUFACTURER,
role=fem_constants.AP_ROLE,
manufacturer=fem_constants.AP_MANUFACTURER,
site=block
)
return devices
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment