Skip to content
Snippets Groups Projects
Commit 6560530f authored by Erik Reid's avatar Erik Reid
Browse files

added some variables to the services query conditions

parent f6f2ea9c
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,8 @@ circuit_hierarchy_query = """SELECT
LEFT JOIN events cp on cp.absid = cc.PTR_project"""
retrieve_services_query = """SELECT *
def retrieve_services_query(types):
format = """SELECT *
FROM (SELECT
c.absid AS id,
c.name,
......@@ -141,8 +142,7 @@ retrieve_services_query = """SELECT *
WHERE
equipment IS NOT NULL
AND equipment != ''
AND circuit_type IN (
'path', 'service', 'l2circuit', 'link-aggr-group')
AND circuit_type IN (%s)
ORDER BY
name,
FIELD(status,
......@@ -152,6 +152,10 @@ retrieve_services_query = """SELECT *
'installed',
'operational')"""
assert types
types_string = "'" + "','".join(types) + "'"
return format % types_string
def _convert_to_dict(crs):
return [dict((crs.description[i][0], "" if value is None else value)
......@@ -242,9 +246,9 @@ def get_geant_lambdas(connection): # pragma: no cover
return r
def get_circuits(connection):
def get_circuits(connection, types=['path', 'service', 'l2circuit', 'link-aggr-group']):
with db.cursor(connection) as crs:
crs.execute(retrieve_services_query)
crs.execute(retrieve_services_query(types))
r = _convert_to_dict(crs)
r = list(map(_update_fields, r))
......@@ -527,3 +531,20 @@ def get_service_users(connection, service_ids):
crs.execute(query % ','.join([str(x) for x in chunk]))
for r in crs.fetchall():
yield {'service_id': r[0], 'user': r[1]}
if __name__ == '__main__':
from inventory_provider.db import db
db_params = {
'hostname': '83.97.93.8',
'dbname': 'opsdb',
'username': 'opsro',
'password': 'opsro'
}
with db.connection(db_params) as cx:
circuits = get_circuits(cx)
print(circuits)
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