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
44642685
Commit
44642685
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
one method for returning all peerings
parent
b5d512bc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/juniper.py
+36
-0
36 additions, 0 deletions
inventory_provider/juniper.py
inventory_provider/routes/testing.py
+1
-1
1 addition, 1 deletion
inventory_provider/routes/testing.py
test/per_router/test_juniper_data.py
+41
-21
41 additions, 21 deletions
test/per_router/test_juniper_data.py
with
78 additions
and
22 deletions
inventory_provider/juniper.py
+
36
−
0
View file @
44642685
...
@@ -211,6 +211,42 @@ def list_interfaces(netconf_config):
...
@@ -211,6 +211,42 @@ def list_interfaces(netconf_config):
for
u
in
_units
(
name
.
text
,
i
):
for
u
in
_units
(
name
.
text
,
i
):
yield
u
yield
u
def
all_bgp_peers
(
netconf_config
):
def
_peering_params
(
neighbor_node
):
info
=
{
'
address
'
:
neighbor_node
.
find
(
'
name
'
).
text
}
peer_as
=
neighbor_node
.
find
(
'
peer-as
'
)
if
peer_as
is
not
None
:
# lxml usage warning: can't just test `if peer_as:`
info
[
'
peer-as
'
]
=
int
(
peer_as
.
text
)
description
=
neighbor_node
.
find
(
'
description
'
)
if
description
is
not
None
:
# lxml usage warning: can't just test `if description:`
info
[
'
description
'
]
=
description
.
text
return
info
for
instance
in
netconf_config
.
xpath
(
'
//configuration/routing-instances/instance
'
):
instance_name
=
instance
.
find
(
'
name
'
).
text
for
group
in
instance
.
xpath
(
'
./protocols/bgp/group
'
):
group_name
=
group
.
find
(
'
name
'
).
text
for
neighbor
in
group
.
xpath
(
'
./neighbor
'
):
peer
=
_peering_params
(
neighbor
)
peer
[
'
instance
'
]
=
instance_name
peer
[
'
group
'
]
=
group_name
yield
peer
for
logical_system
in
netconf_config
.
xpath
(
'
//configuration/logical-systems
'
):
logical_system_name
=
logical_system
.
find
(
'
name
'
).
text
for
group
in
logical_system
.
xpath
(
'
./protocols/bgp/group
'
):
group_name
=
group
.
find
(
'
name
'
).
text
for
neighbor
in
group
.
xpath
(
'
./neighbor
'
):
peer
=
_peering_params
(
neighbor
)
peer
[
'
logical-system
'
]
=
logical_system_name
peer
[
'
group
'
]
=
group_name
yield
peer
def
list_bgp_routes
(
netconf_config
):
def
list_bgp_routes
(
netconf_config
):
for
r
in
netconf_config
.
xpath
(
for
r
in
netconf_config
.
xpath
(
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/routes/testing.py
+
1
−
1
View file @
44642685
...
@@ -169,7 +169,7 @@ def bgp_configs(hostname):
...
@@ -169,7 +169,7 @@ def bgp_configs(hostname):
status
=
404
,
status
=
404
,
mimetype
=
"
text/html
"
)
mimetype
=
"
text/html
"
)
routes
=
list
(
juniper
.
list
_bgp_
route
s
(
routes
=
list
(
juniper
.
all
_bgp_
peer
s
(
etree
.
XML
(
netconf_string
.
decode
(
'
utf-8
'
))))
etree
.
XML
(
netconf_string
.
decode
(
'
utf-8
'
))))
if
not
routes
:
if
not
routes
:
return
Response
(
return
Response
(
...
...
This diff is collapsed.
Click to expand it.
test/per_router/test_juniper_data.py
+
41
−
21
View file @
44642685
...
@@ -35,33 +35,53 @@ def test_interface_list(netconf_doc):
...
@@ -35,33 +35,53 @@ def test_interface_list(netconf_doc):
assert
interfaces
# at least shouldn't be empty
assert
interfaces
# at least shouldn't be empty
def
test_bgp_
list
(
netconf_doc
):
def
test_bgp_
peering_data
(
netconf_doc
):
schema
=
{
schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
array
"
,
"
definitions
"
:
{
"
items
"
:
{
"
instance-peering
"
:
{
"
type
"
:
"
object
"
,
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
properties
"
:
{
"
name
"
:
{
"
type
"
:
"
string
"
},
"
instance
"
:
{
"
type
"
:
"
string
"
},
"
description
"
:
{
"
type
"
:
"
string
"
},
"
group
"
:
{
"
type
"
:
"
string
"
},
"
as
"
:
{
"
description
"
:
{
"
type
"
:
"
string
"
},
"
type
"
:
"
object
"
,
"
address
"
:
{
"
type
"
:
"
string
"
},
"
properties
"
:
{
"
peer-as
"
:
{
"
type
"
:
"
integer
"
}
"
local
"
:
{
"
type
"
:
"
integer
"
},
},
"
peer
"
:
{
"
type
"
:
"
integer
"
},
# description is not always present, just based on
},
# empirical tests - not a problem
"
required
"
:
[
"
local
"
,
"
peer
"
],
"
required
"
:
[
"
instance
"
,
"
group
"
,
"
address
"
,
"
peer-as
"
],
"
additionalProperties
"
:
False
"
additionalProperties
"
:
False
}
},
},
"
required
"
:
[
"
name
"
,
"
description
"
,
"
as
"
],
"
logical-system-peering
"
:
{
"
additionalProperties
"
:
False
"
type
"
:
"
object
"
,
}
"
properties
"
:
{
"
logical-system
"
:
{
"
type
"
:
"
string
"
},
"
group
"
:
{
"
type
"
:
"
string
"
},
"
description
"
:
{
"
type
"
:
"
string
"
},
"
address
"
:
{
"
type
"
:
"
string
"
},
"
peer-as
"
:
{
"
type
"
:
"
integer
"
}
},
# peer-as and/or description are not always present,
# just based on empirical tests - not a problem
"
required
"
:
[
"
logical-system
"
,
"
group
"
,
"
address
"
],
"
additionalProperties
"
:
False
},
"
peering
"
:
{
"
oneOf
"
:
[
{
"
$ref
"
:
"
#/definitions/instance-peering
"
},
{
"
$ref
"
:
"
#/definitions/logical-system-peering
"
}
]
}
},
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/peering
"
}
}
}
routes
=
list
(
juniper
.
list_bgp_routes
(
netconf_doc
))
peerings
=
list
(
juniper
.
all_bgp_peers
(
netconf_doc
))
jsonschema
.
validate
(
routes
,
schema
)
jsonschema
.
validate
(
peerings
,
schema
)
assert
peerings
# there's always at least one
def
test_snmp_community_string
(
mocked_netifaces
,
netconf_doc
):
def
test_snmp_community_string
(
mocked_netifaces
,
netconf_doc
):
...
...
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