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
25a3378c
Commit
25a3378c
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
removed connections with junosspace
parent
03d06d4e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/juniper.py
+10
-95
10 additions, 95 deletions
inventory_provider/juniper.py
test/conftest.py
+1
-5
1 addition, 5 deletions
test/conftest.py
test/test_junosspace_io.py
+5
-10
5 additions, 10 deletions
test/test_junosspace_io.py
with
16 additions
and
110 deletions
inventory_provider/juniper.py
+
10
−
95
View file @
25a3378c
...
@@ -109,53 +109,6 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
...
@@ -109,53 +109,6 @@ UNIT_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?>
"""
# noqa: E501
"""
# noqa: E501
# elements 'use-nat' and 'fingerprint' were added between
# junosspace versions 15.x and 17.x ... hopefully new versions
# will also add new elements at the end of the sequence so
# that the final xs:any below will suffice to allow validation
JUNOSSPACE_DEVICES_SCHEMA
=
"""
<?xml version=
"
1.1
"
encoding=
"
UTF-8
"
?>
<xs:schema xmlns:xs=
"
http://www.w3.org/2001/XMLSchema
"
>
<xs:complexType name=
"
junosspace-device
"
>
<xs:sequence>
<xs:element name=
"
deviceFamily
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
OSVersion
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
platform
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
serialNumber
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
connectionStatus
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
ipAddr
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
managedStatus
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
device-id
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
web-mgmt
"
minOccurs=
"
0
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
lsys-count
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
hosting-deviceId
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
authentication-status
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
connection-type
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
name
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
domain-id
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
domain-name
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:element name=
"
config-status
"
minOccurs=
"
1
"
maxOccurs=
"
1
"
type=
"
xs:string
"
/>
<xs:any processContents=
"
lax
"
minOccurs=
"
0
"
maxOccurs=
"
unbounded
"
/>
</xs:sequence>
<xs:attribute name=
"
href
"
type=
"
xs:string
"
/>
<xs:attribute name=
"
uri
"
type=
"
xs:string
"
/>
<xs:attribute name=
"
key
"
type=
"
xs:string
"
/>
</xs:complexType>
<xs:element name=
"
devices
"
>
<xs:complexType>
<xs:sequence>
<xs:element name=
"
device
"
minOccurs=
"
0
"
maxOccurs=
"
unbounded
"
type=
"
junosspace-device
"
/>
</xs:sequence>
<xs:attribute name=
"
uri
"
type=
"
xs:string
"
/>
<xs:attribute name=
"
size
"
type=
"
xs:string
"
/>
</xs:complexType>
</xs:element>
</xs:schema>
"""
# noqa: E501
def
_rpc
(
hostname
,
ssh
):
def
_rpc
(
hostname
,
ssh
):
dev
=
Device
(
dev
=
Device
(
host
=
hostname
,
host
=
hostname
,
...
@@ -351,58 +304,20 @@ def interface_addresses(netconf_config):
...
@@ -351,58 +304,20 @@ def interface_addresses(netconf_config):
#
#
def
load_routers_from_
junosspace
(
config
):
def
load_routers_from_
netdash
(
url
):
"""
"""
query
junosspace for configured devic
es
query
url for a linefeed-delmitted list of managed router hostnam
es
:param
config: junosspace config element from app config
:param
url: url of alldevices.txt file
:return: list of
dictionaries, each element of which describes a router
:return: list of
router hostnames
"""
"""
logger
=
logging
.
getLogger
(
__name__
)
r
=
requests
.
get
(
url
=
url
)
r
.
raise_for_status
()
request_url
=
config
[
'
api
'
]
if
not
request_url
.
endswith
(
'
/
'
):
request_url
+=
'
/
'
request_url
+=
'
device-management/devices
'
r
=
requests
.
get
(
request_url
,
auth
=
HTTPBasicAuth
(
config
[
'
username
'
],
config
[
'
password
'
]),
# TODO: seems server doesn't send the full chain
# ... add the terena cert locally & reenable cert validateion
verify
=
False
)
# TODO: use a proper exception type
if
r
.
status_code
!=
200
:
logger
.
error
(
"
error response from %r
"
%
request_url
)
assert
False
# TODO: use proper exception type
devices
=
etree
.
fromstring
(
r
.
text
.
encode
(
'
utf-8
'
))
schema_doc
=
etree
.
XML
(
JUNOSSPACE_DEVICES_SCHEMA
.
encode
(
'
utf-8
'
))
schema
=
etree
.
XMLSchema
(
schema_doc
)
if
not
schema
.
validate
(
devices
):
for
e
in
schema
.
error_log
:
logger
.
error
(
'
%d.%d: %s
'
%
(
e
.
line
,
e
.
column
,
e
.
message
))
assert
False
def
_derive_hostname
(
n
):
neteng_routers
=
set
([
# TODO: ask ops if this name->hostname operation is valid
l
.
strip
()
for
l
in
r
.
text
.
splitlines
()
if
l
.
strip
()
if
n
.
endswith
(
'
geant.net
'
):
])
return
n
return
list
(
neteng_routers
)
m
=
re
.
match
(
r
'
^(.*?)(\.re\d+)?$
'
,
n
)
if
m
:
return
m
.
group
(
1
)
+
'
.geant.net
'
logger
.
error
(
f
'
unrecognized junosspace device name format:
"
{
n
}
"'
)
return
None
for
d
in
devices
.
xpath
(
'
//devices/device
'
):
name
=
d
.
xpath
(
'
./name/text()
'
)[
0
]
yield
{
"
OSVersion
"
:
d
.
xpath
(
'
./OSVersion/text()
'
)[
0
],
"
platform
"
:
d
.
xpath
(
'
./platform/text()
'
)[
0
],
"
address
"
:
d
.
xpath
(
'
./ipAddr/text()
'
)[
0
],
"
name
"
:
name
,
"
hostname
"
:
_derive_hostname
(
name
)
}
def
local_interfaces
(
def
local_interfaces
(
...
...
This diff is collapsed.
Click to expand it.
test/conftest.py
+
1
−
5
View file @
25a3378c
...
@@ -42,11 +42,7 @@ def data_config_filename():
...
@@ -42,11 +42,7 @@ def data_config_filename():
"
socket_timeout
"
:
2.8
"
socket_timeout
"
:
2.8
},
},
"
redis-databases
"
:
[
0
,
7
],
"
redis-databases
"
:
[
0
,
7
],
"
junosspace
"
:
{
"
managed-routers
"
:
"
bogus url
"
,
"
api
"
:
"
bogus-url
"
,
"
username
"
:
"
bogus-username
"
,
"
password
"
:
"
bogus-password
"
}
}
}
f
.
write
(
json
.
dumps
(
config
).
encode
(
'
utf-8
'
))
f
.
write
(
json
.
dumps
(
config
).
encode
(
'
utf-8
'
))
...
...
This diff is collapsed.
Click to expand it.
test/test_junosspace_io.py
+
5
−
10
View file @
25a3378c
...
@@ -12,27 +12,22 @@ TEST_DATA_FILENAME = os.path.realpath(os.path.join(
...
@@ -12,27 +12,22 @@ TEST_DATA_FILENAME = os.path.realpath(os.path.join(
'
..
'
,
'
..
'
,
'
test
'
,
'
test
'
,
'
data
'
,
'
data
'
,
'
junosspace-
devices.
xml
'
))
'
netdash-all
devices.
txt
'
))
@responses.activate
@responses.activate
def
test_junosspace_devices_parsing
(
data_config
):
def
test_junosspace_devices_parsing
(
data_config
):
data_config
[
'
junosspace
'
][
'
api
'
]
=
'
http://sabababa
'
data_config
[
'
managed-routers
'
]
=
'
http://sabababa
'
with
open
(
TEST_DATA_FILENAME
)
as
f
:
with
open
(
TEST_DATA_FILENAME
)
as
f
:
responses
.
add
(
responses
.
add
(
method
=
responses
.
GET
,
method
=
responses
.
GET
,
url
=
data_config
[
'
junosspace
'
][
'
api
'
]
+
url
=
data_config
[
'
managed-routers
'
],
'
/device-management/devices
'
,
body
=
f
.
read
())
body
=
f
.
read
())
routers
=
juniper
.
load_routers_from_junosspace
(
data_config
[
'
junosspace
'
])
hostnames
=
juniper
.
load_routers_from_netdash
(
data_config
[
'
managed-routers
'
])
hostnames
=
[
r
[
'
hostname
'
]
for
r
in
routers
]
# test for .re\d+ greediness
assert
'
mx1.ams.nl.geant.net
'
in
hostnames
assert
'
mx1.ams.nl.geant.net
'
in
hostnames
# test that 'qfx1.fra.de' is parsed
assert
'
qfx1.fra.de.geant.net
'
in
hostnames
def
test_router_hostname_derivation
(
mocked_redis
):
def
test_router_hostname_derivation
(
mocked_redis
):
...
...
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