Skip to content
Snippets Groups Projects
Verified Commit 6d84566c authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

add missing trailing commas

parent d8f4b6fc
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !126. Comments created here will be created in the context of that merge request.
""" """The LibreNMS module interacts with the LibreNMS instance when
The LibreNMS module interacts with the LibreNMS instance when
- Creating a device. - Creating a device.
- Validating the input of a device. - Validating the input of a device.
- Terminating a device. - Terminating a device.
""" """
import json import json
import logging import logging
import requests import requests
from gso import settings
from gso import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class CfgStruct(object): class CfgStruct:
pass pass
def _get_cfg(): def _get_cfg():
""" """Internal function to retrieve all needed configuration."""
Internal function to retrieve all needed configuration.
"""
oss = settings.load_oss_params() oss = settings.load_oss_params()
cfg = CfgStruct() cfg = CfgStruct()
# Hack for later ease: 1st setattr will fill in the inner's dict # Hack for later ease: 1st setattr will fill in the inner's dict
setattr(cfg, "_hack", "") cfg._hack = ""
# Update inner dict # Update inner dict
cfg.__dict__.update(oss.MONITORING) cfg.__dict__.update(oss.MONITORING)
assert cfg.__dict__ is not None assert cfg.__dict__ is not None
...@@ -51,8 +49,7 @@ def _get_cfg(): ...@@ -51,8 +49,7 @@ def _get_cfg():
def validate_device(fqdn: str): def validate_device(fqdn: str):
""" """Function that validates the existence of a device in LibreNMS.
Function that validates the existence of a device in LibreNMS.
:param FQDN of the device to validate. :param FQDN of the device to validate.
""" """
...@@ -63,10 +60,8 @@ def validate_device(fqdn: str): ...@@ -63,10 +60,8 @@ def validate_device(fqdn: str):
CFG.url_devices, headers=CFG.headers) CFG.url_devices, headers=CFG.headers)
assert nms_result is not None assert nms_result is not None
device_id = list(map( device_id = [x.get("device_id") for x in filter(lambda x: x.get("hostname") == fqdn,
lambda x: x.get("device_id"), nms_result.json().get("devices"))]
filter(lambda x: x.get("hostname") == fqdn,
nms_result.json().get("devices"))))
if len(device_id) != 1 or device_id[0] is None: if len(device_id) != 1 or device_id[0] is None:
error_msg = f"Device with FQDN={fqdn} is not registered in LibreNMS" error_msg = f"Device with FQDN={fqdn} is not registered in LibreNMS"
...@@ -96,8 +91,7 @@ def validate_device(fqdn: str): ...@@ -96,8 +91,7 @@ def validate_device(fqdn: str):
def register_device(fqdn: str): def register_device(fqdn: str):
""" """Function that registers a new device in LibreNMS.
Function that registers a new device in LibreNMS.
:param FQDN of the device to register. :param FQDN of the device to register.
""" """
...@@ -115,7 +109,7 @@ def register_device(fqdn: str): ...@@ -115,7 +109,7 @@ def register_device(fqdn: str):
} }
if CFG.SNMP.version == "v2c": if CFG.SNMP.version == "v2c":
device_data.update({ device_data.update({
"community": CFG.SNMP.V2.community "community": CFG.SNMP.V2.community,
}) })
elif CFG.SNMP.version == "v3": elif CFG.SNMP.version == "v3":
...@@ -138,8 +132,7 @@ def register_device(fqdn: str): ...@@ -138,8 +132,7 @@ def register_device(fqdn: str):
def deregister_device(fqdn: str): def deregister_device(fqdn: str):
""" """Function that reregisters a device from LibreNMS.
Function that reregisters a device from LibreNMS.
:param FQDN of the device to deregister. :param FQDN of the device to deregister.
""" """
...@@ -149,10 +142,8 @@ def deregister_device(fqdn: str): ...@@ -149,10 +142,8 @@ def deregister_device(fqdn: str):
nms_result = requests.get( nms_result = requests.get(
CFG.url_devices, headers=CFG.headers) CFG.url_devices, headers=CFG.headers)
assert nms_result is not None assert nms_result is not None
device_id = list(map( device_id = [x.get("device_id") for x in filter(lambda x: x.get("hostname") == fqdn,
lambda x: x.get("device_id"), nms_result.json().get("devices"))]
filter(lambda x: x.get("hostname") == fqdn,
nms_result.json().get("devices"))))
if len(device_id) != 1: if len(device_id) != 1:
return return
device_id = device_id[0] device_id = device_id[0]
...@@ -160,7 +151,7 @@ def deregister_device(fqdn: str): ...@@ -160,7 +151,7 @@ def deregister_device(fqdn: str):
# https://docs.librenms.org/API/Devices/#endpoint-categories # https://docs.librenms.org/API/Devices/#endpoint-categories
device_data = { device_data = {
"field": "disabled", "field": "disabled",
"data": "1" "data": "1",
} }
url_device = f"{CFG.url_devices}/{device_id}" url_device = f"{CFG.url_devices}/{device_id}"
logger.debug(f"Connecting to URL: {url_device}" logger.debug(f"Connecting to URL: {url_device}"
......
...@@ -115,7 +115,7 @@ def get_active_trunks_that_terminate_on_router(subscription_id: UUIDstr) -> list ...@@ -115,7 +115,7 @@ def get_active_trunks_that_terminate_on_router(subscription_id: UUIDstr) -> list
""" """
return query_in_use_by_subscriptions(UUID(subscription_id)).join(ProductTable).filter( return query_in_use_by_subscriptions(UUID(subscription_id)).join(ProductTable).filter(
ProductTable.product_type == "Iptrunk", ProductTable.product_type == "Iptrunk",
SubscriptionTable.status == "active" SubscriptionTable.status == "active",
).all() ).all()
......
...@@ -21,8 +21,6 @@ class GeneralParams(BaseSettings): ...@@ -21,8 +21,6 @@ class GeneralParams(BaseSettings):
public_hostname: str public_hostname: str
"""The hostname that :term:`GSO` is publicly served at, used for building the callback URL that the provisioning """The hostname that :term:`GSO` is publicly served at, used for building the callback URL that the provisioning
proxy uses.""" proxy uses."""
environment: str
"""The environment in which :term:`GSO` runs."""
class CeleryParams(BaseSettings): class CeleryParams(BaseSettings):
...@@ -97,24 +95,21 @@ class IPAMParams(BaseSettings): ...@@ -97,24 +95,21 @@ class IPAMParams(BaseSettings):
class MonitoringLibreNMSDevGroupsParams(BaseSettings): class MonitoringLibreNMSDevGroupsParams(BaseSettings):
""" """Parameters related to LibreNMS device groups."""
Parameters related to LibreNMS device groups.
"""
routers_lab: str routers_lab: str
routers_prod: str routers_prod: str
class MonitoringSNMPV2Params(BaseSettings): class MonitoringSNMPV2Params(BaseSettings):
""" """Parameters related to SNMPv2."""
Parameters related to SNMPv2.
"""
community: str community: str
class MonitoringSNMPV3Params(BaseSettings): class MonitoringSNMPV3Params(BaseSettings):
""" """Parameters related to SNMPv3."""
Parameters related to SNMPv3.
"""
authlevel: str authlevel: str
authname: str authname: str
authpass: str authpass: str
...@@ -123,30 +118,19 @@ class MonitoringSNMPV3Params(BaseSettings): ...@@ -123,30 +118,19 @@ class MonitoringSNMPV3Params(BaseSettings):
cryptoalgo: str cryptoalgo: str
class MonitoringSNMPParams(BaseSettings):
"""
Parameters related to SNMP.
"""
version: str
V2: MonitoringSNMPV2Params
V3: MonitoringSNMPV3Params
class MonitoringLibreNMSParams(BaseSettings): class MonitoringLibreNMSParams(BaseSettings):
""" """Parameters related to LibreNMS."""
Parameters related to LibreNMS.
"""
endpoint: str endpoint: str
token: str token: str
DEVICE_GROUPS: MonitoringLibreNMSDevGroupsParams DEVICE_GROUPS: MonitoringLibreNMSDevGroupsParams
class MonitoringParams(BaseSettings): class MonitoringParams(BaseSettings):
""" """Parameters related to the monitoring."""
Parameters related to the monitoring.
"""
LIBRENMS: MonitoringLibreNMSParams LIBRENMS: MonitoringLibreNMSParams
SNMP: MonitoringSNMPParams SNMP: MonitoringSNMPV2Params | MonitoringSNMPV3Params
class ProvisioningProxyParams(BaseSettings): class ProvisioningProxyParams(BaseSettings):
......
...@@ -10,8 +10,8 @@ from pydantic import root_validator ...@@ -10,8 +10,8 @@ from pydantic import root_validator
from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.router import RouterRole
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
from gso.services import provisioning_proxy, subscriptions from gso.services import librenms_client, provisioning_proxy, subscriptions
from gso.services.provisioning_proxy import pp_interaction, indifferent_pp_interaction from gso.services.provisioning_proxy import indifferent_pp_interaction, pp_interaction
from gso.services.subscriptions import get_active_trunks_that_terminate_on_router from gso.services.subscriptions import get_active_trunks_that_terminate_on_router
...@@ -52,14 +52,14 @@ def _generate_pe_inventory(pe_router_list: list[Router]) -> dict[str, Any]: ...@@ -52,14 +52,14 @@ def _generate_pe_inventory(pe_router_list: list[Router]) -> dict[str, Any]:
"lo4": router.router.router_lo_ipv4_address, "lo4": router.router.router_lo_ipv4_address,
"lo6": router.router.router_lo_ipv6_address, "lo6": router.router.router_lo_ipv6_address,
"vendor": router.router.vendor, "vendor": router.router.vendor,
} },
} for router in pe_router_list } for router in pe_router_list
}, },
"all": { "all": {
"hosts": { "hosts": {
router.router.router_fqdn: None for router in pe_router_list router.router.router_fqdn: None for router in pe_router_list
} },
} },
} }
...@@ -67,7 +67,7 @@ def _generate_pe_inventory(pe_router_list: list[Router]) -> dict[str, Any]: ...@@ -67,7 +67,7 @@ def _generate_pe_inventory(pe_router_list: list[Router]) -> dict[str, Any]:
def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list: list[Router]) -> State: def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list: list[Router]) -> State:
extra_vars = { extra_vars = {
"dry_run": True, "dry_run": True,
"subscription": subscription "subscription": subscription,
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
...@@ -84,7 +84,7 @@ def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list: ...@@ -84,7 +84,7 @@ def add_p_to_mesh_dry(subscription: Router, callback_route: str, pe_router_list:
def add_p_to_mesh_real(subscription: Router, callback_route: str, pe_router_list: list[Router]) -> State: def add_p_to_mesh_real(subscription: Router, callback_route: str, pe_router_list: list[Router]) -> State:
extra_vars = { extra_vars = {
"dry_run": False, "dry_run": False,
"subscription": subscription "subscription": subscription,
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
...@@ -113,9 +113,9 @@ def add_all_pe_to_p_dry(subscription: Router, pe_router_list: list[Router], call ...@@ -113,9 +113,9 @@ def add_all_pe_to_p_dry(subscription: Router, pe_router_list: list[Router], call
inventory = { inventory = {
"all": { "all": {
"hosts": { "hosts": {
router.router.router_fqdn: None router.router.router_fqdn: None,
} for router in pe_router_list } for router in pe_router_list
} },
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
...@@ -144,9 +144,9 @@ def add_all_pe_to_p_real(subscription: Router, pe_router_list: list[Router], cal ...@@ -144,9 +144,9 @@ def add_all_pe_to_p_real(subscription: Router, pe_router_list: list[Router], cal
inventory = { inventory = {
"all": { "all": {
"hosts": { "hosts": {
router.router.router_fqdn: None router.router.router_fqdn: None,
} for router in pe_router_list } for router in pe_router_list
} },
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
...@@ -164,9 +164,9 @@ def check_ibgp_session(subscription: Router, callback_route: str) -> State: ...@@ -164,9 +164,9 @@ def check_ibgp_session(subscription: Router, callback_route: str) -> State:
inventory = { inventory = {
"all": { "all": {
"hosts": { "hosts": {
subscription.router.router_fqdn: None subscription.router.router_fqdn: None,
} },
} },
} }
provisioning_proxy.execute_playbook( provisioning_proxy.execute_playbook(
...@@ -199,7 +199,7 @@ def update_subscription_model(subscription: Router) -> State: ...@@ -199,7 +199,7 @@ def update_subscription_model(subscription: Router) -> State:
target=Target.MODIFY, target=Target.MODIFY,
) )
def update_ibgp_mesh() -> StepList: def update_ibgp_mesh() -> StepList:
"""Update the iBGP mesh with a new P router """Update the iBGP mesh with a new P router.
* Add the new P-router to all other PE-routers in the network, including a dry run. * Add the new P-router to all other PE-routers in the network, including a dry run.
* Add all PE-routers to the P-router, including a dry run. * Add all PE-routers to the P-router, including a dry run.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment