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
0b0c766f
Commit
0b0c766f
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
store & return all peerings for a remote
parent
af9596c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/classifier.py
+7
-5
7 additions, 5 deletions
inventory_provider/routes/classifier.py
inventory_provider/tasks/worker.py
+29
-11
29 additions, 11 deletions
inventory_provider/tasks/worker.py
with
36 additions
and
16 deletions
inventory_provider/routes/classifier.py
+
7
−
5
View file @
0b0c766f
...
@@ -384,13 +384,15 @@ def peer_info(address):
...
@@ -384,13 +384,15 @@ def peer_info(address):
_location_from_service_dict
(
s
)
for
s
in
i
[
'
services
'
]]
_location_from_service_dict
(
s
)
for
s
in
i
[
'
services
'
]]
snmp_info
=
r
.
get
(
snmp_info
=
r
.
get
(
f
'
snmp-peerings:
{
address
}
'
)
f
'
snmp-peerings:
remote:
{
address
}
'
)
if
snmp_info
:
if
snmp_info
:
snmp_info
=
json
.
loads
(
snmp_info
.
decode
(
'
utf-8
'
))
snmp_info
=
json
.
loads
(
snmp_info
.
decode
(
'
utf-8
'
))
result
[
'
snmp
'
]
=
{
result
[
'
snmp
'
]
=
[
'
community
'
:
snmp_info
[
'
community
'
],
{
'
oid
'
:
snmp_info
[
'
oid
'
]
'
hostname
'
:
h
[
'
hostname
'
],
}
'
community
'
:
h
[
'
community
'
],
'
oid
'
:
h
[
'
oid
'
]
}
for
h
in
snmp_info
]
result
[
'
locations
'
]
=
_remove_duplicates_from_list
(
result
[
'
locations
'
])
result
[
'
locations
'
]
=
_remove_duplicates_from_list
(
result
[
'
locations
'
])
result
=
json
.
dumps
(
result
)
result
=
json
.
dumps
(
result
)
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/worker.py
+
29
−
11
View file @
0b0c766f
...
@@ -96,7 +96,7 @@ def snmp_refresh_peerings(self, hostname, community, logical_systems):
...
@@ -96,7 +96,7 @@ def snmp_refresh_peerings(self, hostname, community, logical_systems):
logger
.
exception
(
msg
)
logger
.
exception
(
msg
)
self
.
log_warning
(
msg
)
self
.
log_warning
(
msg
)
r
=
get_current_redis
(
InventoryTask
.
config
)
r
=
get_current_redis
(
InventoryTask
.
config
)
peerings
=
r
.
get
(
f
'
snmp-peerings:
{
hostname
}
:all
'
)
peerings
=
r
.
get
(
f
'
snmp-peerings:
hosts:
{
hostname
}
'
)
if
peerings
is
None
:
if
peerings
is
None
:
raise
InventoryTaskError
(
raise
InventoryTaskError
(
f
'
snmp error with
{
peerings
}
'
f
'
snmp error with
{
peerings
}
'
...
@@ -106,16 +106,7 @@ def snmp_refresh_peerings(self, hostname, community, logical_systems):
...
@@ -106,16 +106,7 @@ def snmp_refresh_peerings(self, hostname, community, logical_systems):
self
.
log_warning
(
f
'
using cached snmp peering data for
{
hostname
}
'
)
self
.
log_warning
(
f
'
using cached snmp peering data for
{
hostname
}
'
)
r
=
get_next_redis
(
InventoryTask
.
config
)
r
=
get_next_redis
(
InventoryTask
.
config
)
r
.
set
(
f
'
snmp-peerings:hosts:
{
hostname
}
'
,
json
.
dumps
(
peerings
))
rp
=
r
.
pipeline
()
rp
.
set
(
f
'
snmp-peerings:
{
hostname
}
:all
'
,
json
.
dumps
(
peerings
))
for
session
in
peerings
:
rp
.
set
(
f
'
snmp-peerings:
{
hostname
}
:
{
session
[
"
remote
"
]
}
'
,
json
.
dumps
(
session
))
rp
.
execute
()
self
.
log_info
(
f
'
snmp peering info loaded from
{
hostname
}
'
)
self
.
log_info
(
f
'
snmp peering info loaded from
{
hostname
}
'
)
...
@@ -726,6 +717,7 @@ def refresh_finalizer(self, pending_task_ids_json):
...
@@ -726,6 +717,7 @@ def refresh_finalizer(self, pending_task_ids_json):
_wait_for_tasks
(
task_ids
,
update_callback
=
self
.
log_info
)
_wait_for_tasks
(
task_ids
,
update_callback
=
self
.
log_info
)
_build_subnet_db
(
update_callback
=
self
.
log_info
)
_build_subnet_db
(
update_callback
=
self
.
log_info
)
_build_peering_db
(
update_callback
=
self
.
log_info
)
except
(
jsonschema
.
ValidationError
,
except
(
jsonschema
.
ValidationError
,
json
.
JSONDecodeError
,
json
.
JSONDecodeError
,
...
@@ -760,6 +752,32 @@ def _build_subnet_db(update_callback=lambda s: None):
...
@@ -760,6 +752,32 @@ def _build_subnet_db(update_callback=lambda s: None):
rp
.
execute
()
rp
.
execute
()
def
_build_peering_db
(
update_callback
=
lambda
s
:
None
):
r
=
get_next_redis
(
InventoryTask
.
config
)
update_callback
(
'
loading all network peerings
'
)
peerings
=
{}
# scan with bigger batches, to mitigate network latency effects
key_prefix
=
'
snmp-peerings:hosts:
'
for
k
in
r
.
scan_iter
(
f
'
{
key_prefix
}
*
'
,
count
=
1000
):
key_name
=
k
.
decode
(
'
utf-8
'
)
hostname
=
key_name
[
len
(
key_prefix
):]
host_peerings
=
r
.
get
(
key_name
).
decode
(
'
utf-8
'
)
host_peerings
=
json
.
loads
(
host_peerings
)
for
p
in
host_peerings
:
p
[
'
hostname
'
]
=
hostname
peerings
.
setdefault
(
p
[
'
remote
'
],
[]).
append
(
p
)
update_callback
(
f
'
saving
{
len
(
peerings
)
}
remote peers
'
)
rp
=
r
.
pipeline
()
for
k
,
v
in
peerings
.
items
():
rp
.
set
(
f
'
snmp-peerings:remote:
{
k
}
'
,
json
.
dumps
(
v
))
rp
.
execute
()
def
check_task_status
(
task_id
,
parent
=
None
,
forget
=
False
):
def
check_task_status
(
task_id
,
parent
=
None
,
forget
=
False
):
r
=
AsyncResult
(
task_id
,
app
=
app
)
r
=
AsyncResult
(
task_id
,
app
=
app
)
assert
r
.
id
==
task_id
# sanity
assert
r
.
id
==
task_id
# sanity
...
...
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