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
290d2304
Commit
290d2304
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
move all cache updating to single task
parent
54233b87
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/jobs.py
+3
-28
3 additions, 28 deletions
inventory_provider/routes/jobs.py
inventory_provider/tasks/worker.py
+60
-1
60 additions, 1 deletion
inventory_provider/tasks/worker.py
with
63 additions
and
29 deletions
inventory_provider/routes/jobs.py
+
3
−
28
View file @
290d2304
...
...
@@ -4,42 +4,17 @@ from flask import Blueprint, Response, current_app
from
inventory_provider.tasks.app
import
app
from
inventory_provider.constants
import
TASK_LOGGER_NAME
routes
=
Blueprint
(
"
inventory-data-job-routes
"
,
__name__
)
@routes.route
(
"
/update
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
update
():
task_logger
=
logging
.
getLogger
(
TASK_LOGGER_NAME
)
config
=
current_app
.
config
[
"
INVENTORY_PROVIDER_CONFIG
"
]
for
r
in
config
[
"
routers
"
]:
task_logger
.
info
(
"
fetching details for: %r
"
%
r
)
task_logger
.
debug
(
'
launching task:
'
'
inventory_provider.tasks.worker.netconf_refresh_config
'
'
(%s)
'
%
r
[
'
hostname
'
])
app
.
send_task
(
'
inventory_provider.tasks.worker.netconf_refresh_config
'
,
args
=
[
r
[
"
hostname
"
]])
task_logger
.
debug
(
'
launching task:
'
'
inventory_provider.tasks.worker.snmp_refresh_interfaces
'
'
(%s)
'
%
r
[
'
hostname
'
])
app
.
send_task
(
'
inventory_provider.tasks.worker.snmp_refresh_interfaces
'
,
args
=
[
r
[
"
hostname
"
],
r
[
"
community
"
]])
task_logger
.
debug
(
'
launching task:
'
'
inventory_provider.tasks.worker.
update_inventory_system
_cache
'
)
'
inventory_provider.tasks.worker.
refresh
_cache
_all
'
)
app
.
send_task
(
'
inventory_provider.tasks.worker.update_inventory_system_cache
'
)
'
inventory_provider.tasks.worker.refresh_cache_all
'
)
return
Response
(
"
OK
"
)
...
...
@@ -51,7 +26,7 @@ def update():
# 'inventory_provider.tasks.worker.update_alarmsdb_cache')
# app.send_task(
# 'inventory_provider.tasks.worker.update_alarmsdb_cache')
#
return Response("OK")
return
Response
(
"
OK
"
)
# @routes.route("update-interfaces-to-services", methods=['GET'])
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/worker.py
+
60
−
1
View file @
290d2304
import
json
import
logging
import
re
from
celery
import
bootsteps
,
Task
,
group
from
celery.result
import
allow_join_result
from
collections
import
defaultdict
from
lxml
import
etree
...
...
@@ -242,3 +243,61 @@ def update_junosspace_device_list():
r
.
set
(
'
junosspace:
'
+
d
[
'
hostname
'
],
json
.
dumps
(
d
).
encode
(
'
utf-8
'
))
def
_derive_router_hostnames
(
config
):
r
=
get_redis
(
config
)
junosspace_equipment
=
set
()
for
k
in
r
.
keys
(
'
junosspace:*
'
):
m
=
re
.
match
(
'
^junosspace:(.*)$
'
,
k
.
decode
(
'
utf-8
'
))
assert
m
junosspace_equipment
.
add
(
m
.
group
(
1
))
opsdb_equipment
=
set
()
for
k
in
r
.
keys
(
'
opsdb:interface_services:*
'
):
m
=
re
.
match
(
'
opsdb:interface_services:([^:]+):.*$
'
,
k
.
decode
(
'
utf-8
'
))
opsdb_equipment
.
add
(
m
.
group
(
1
))
return
junosspace_equipment
&
opsdb_equipment
@app.task
()
def
refresh_cache_all
():
task_logger
=
logging
.
getLogger
(
constants
.
TASK_LOGGER_NAME
)
task_logger
.
debug
(
'
starting update_junosspace_device_list,
'
'
update_inventory_system_cache
'
)
g
=
group
([
update_junosspace_device_list
.
s
(),
update_inventory_system_cache
.
s
()
])
results
=
g
.
apply_async
()
with
allow_join_result
():
results
.
join
()
for
hostname
in
_derive_router_hostnames
(
InventoryTask
.
config
):
task_logger
.
info
(
"
fetching details for: %r
"
%
hostname
)
task_logger
.
debug
(
'
launching task:
'
'
inventory_provider.tasks.worker.netconf_refresh_config
'
'
(%s)
'
%
hostname
)
app
.
send_task
(
'
inventory_provider.tasks.worker.netconf_refresh_config
'
,
args
=
[
hostname
])
task_logger
.
debug
(
'
launching task:
'
'
inventory_provider.tasks.worker.snmp_refresh_interfaces
'
'
(%s)
'
%
hostname
)
# TODO: !!!! extract community string from netconf data
app
.
send_task
(
'
inventory_provider.tasks.worker.snmp_refresh_interfaces
'
,
args
=
[
hostname
,
'
0pBiFbD
'
])
return
"
OK
"
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