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
a9999a19
Commit
a9999a19
authored
5 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
Module to replace opsdb module. Implemented LG and Pop details functionality.
parent
49eb2514
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/db/ims_data.py
+163
-0
163 additions, 0 deletions
inventory_provider/db/ims_data.py
with
163 additions
and
0 deletions
inventory_provider/db/ims_data.py
0 → 100644
+
163
−
0
View file @
a9999a19
import
re
from
inventory_provider.db
import
ims
from
inventory_provider.db.ims
import
IMS
,
InventoryStatus
INTERNAL_POP_NAMES
=
{
'
Cambridge OC
'
,
'
DANTE Lab
'
,
'
GÉANT LAB
'
,
'
GEANT LAB
'
,
'
Amsterdam GEANT Office
'
,
'
Amsterdam GÉANT Office
'
}
def
lookup_lg_routers
(
ds
):
pattern
=
re
.
compile
(
"
vpn-proxy|vrr|taas
"
,
re
.
IGNORECASE
)
def
_matching_node
(
node_
):
if
InventoryStatus
(
node_
[
'
InventoryStatusId
'
])
not
in
[
InventoryStatus
.
IN_SERVICE
,
InventoryStatus
.
PLANNED
# remove once data fully migrated
]:
return
False
if
pattern
.
match
(
node_
[
'
Name
'
]):
return
False
return
True
site_nav_props
=
[
ims
.
SITE_PROPERTIES
[
'
aliases
'
],
ims
.
SITE_PROPERTIES
[
'
city
'
],
ims
.
SITE_PROPERTIES
[
'
country
'
]
]
eq_definitions
=
ds
.
get_filtered_entities
(
'
EquipmentDefinition
'
,
'
Name like mx
'
,
ims
.
EQUIP_DEF_PROPERTIES
[
'
nodes
'
])
for
eq_def
in
eq_definitions
:
nodes
=
eq_def
[
'
Nodes
'
]
for
node
in
nodes
:
if
not
_matching_node
(
node
):
continue
site
=
ds
.
get_entity_by_id
(
'
Site
'
,
node
[
'
SiteId
'
],
site_nav_props
,
True
)
city
=
site
[
'
City
'
]
abbreviation
=
''
try
:
abbreviation
=
site
[
'
SiteAliases
'
][
0
][
'
AliasName
'
]
except
IndexError
:
pass
# no alias - ignore silently
eq
=
{
'
equipment name
'
:
node
[
'
Name
'
],
'
type
'
:
'
INTERNAL
'
if
site
[
'
Name
'
]
in
INTERNAL_POP_NAMES
else
'
CORE
'
,
'
pop
'
:
{
'
name
'
:
site
[
'
Name
'
],
'
city
'
:
city
[
'
Name
'
],
'
country
'
:
city
[
'
Country
'
][
'
Name
'
],
'
country code
'
:
city
[
'
Country
'
][
'
Abbreviation
'
],
'
abbreviation
'
:
abbreviation
,
'
longitude
'
:
site
[
'
Longitude
'
],
'
latitude
'
:
site
[
'
Latitude
'
],
}
}
yield
(
eq
)
def
lookup_pop_info
(
ds
,
hostname
):
site_nav_props
=
[
ims
.
SITE_PROPERTIES
[
'
aliases
'
],
ims
.
SITE_PROPERTIES
[
'
city
'
],
ims
.
SITE_PROPERTIES
[
'
country
'
]
]
node
=
ds
.
get_entity_by_name
(
'
Node
'
,
hostname
)
if
not
node
:
return
None
site
=
ds
.
get_entity_by_id
(
'
Site
'
,
node
[
'
SiteId
'
],
site_nav_props
,
True
)
city
=
site
[
'
City
'
]
abbreviation
=
''
try
:
abbreviation
=
site
[
'
SiteAliases
'
][
0
][
'
AliasName
'
]
except
IndexError
:
pass
# no alias - ignore silently
eq
=
{
'
equipment-name
'
:
node
[
'
Name
'
],
'
status
'
:
InventoryStatus
(
node
[
'
InventoryStatusId
'
]).
name
,
'
pop
'
:
{
'
name
'
:
site
[
'
Name
'
],
'
city
'
:
city
[
'
Name
'
],
'
country
'
:
city
[
'
Country
'
][
'
Name
'
],
'
abbreviation
'
:
abbreviation
,
'
longitude
'
:
site
[
'
Longitude
'
],
'
latitude
'
:
site
[
'
Latitude
'
],
}
}
return
eq
if
__name__
==
'
__main__
'
:
import
sys
username
=
sys
.
argv
[
1
]
password
=
sys
.
argv
[
2
]
ds
=
IMS
(
'
http://83.97.94.128:81/api
'
,
username
,
password
)
equipment_names
=
[
'
mx1.ams.nl
'
,
'
mx1.ath2.gr
'
,
'
mx1.buc.ro
'
,
'
mx1.bud.hu
'
,
'
mx1.dub.ie
'
,
'
mx1.dub2.ie
'
,
'
mx1.fra.de
'
,
'
mx1.gen.ch
'
,
'
mx1.ham.de
'
,
'
mx1.kau.lt
'
,
'
mx1.lis.pt
'
,
'
mx1.lon.uk
'
,
'
mx1.lon2.uk
'
,
'
mx1.mad.es
'
,
'
mx1.mar.fr
'
,
'
mx1.mil2.it
'
,
'
mx1.par.fr
'
,
'
mx1.poz.pl
'
,
'
mx1.pra.cz
'
,
'
mx1.sof.bg
'
,
'
mx1.tal.ee
'
,
'
mx1.vie.at
'
,
'
mx2.ath.gr
'
,
'
mx2.bra.sk
'
,
'
mx2.bru.be
'
,
'
mx2.kau.lt
'
,
'
mx2.lis.pt
'
,
'
mx2.lju.si
'
,
'
mx2.rig.lv
'
,
'
mx2.tal.ee
'
,
'
mx2.zag.hr
'
,
'
qfx.fra.de
'
,
'
qfx.lon2.uk
'
,
'
qfx.par.fr
'
]
for
equipment
in
equipment_names
:
r
=
lookup_pop_info
(
ds
,
equipment
)
print
(
''
)
print
(
r
)
print
(
''
)
print
(
'
--------------------
'
)
print
(
'
--------------------
'
)
print
(
'
--------------------
'
)
for
r
in
lookup_lg_routers
(
ds
):
print
(
r
)
print
(
''
)
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