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
e4066474
Commit
e4066474
authored
3 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
catch some missed pyez errors
parent
0620f0c9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/juniper.py
+14
-8
14 additions, 8 deletions
inventory_provider/juniper.py
with
14 additions
and
8 deletions
inventory_provider/juniper.py
+
14
−
8
View file @
e4066474
import
contextlib
import
logging
import
logging
import
re
import
re
import
ipaddress
import
ipaddress
...
@@ -114,6 +115,7 @@ class NetconfHandlingError(Exception):
...
@@ -114,6 +115,7 @@ class NetconfHandlingError(Exception):
pass
pass
@contextlib.contextmanager
def
_rpc
(
hostname
,
ssh
):
def
_rpc
(
hostname
,
ssh
):
dev
=
Device
(
dev
=
Device
(
host
=
hostname
,
host
=
hostname
,
...
@@ -121,9 +123,9 @@ def _rpc(hostname, ssh):
...
@@ -121,9 +123,9 @@ def _rpc(hostname, ssh):
ssh_private_key_file
=
ssh
[
'
private-key
'
])
ssh_private_key_file
=
ssh
[
'
private-key
'
])
try
:
try
:
dev
.
open
()
dev
.
open
()
except
(
EzErrors
.
ConnectError
,
EzErrors
.
RpcError
)
as
e
:
yield
dev
.
rpc
raise
ConnectionError
(
str
(
e
))
finally
:
return
dev
.
rpc
dev
.
close
()
def
validate_netconf_config
(
config_doc
):
def
validate_netconf_config
(
config_doc
):
...
@@ -166,14 +168,18 @@ def load_config(hostname, ssh_params, validate=True):
...
@@ -166,14 +168,18 @@ def load_config(hostname, ssh_params, validate=True):
:param ssh_params:
'
ssh
'
config element(cf. config.py:CONFIG_SCHEMA)
:param ssh_params:
'
ssh
'
config element(cf. config.py:CONFIG_SCHEMA)
:param validate: whether or not to validate netconf data (default True)
:param validate: whether or not to validate netconf data (default True)
:return:
:return:
:raises: NetconfHandlingError
from validate_netconf_config
:raises: NetconfHandlingError
or ConnectionError
"""
"""
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
logger
.
info
(
"
capturing netconf data for
'
%s
'"
%
hostname
)
logger
.
info
(
"
capturing netconf data for
'
%s
'"
%
hostname
)
config
=
_rpc
(
hostname
,
ssh_params
).
get_config
()
try
:
if
validate
:
with
_rpc
(
hostname
,
ssh_params
)
as
router
:
validate_netconf_config
(
config
)
config
=
router
.
get_config
()
return
config
if
validate
:
validate_netconf_config
(
config
)
return
config
except
(
EzErrors
.
ConnectError
,
EzErrors
.
RpcError
)
as
e
:
raise
ConnectionError
(
str
(
e
))
def
list_interfaces
(
netconf_config
):
def
list_interfaces
(
netconf_config
):
...
...
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