Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
1f9f6b68
Commit
1f9f6b68
authored
5 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added coriant path lookup
parent
a910e575
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/db/opsdb.py
+131
-0
131 additions, 0 deletions
inventory_provider/db/opsdb.py
with
131 additions
and
0 deletions
inventory_provider/db/opsdb.py
+
131
−
0
View file @
1f9f6b68
...
@@ -164,6 +164,17 @@ retrieve_services_query = """SELECT *
...
@@ -164,6 +164,17 @@ retrieve_services_query = """SELECT *
'
installed
'
,
'
installed
'
,
'
operational
'
)
"""
'
operational
'
)
"""
"""
SELECT eq_a.name, eq_b.name, eqc_a.card_id, eqc_b.card_id, vcc.port_a, vcc.port_b FROM vcircuitconns vcc
LEFT JOIN equipment eq_a ON eq_a.absid = vcc.PTR_equip_a
LEFT JOIN equipment eq_b ON eq_b.absid = vcc.PTR_equip_b
LEFT JOIN equipment_card eqc_a ON eqc_a.absid = vcc.PTR_card_a
LEFT JOIN equipment_card eqc_b ON eqc_b.absid = vcc.PTR_card_b
WHERE vcc.status =
'
Operational
'
"""
def
_convert_to_dict
(
crs
):
def
_convert_to_dict
(
crs
):
return
[
dict
((
crs
.
description
[
i
][
0
],
""
if
value
is
None
else
value
)
return
[
dict
((
crs
.
description
[
i
][
0
],
""
if
value
is
None
else
value
)
...
@@ -242,3 +253,123 @@ def get_equipment_location_data(connection): # pragma: no cover
...
@@ -242,3 +253,123 @@ def get_equipment_location_data(connection): # pragma: no cover
crs
.
execute
(
equipment_location_query
)
crs
.
execute
(
equipment_location_query
)
r
=
_convert_to_dict
(
crs
)
r
=
_convert_to_dict
(
crs
)
return
r
return
r
def
get_coriant_path
(
connection
,
equipment_name
,
card_id
,
port_number
):
circuit_query
=
"""
SELECT
vcc.absid,
vcc.category,
vcc.circuit_type,
vcc.service_type,
vcc.peering_type,
eq_a.name as equipment_name_a,
eq_b.name as equipment_name_b,
eqc_a.card_id as card_id_a,
eqc_a.card_id as card_id_b,
pop_a.name as pop_name_a,
pop_b.name as pop_name_b
FROM vcircuitconns vcc
LEFT JOIN equipment eq_a ON eq_a.absid = vcc.PTR_equip_a
LEFT JOIN equipment eq_b ON eq_b.absid = vcc.PTR_equip_b
LEFT JOIN equipment_card eqc_a ON eqc_a.absid = vcc.PTR_card_a
LEFT JOIN equipment_card eqc_b ON eqc_b.absid = vcc.PTR_card_b
LEFT JOIN pop pop_a ON pop_a.absid = vcc.PTR_pop_a
LEFT JOIN pop pop_b ON pop_b.absid = vcc.PTR_pop_b
WHERE vcc.status =
'
Operational
'
AND (
(eq_a.name = %(equipment_name)s
AND eqc_a.card_id = %(card_id)s
AND vcc.port_a = %(port_number)s )
OR
(eq_b.name = %(equipment_name)s
AND eqc_b.card_id = %(card_id)s
AND vcc.port_b = %(port_number)s ))
ORDER BY FIELD(vcc.circuit_type,
'
path
'
) DESC
"""
parent_query
=
"""
SELECT
parent.absid,
parent.category,
parent.circuit_type,
parent.service_type,
parent.peering_type,
eq_a.name as equipment_name_a,
eq_b.name as equipment_name_b,
eqc_a.card_id as card_id_a,
eqc_a.card_id as card_id_b,
pop_a.name as pop_name_a,
pop_b.name as pop_name_b
FROM vcircuitconns parent
LEFT JOIN equipment eq_a ON eq_a.absid = parent.PTR_equip_a
LEFT JOIN equipment eq_b ON eq_b.absid = parent.PTR_equip_b
LEFT JOIN equipment_card eqc_a ON eqc_a.absid = parent.PTR_card_a
LEFT JOIN equipment_card eqc_b ON eqc_b.absid = parent.PTR_card_b
LEFT JOIN pop pop_a ON pop_a.absid = parent.PTR_pop_a
LEFT JOIN pop pop_b ON pop_b.absid = parent.PTR_pop_b
JOIN circuit_glue
ON circuit_glue.PTR_circuit = parent.absid
WHERE circuit_glue.PTR_component = %s
AND circuit_type =
'
Path
'
"""
# for_testing = """
# SELECT parent.absid, child.absid,
# parent.circuit_type as parent_circuit_type,
# child.circuit_type as child_circuit_type,
# eq_a.name as equipment_name_a,
# eq_b.name as equipment_name_b,
# eqc_a.card_id as card_id_a,
# eqc_a.card_id as card_id_b,
# child.port_a as port_a,
# child.port_b as port_b,
# pop_a.name as pop_name_a,
# pop_b.name as pop_name_b
#
# FROM vcircuitconns parent
# RIGHT JOIN circuit_glue
# ON circuit_glue.PTR_circuit = parent.absid
# JOIN vcircuitconns child
# ON circuit_glue.PTR_component = child.absid
#
# LEFT JOIN equipment eq_a ON eq_a.absid = child.PTR_equip_a
# LEFT JOIN equipment eq_b ON eq_b.absid = child.PTR_equip_b
# LEFT JOIN equipment_card eqc_a ON eqc_a.absid = child.PTR_card_a
# LEFT JOIN equipment_card eqc_b ON eqc_b.absid = child.PTR_card_b
# LEFT JOIN pop pop_a ON pop_a.absid = child.PTR_pop_a
# LEFT JOIN pop pop_b ON pop_b.absid = child.PTR_pop_b
#
# WHERE parent.circuit_type = 'Path'
# AND child.circuit_type <> 'Path'
# AND child.status = 'Operational'
# AND (eq_a.name like 'grv%' or eq_b.name like 'grv%')
# """
args
=
{
'
equipment_name
'
:
equipment_name
,
'
card_id
'
:
card_id
,
'
port_number
'
:
port_number
}
with
db
.
cursor
(
connection
)
as
crs
:
crs
.
execute
(
circuit_query
,
args
)
r
=
_convert_to_dict
(
crs
)
if
not
r
:
return
None
circuit
=
r
[
0
]
if
circuit
[
'
circuit_type
'
].
lower
()
==
'
path
'
:
return
circuit
crs
.
execute
(
parent_query
,
[
circuit
[
'
absid
'
]])
r
=
_convert_to_dict
(
crs
)
print
(
"
PARENT
"
)
return
r
[
0
]
if
r
else
None
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment