Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-dashboard-manager
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
brian
brian-dashboard-manager
Commits
e29f0841
Commit
e29f0841
authored
4 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Temporarily fetch IPv6 info from separate endpoint
parent
2e6b2188
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
brian_dashboard_manager/inventory_provider/interfaces.py
+41
-2
41 additions, 2 deletions
brian_dashboard_manager/inventory_provider/interfaces.py
with
41 additions
and
2 deletions
brian_dashboard_manager/inventory_provider/interfaces.py
+
41
−
2
View file @
e29f0841
import
requests
import
logging
from
functools
import
reduce
logger
=
logging
.
getLogger
(
__name__
)
def
get_interfaces
(
host
):
def
_get_ip_info
(
host
):
# pragma: no cover
def
reduce_func
(
prev
,
curr
):
interface_name
=
curr
.
get
(
'
name
'
)
router_name
=
curr
.
get
(
'
router
'
)
if
interface_name
and
router_name
:
router
=
prev
.
get
(
router_name
,
{})
interface
=
router
.
get
(
interface_name
,
{})
ipv4
=
curr
.
get
(
'
ipv4
'
,
[])
ipv6
=
curr
.
get
(
'
ipv6
'
,
[])
interface
[
'
ipv4
'
]
=
ipv4
interface
[
'
ipv6
'
]
=
ipv6
router
[
interface_name
]
=
interface
prev
[
router_name
]
=
router
return
prev
r
=
requests
.
get
(
f
'
{
host
}
/data/interfaces
'
)
r
.
raise_for_status
()
interfaces
=
r
.
json
()
return
reduce
(
reduce_func
,
interfaces
,
{})
def
get_interfaces
(
host
):
# pragma: no cover
r
=
requests
.
get
(
f
'
{
host
}
/poller/interfaces
'
)
r
.
raise_for_status
()
return
r
.
json
()
interfaces
=
r
.
json
()
ip_info
=
_get_ip_info
(
host
)
def
enrich
(
interface
):
router_name
=
interface
.
get
(
'
router
'
)
router
=
ip_info
.
get
(
router_name
)
if
not
router
:
return
interface
ip
=
router
.
get
(
interface
[
'
name
'
])
ipv4
=
ip
[
'
ipv4
'
]
ipv6
=
ip
[
'
ipv6
'
]
interface
[
'
ipv4
'
]
=
ipv4
interface
[
'
ipv6
'
]
=
ipv6
return
interface
enriched
=
list
(
map
(
enrich
,
interfaces
))
return
enriched
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