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
364ebb9b
Commit
364ebb9b
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Plain Diff
Finished feature DBOARD3-244-add-structured-subtask-reponses.
parents
09734075
55b9d8ba
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/config.py
+1
-1
1 addition, 1 deletion
inventory_provider/config.py
inventory_provider/tasks/worker.py
+59
-17
59 additions, 17 deletions
inventory_provider/tasks/worker.py
with
60 additions
and
18 deletions
inventory_provider/config.py
+
1
−
1
View file @
364ebb9b
...
@@ -8,7 +8,7 @@ CONFIG_SCHEMA = {
...
@@ -8,7 +8,7 @@ CONFIG_SCHEMA = {
"
definitions
"
:
{
"
definitions
"
:
{
"
timeout
"
:
{
"
timeout
"
:
{
"
type
"
:
"
number
"
,
"
type
"
:
"
number
"
,
"
maximum
"
:
1
0
,
# sanity
"
maximum
"
:
6
0
,
# sanity
"
exclusiveMinimum
"
:
0
"
exclusiveMinimum
"
:
0
},
},
"
database-credentials
"
:
{
"
database-credentials
"
:
{
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/worker.py
+
59
−
17
View file @
364ebb9b
...
@@ -35,7 +35,7 @@ def log_task_entry_and_exit(f):
...
@@ -35,7 +35,7 @@ def log_task_entry_and_exit(f):
def
_w
(
*
args
,
**
kwargs
):
def
_w
(
*
args
,
**
kwargs
):
logger
.
debug
(
f
'
>>>
{
f
.
__name__
}{
args
}
'
)
logger
.
debug
(
f
'
>>>
{
f
.
__name__
}{
args
}
'
)
try
:
try
:
return
f
(
*
args
,
*
kwargs
)
return
f
(
*
args
,
*
*
kwargs
)
finally
:
finally
:
logger
.
debug
(
f
'
<<<
{
f
.
__name__
}{
args
}
'
)
logger
.
debug
(
f
'
<<<
{
f
.
__name__
}{
args
}
'
)
return
_w
return
_w
...
@@ -51,6 +51,8 @@ class InventoryTask(Task):
...
@@ -51,6 +51,8 @@ class InventoryTask(Task):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
pid
=
os
.
getpid
()
if
InventoryTask
.
config
:
if
InventoryTask
.
config
:
return
return
...
@@ -69,6 +71,8 @@ class InventoryTask(Task):
...
@@ -69,6 +71,8 @@ class InventoryTask(Task):
def
update_state
(
self
,
**
kwargs
):
def
update_state
(
self
,
**
kwargs
):
meta
=
kwargs
.
setdefault
(
'
meta
'
,
dict
())
meta
=
kwargs
.
setdefault
(
'
meta
'
,
dict
())
meta
[
'
task
'
]
=
self
.
name
meta
[
'
task
'
]
=
self
.
name
meta
[
'
worker
'
]
=
self
.
request
.
hostname
meta
[
'
pid
'
]
=
self
.
pid
logger
.
debug
(
json
.
dumps
(
logger
.
debug
(
json
.
dumps
(
{
'
state
'
:
kwargs
[
'
state
'
],
'
meta
'
:
str
(
meta
)}
{
'
state
'
:
kwargs
[
'
state
'
],
'
meta
'
:
str
(
meta
)}
))
))
...
@@ -78,22 +82,48 @@ class InventoryTask(Task):
...
@@ -78,22 +82,48 @@ class InventoryTask(Task):
logger
.
exception
(
exc
)
logger
.
exception
(
exc
)
super
().
on_failure
(
exc
,
task_id
,
args
,
kwargs
,
einfo
)
super
().
on_failure
(
exc
,
task_id
,
args
,
kwargs
,
einfo
)
def
_task_return_value
(
self
,
warning
,
message
):
"""
common method for constructing a standard task return value
:param warning: boolean (False for normal, warning-free response)
:param message: text message to include in return value
:return: a serializable dict
"""
return
{
'
task
'
:
self
.
name
,
'
id
'
:
self
.
request
.
id
,
'
worker
'
:
self
.
request
.
hostname
,
'
pid
'
:
self
.
pid
,
'
warning
'
:
warning
,
'
message
'
:
message
}
def
success
(
self
,
message
=
'
OK
'
):
return
self
.
_task_return_value
(
warning
=
False
,
message
=
message
)
def
warning
(
self
,
message
=
'
WARNING
'
):
return
self
.
_task_return_value
(
warning
=
True
,
message
=
message
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
snmp_refresh_interfaces
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
snmp_refresh_interfaces
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
def
snmp_refresh_interfaces
(
self
,
hostname
,
community
):
def
snmp_refresh_interfaces
(
self
,
hostname
,
community
):
# TODO: [DBOARD3-242] copy from current redis in case of error
value
=
list
(
snmp
.
get_router_snmp_indexes
(
hostname
,
community
))
value
=
list
(
snmp
.
get_router_snmp_indexes
(
hostname
,
community
))
r
=
get_next_redis
(
InventoryTask
.
config
)
r
=
get_next_redis
(
InventoryTask
.
config
)
r
.
set
(
'
snmp-interfaces:
'
+
hostname
,
json
.
dumps
(
value
))
r
.
set
(
'
snmp-interfaces:
'
+
hostname
,
json
.
dumps
(
value
))
return
self
.
success
(
message
=
f
'
snmp info loaded from
{
hostname
}
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
netconf_refresh_config
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
netconf_refresh_config
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
def
netconf_refresh_config
(
self
,
hostname
):
def
netconf_refresh_config
(
self
,
hostname
):
# TODO: [DBOARD3-242] copy from current redis in case of error
netconf_doc
=
juniper
.
load_config
(
hostname
,
InventoryTask
.
config
[
"
ssh
"
])
netconf_doc
=
juniper
.
load_config
(
hostname
,
InventoryTask
.
config
[
"
ssh
"
])
netconf_str
=
etree
.
tostring
(
netconf_doc
,
encoding
=
'
unicode
'
)
netconf_str
=
etree
.
tostring
(
netconf_doc
,
encoding
=
'
unicode
'
)
r
=
get_next_redis
(
InventoryTask
.
config
)
r
=
get_next_redis
(
InventoryTask
.
config
)
r
.
set
(
'
netconf:
'
+
hostname
,
netconf_str
)
r
.
set
(
'
netconf:
'
+
hostname
,
netconf_str
)
return
self
.
success
(
message
=
f
'
netconf info loaded from
{
hostname
}
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_interfaces_to_services
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_interfaces_to_services
'
)
...
@@ -119,6 +149,8 @@ def update_interfaces_to_services(self):
...
@@ -119,6 +149,8 @@ def update_interfaces_to_services(self):
json
.
dumps
(
services
))
json
.
dumps
(
services
))
rp
.
execute
()
rp
.
execute
()
return
self
.
success
()
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
import_unmanaged_interfaces
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
import_unmanaged_interfaces
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
...
@@ -151,6 +183,8 @@ def import_unmanaged_interfaces(self):
...
@@ -151,6 +183,8 @@ def import_unmanaged_interfaces(self):
json
.
dumps
([
ifc
]))
json
.
dumps
([
ifc
]))
rp
.
execute
()
rp
.
execute
()
return
self
.
success
()
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_access_services
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_access_services
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
...
@@ -180,6 +214,8 @@ def update_access_services(self):
...
@@ -180,6 +214,8 @@ def update_access_services(self):
json
.
dumps
(
service
))
json
.
dumps
(
service
))
rp
.
execute
()
rp
.
execute
()
return
self
.
success
()
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_lg_routers
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_lg_routers
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
...
@@ -197,6 +233,8 @@ def update_lg_routers(self):
...
@@ -197,6 +233,8 @@ def update_lg_routers(self):
rp
.
set
(
f
'
opsdb:lg:
{
router
[
"
equipment name
"
]
}
'
,
json
.
dumps
(
router
))
rp
.
set
(
f
'
opsdb:lg:
{
router
[
"
equipment name
"
]
}
'
,
json
.
dumps
(
router
))
rp
.
execute
()
rp
.
execute
()
return
self
.
success
()
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_equipment_locations
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_equipment_locations
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
...
@@ -216,6 +254,8 @@ def update_equipment_locations(self):
...
@@ -216,6 +254,8 @@ def update_equipment_locations(self):
rp
.
set
(
'
opsdb:location:%s
'
%
h
,
json
.
dumps
(
locations
))
rp
.
set
(
'
opsdb:location:%s
'
%
h
,
json
.
dumps
(
locations
))
rp
.
execute
()
rp
.
execute
()
return
self
.
success
()
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_circuit_hierarchy
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_circuit_hierarchy
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
...
@@ -246,6 +286,8 @@ def update_circuit_hierarchy(self):
...
@@ -246,6 +286,8 @@ def update_circuit_hierarchy(self):
rp
.
set
(
'
opsdb:services:children:%d
'
%
cid
,
json
.
dumps
(
children
))
rp
.
set
(
'
opsdb:services:children:%d
'
%
cid
,
json
.
dumps
(
children
))
rp
.
execute
()
rp
.
execute
()
return
self
.
success
()
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_geant_lambdas
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_geant_lambdas
'
)
@log_task_entry_and_exit
@log_task_entry_and_exit
...
@@ -265,6 +307,8 @@ def update_geant_lambdas(self):
...
@@ -265,6 +307,8 @@ def update_geant_lambdas(self):
json
.
dumps
(
ld
))
json
.
dumps
(
ld
))
rp
.
execute
()
rp
.
execute
()
return
self
.
success
()
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_neteng_managed_device_list
'
)
name
=
'
update_neteng_managed_device_list
'
)
...
@@ -288,10 +332,7 @@ def update_neteng_managed_device_list(self):
...
@@ -288,10 +332,7 @@ def update_neteng_managed_device_list(self):
r
=
get_next_redis
(
InventoryTask
.
config
)
r
=
get_next_redis
(
InventoryTask
.
config
)
r
.
set
(
'
netdash
'
,
json
.
dumps
(
routers
).
encode
(
'
utf-8
'
))
r
.
set
(
'
netdash
'
,
json
.
dumps
(
routers
).
encode
(
'
utf-8
'
))
return
{
return
self
.
success
(
f
'
saved
{
len
(
routers
)
}
managed routers
'
)
'
task
'
:
'
update_neteng_managed_device_list
'
,
'
message
'
:
'
saved %d managed routers
'
%
len
(
routers
)
}
def
load_netconf_data
(
hostname
):
def
load_netconf_data
(
hostname
):
...
@@ -368,6 +409,7 @@ def _refresh_peers(hostname, key_base, peers):
...
@@ -368,6 +409,7 @@ def _refresh_peers(hostname, key_base, peers):
rp
.
execute
()
rp
.
execute
()
@log_task_entry_and_exit
def
refresh_ix_public_peers
(
hostname
,
netconf
):
def
refresh_ix_public_peers
(
hostname
,
netconf
):
_refresh_peers
(
_refresh_peers
(
hostname
,
hostname
,
...
@@ -375,6 +417,7 @@ def refresh_ix_public_peers(hostname, netconf):
...
@@ -375,6 +417,7 @@ def refresh_ix_public_peers(hostname, netconf):
juniper
.
ix_public_peers
(
netconf
))
juniper
.
ix_public_peers
(
netconf
))
@log_task_entry_and_exit
def
refresh_vpn_rr_peers
(
hostname
,
netconf
):
def
refresh_vpn_rr_peers
(
hostname
,
netconf
):
_refresh_peers
(
_refresh_peers
(
hostname
,
hostname
,
...
@@ -382,6 +425,7 @@ def refresh_vpn_rr_peers(hostname, netconf):
...
@@ -382,6 +425,7 @@ def refresh_vpn_rr_peers(hostname, netconf):
juniper
.
vpn_rr_peers
(
netconf
))
juniper
.
vpn_rr_peers
(
netconf
))
@log_task_entry_and_exit
def
refresh_interface_address_lookups
(
hostname
,
netconf
):
def
refresh_interface_address_lookups
(
hostname
,
netconf
):
_refresh_peers
(
_refresh_peers
(
hostname
,
hostname
,
...
@@ -389,6 +433,7 @@ def refresh_interface_address_lookups(hostname, netconf):
...
@@ -389,6 +433,7 @@ def refresh_interface_address_lookups(hostname, netconf):
juniper
.
interface_addresses
(
netconf
))
juniper
.
interface_addresses
(
netconf
))
@log_task_entry_and_exit
def
refresh_juniper_interface_list
(
hostname
,
netconf
):
def
refresh_juniper_interface_list
(
hostname
,
netconf
):
logger
.
debug
(
logger
.
debug
(
'
removing cached netconf-interfaces for %r
'
%
hostname
)
'
removing cached netconf-interfaces for %r
'
%
hostname
)
...
@@ -440,7 +485,7 @@ def reload_router_config(self, hostname):
...
@@ -440,7 +485,7 @@ def reload_router_config(self, hostname):
except
InventoryTaskError
:
except
InventoryTaskError
:
pass
# ok at this point if not found
pass
# ok at this point if not found
# load new netconf data
# load new netconf data
, in this thread
netconf_refresh_config
.
apply
(
args
=
[
hostname
])
netconf_refresh_config
.
apply
(
args
=
[
hostname
])
netconf_doc
=
load_netconf_data
(
hostname
)
netconf_doc
=
load_netconf_data
(
hostname
)
...
@@ -451,11 +496,7 @@ def reload_router_config(self, hostname):
...
@@ -451,11 +496,7 @@ def reload_router_config(self, hostname):
'
no timestamp available for new netconf data
'
'
no timestamp available for new netconf data
'
if
new_netconf_timestamp
==
current_netconf_timestamp
:
if
new_netconf_timestamp
==
current_netconf_timestamp
:
logger
.
debug
(
'
no netconf change timestamp change, aborting
'
)
logger
.
debug
(
'
no netconf change timestamp change, aborting
'
)
return
{
return
self
.
success
(
f
'
no change (timestamp not updated)
'
)
'
task
'
:
'
reload_router_config
'
,
'
hostname
'
:
hostname
,
'
message
'
:
'
OK (no change)
'
}
# clear cached classifier responses for this router, and
# clear cached classifier responses for this router, and
# refresh peering data
# refresh peering data
...
@@ -487,11 +528,7 @@ def reload_router_config(self, hostname):
...
@@ -487,11 +528,7 @@ def reload_router_config(self, hostname):
clear_cached_classifier_responses
(
None
)
clear_cached_classifier_responses
(
None
)
return
{
return
self
.
success
(
f
'
updated config for
{
hostname
}
'
)
'
task
'
:
'
reload_router_config
'
,
'
hostname
'
:
hostname
,
'
message
'
:
'
OK
'
}
def
_erase_next_db
(
config
):
def
_erase_next_db
(
config
):
...
@@ -532,9 +569,11 @@ def internal_refresh_phase_2(self):
...
@@ -532,9 +569,11 @@ def internal_refresh_phase_2(self):
t
=
refresh_finalizer
.
apply_async
(
args
=
[
json
.
dumps
(
pending_task_ids
)])
t
=
refresh_finalizer
.
apply_async
(
args
=
[
json
.
dumps
(
pending_task_ids
)])
pending_task_ids
.
append
(
t
.
id
)
pending_task_ids
.
append
(
t
.
id
)
return
pending_task_ids
return
self
.
success
()
@log_task_entry_and_exit
def
launch_refresh_cache_all
(
config
):
def
launch_refresh_cache_all
(
config
):
"""
"""
utility function intended to be called outside of the worker process
utility function intended to be called outside of the worker process
...
@@ -628,7 +667,10 @@ def refresh_finalizer(self, pending_task_ids_json):
...
@@ -628,7 +667,10 @@ def refresh_finalizer(self, pending_task_ids_json):
latch_db
(
InventoryTask
.
config
)
latch_db
(
InventoryTask
.
config
)
_update
(
'
latched current/next dbs
'
)
_update
(
'
latched current/next dbs
'
)
return
self
.
success
()
@log_task_entry_and_exit
def
_build_service_category_interface_list
(
update_callback
=
lambda
s
:
None
):
def
_build_service_category_interface_list
(
update_callback
=
lambda
s
:
None
):
def
_classify
(
ifc
):
def
_classify
(
ifc
):
...
...
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