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
901923e6
Commit
901923e6
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
use current data, in case of snmp/netconf errors
parent
5bdc26e2
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
inventory_provider/tasks/worker.py
+46
-10
46 additions, 10 deletions
inventory_provider/tasks/worker.py
with
46 additions
and
10 deletions
inventory_provider/tasks/worker.py
+
46
−
10
View file @
901923e6
...
...
@@ -12,7 +12,8 @@ import jsonschema
from
inventory_provider.tasks.app
import
app
from
inventory_provider.tasks.common
\
import
get_next_redis
,
latch_db
,
get_latch
,
set_latch
,
update_latch_status
import
get_next_redis
,
get_current_redis
,
\
latch_db
,
get_latch
,
set_latch
,
update_latch_status
from
inventory_provider.tasks
import
data
from
inventory_provider
import
config
from
inventory_provider
import
environment
...
...
@@ -108,22 +109,57 @@ class InventoryTask(Task):
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
snmp_refresh_interfaces
'
)
@log_task_entry_and_exit
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
))
warning
=
False
try
:
value
=
list
(
snmp
.
get_router_snmp_indexes
(
hostname
,
community
))
except
ConnectionError
:
logger
.
exception
(
f
'
error loading snmp data from
{
hostname
}
'
)
warning
=
True
r
=
get_current_redis
(
InventoryTask
.
config
)
value
=
r
.
get
(
f
'
snmp-interfaces:
{
hostname
}
'
)
if
not
value
:
raise
InventoryTaskError
(
f
'
snmp error with
{
hostname
}
'
f
'
and no cached netconf data found
'
)
# unnecessary json encode/decode here ... could be optimized
value
=
json
.
loads
(
value
.
decode
(
'
utf-8
'
))
r
=
get_next_redis
(
InventoryTask
.
config
)
r
.
set
(
'
snmp-interfaces:
'
+
hostname
,
json
.
dumps
(
value
))
return
self
.
success
(
message
=
f
'
snmp info loaded from
{
hostname
}
'
)
r
.
set
(
f
'
snmp-interfaces:
{
hostname
}
'
,
json
.
dumps
(
value
))
if
warning
:
return
self
.
warning
(
message
=
f
'
i/o error with
{
hostname
}
, using cached snmp info
'
)
else
:
return
self
.
success
(
message
=
f
'
snmp info loaded from
{
hostname
}
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
netconf_refresh_config
'
)
@log_task_entry_and_exit
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_str
=
etree
.
tostring
(
netconf_doc
,
encoding
=
'
unicode
'
)
warning
=
False
try
:
netconf_doc
=
juniper
.
load_config
(
hostname
,
InventoryTask
.
config
[
"
ssh
"
])
netconf_str
=
etree
.
tostring
(
netconf_doc
,
encoding
=
'
unicode
'
)
except
ConnectionError
:
logger
.
exception
(
f
'
error loading netconf data from
{
hostname
}
'
)
warning
=
True
r
=
get_current_redis
(
InventoryTask
.
config
)
netconf_str
=
r
.
get
(
f
'
netconf:
{
hostname
}
'
)
if
not
netconf_str
:
raise
InventoryTaskError
(
f
'
netconf error with
{
hostname
}
'
f
'
and no cached netconf data found
'
)
r
=
get_next_redis
(
InventoryTask
.
config
)
r
.
set
(
'
netconf:
'
+
hostname
,
netconf_str
)
return
self
.
success
(
message
=
f
'
netconf info loaded from
{
hostname
}
'
)
r
.
set
(
f
'
netconf:
{
hostname
}
'
,
netconf_str
)
if
warning
:
return
self
.
warning
(
message
=
f
'
i/o error with
{
hostname
}
, using cached netconf info
'
)
else
:
return
self
.
success
(
message
=
f
'
netconf info loaded from
{
hostname
}
'
)
@app.task
(
base
=
InventoryTask
,
bind
=
True
,
name
=
'
update_interfaces_to_services
'
)
...
...
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