Skip to content
Snippets Groups Projects
Commit c6f200a9 authored by Robert Latta's avatar Robert Latta
Browse files

Merge branch 'feature/replacement-for-findAffectedCircuits' into develop

parents 9335d3fb fd405e1a
No related branches found
No related tags found
No related merge requests found
......@@ -166,6 +166,7 @@ retrieve_services_query = """SELECT *
c.status != 'terminated'
AND is_circuit = 1)
AS inner_query
WHERE circuit_type IN ('path', 'service', 'l2circuit')
ORDER BY
FIELD(status,
'spare',
......@@ -211,6 +212,14 @@ def _juniper_field_update(record):
return record
def _coriant_field_update(record):
record["interface_name"] = record["card_id"]
if record["port"] is not None and record["port"] != "":
separator = "/" if "-" in record["interface_name"] else ""
record["interface_name"] += separator + str(record["port"])
return record
def _update_fields(r):
func = globals().get("_" + r["manufacturer"] + "_field_update")
return func(r) if func else r
......
......@@ -177,3 +177,17 @@ def interface_statuses(hostname, interface):
status=404,
mimetype="text/html")
return jsonify({"status": result.decode('utf-8')})
@routes.route("/services/<hostname>/<path:interface>",
methods=['GET', 'POST'])
def services_for_interface(hostname, interface):
r = db.get_redis()
result = r.hget("interface_services",
"{}::{}".format(hostname, interface))
if not result:
return Response(
response="no available info for {} {}".format(hostname, interface),
status=404,
mimetype="text/html")
return jsonify(json.loads(result.decode('utf-8')))
......@@ -48,13 +48,6 @@ def startup_update():
return Response("OK")
@routes.route("update-services-to-monitor", methods=['GET'])
def update_services_to_monitor():
app.send_task(
'inventory_provider.tasks.worker.update_service_to_monitor')
return Response("OK")
@routes.route("update-interfaces-to-services", methods=['GET'])
def update_interfaces_to_services():
app.send_task(
......
......@@ -6,7 +6,6 @@ from inventory_provider import db
routes = Blueprint("inventory-opsdb-query-routes", __name__)
monitored_services_key = "monitored_services"
interfaces_key = "interface_services"
equipment_locations_key = "equipment_locations"
service_child_to_parents_key = "child_to_parent_circuit_relations"
......
......@@ -83,7 +83,6 @@ class WorkerArgs(bootsteps.Step):
InventoryTask.logger = logging.getLogger(constants.TASK_LOGGER_NAME)
monitored_services_key = "monitored_services"
interfaces_key = "interface_services"
equipment_locations_key = "equipment_locations"
service_child_to_parents_key = "child_to_parent_circuit_relations"
......@@ -147,22 +146,6 @@ def update_alarmsdb_cache(self):
logger.debug('FINISHED: update_alarmsdb_cache')
@app.task()
def update_service_to_monitor():
# todo - factor this connection stuff out
r = redis.StrictRedis(
host=InventoryTask.config["redis"]["hostname"],
port=InventoryTask.config["redis"]["port"])
r.delete(monitored_services_key)
relevant_types = ("path", "service", "l2circuit")
with db.connection(InventoryTask.config["ops-db"]) as cx:
for circuit in opsdb.get_circuits(cx):
if circuit["circuit_type"].lower() in relevant_types:
r.hset(
monitored_services_key, circuit["id"], json.dumps(circuit))
@app.task()
def update_interfaces_to_services():
# todo - factor this connection stuff out
......@@ -179,6 +162,14 @@ def update_interfaces_to_services():
service["interface_name"]
)
mapped_interfaces[key].append(service)
# Puts lu services under the parent ae as well as their own interface
# eg. services on ae15.12 would be found under ae15 as well as ae15.12
if "." in service["interface_name"]:
key = "{}::{}".format(
service["equipment"],
service["interface_name"].split(".")[0]
)
mapped_interfaces[key].append(service)
r.delete(interfaces_key)
for key, value in mapped_interfaces.items():
......
......@@ -97,6 +97,24 @@ def test_juniper_field_update():
assert r["interface_name"] == "xe-2/0/0.123"
def test_coriant_update_fields():
i = {
"equipment": "groove-1",
"card_id": "2-3",
"port": None
}
r = inventory_provider.opsdb._coriant_field_update(i)
assert r["interface_name"] == "2-3"
i = {
"equipment": "groove-1",
"card_id": "2-3",
"port": "4"
}
r = inventory_provider.opsdb._coriant_field_update(i)
assert r["interface_name"] == "2-3/4"
def test_get_circuits(mocker):
mocker.patch("inventory_provider.opsdb.db.cursor")
mocked_convert_to_dict = mocker.patch(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment