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
34ad09a1
Commit
34ad09a1
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Plain Diff
Finished feature add-ix-public-peer-group.
parents
d6d79ce3
5fb25738
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+12
-6
12 additions, 6 deletions
README.md
inventory_provider/routes/classifier.py
+32
-0
32 additions, 0 deletions
inventory_provider/routes/classifier.py
test/test_classifier_routes.py
+20
-12
20 additions, 12 deletions
test/test_classifier_routes.py
with
64 additions
and
18 deletions
README.md
+
12
−
6
View file @
34ad09a1
...
...
@@ -376,10 +376,10 @@ Any non-empty responses are JSON formatted messages.
then information about the interface is returned, otherwise
404 is returned.
The resp
onse will be formatted according to the following syntax:
The response will be formatted according to the following syntax:
```
json
{
{
"$schema"
:
"http://json-schema.org/draft-07/schema#"
,
"type"
:
"object"
,
...
...
@@ -402,7 +402,6 @@ Any non-empty responses are JSON formatted messages.
"required"
:
[
"name"
,
"description"
],
"additionalProperties"
:
False
},
"ix-public-peer"
:
{
"type"
:
"object"
,
"properties"
:
{
...
...
@@ -421,17 +420,24 @@ Any non-empty responses are JSON formatted messages.
},
"required"
:
[
"name"
,
"description"
,
"as"
],
"additionalProperties"
:
False
}
},
"ix-public-peer-group"
:
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"#/definitions/ip-address"
}
},
},
"type"
:
"object"
,
"properties"
:
{
"ix-public-peer-info"
:
{
"$ref"
:
"#/definitions/ix-public-peer"
},
"ix-public-peer-group"
:
{
"$ref"
:
"#/definitions/ix-public-peer-group"
},
"vpn-rr-peer-info"
:
{
"$ref"
:
"#/definitions/vpn-rr-peer"
}
},
"additionalProperties"
:
False
}
```
}
```
*
/poller/interfaces/
*`hostname`*
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/routes/classifier.py
+
32
−
0
View file @
34ad09a1
import
ipaddress
import
json
from
flask
import
Blueprint
,
Response
,
jsonify
...
...
@@ -49,6 +50,35 @@ def get_trap_metadata(source_equipment, interface):
@common.require_accepts_json
def
peer_info
(
address
):
def
_related_ix_peers
(
ix_public_peer_info
):
"""
TODO: this is probably the least efficient way of doing this
(if it
'
s a problem, pre-compute these lists)
:param ix_public_peer_info: ix public peer info loaded for address
:return:
"""
protocol
=
type
(
ipaddress
.
ip_address
(
address
)).
__name__
description
=
ix_public_peer_info
[
'
description
'
]
assert
description
is
not
None
# sanity: at least empty string
keyword
=
description
.
split
(
'
'
)[
0
]
# regex needed??? (e.g. tabs???)
r
=
common
.
get_redis
()
for
k
in
r
.
keys
(
'
ix_public_peer:*
'
):
peer
=
r
.
get
(
k
.
decode
(
'
utf-8
'
)).
decode
(
'
utf-8
'
)
peer
=
json
.
loads
(
peer
)
assert
peer
[
'
description
'
]
is
not
None
# sanity: as above...
if
not
peer
[
'
description
'
].
startswith
(
keyword
):
continue
if
peer
[
'
name
'
]
==
address
:
continue
# skip self
peer_address
=
ipaddress
.
ip_address
(
peer
[
'
name
'
])
if
protocol
==
type
(
peer_address
).
__name__
:
yield
peer
[
'
name
'
]
r
=
common
.
get_redis
()
result
=
{}
...
...
@@ -57,6 +87,8 @@ def peer_info(address):
if
info
:
info
=
info
.
decode
(
'
utf-8
'
)
result
[
'
ix-public-peer-info
'
]
=
json
.
loads
(
info
)
result
[
'
ix-public-peer-group
'
]
=
list
(
_related_ix_peers
(
result
[
'
ix-public-peer-info
'
]))
info
=
r
.
get
(
'
vpn_rr_peer:%s
'
%
address
)
if
info
:
...
...
This diff is collapsed.
Click to expand it.
test/test_classifier_routes.py
+
20
−
12
View file @
34ad09a1
...
...
@@ -22,14 +22,19 @@ def test_trap_metadata(client_with_mocked_data):
jsonschema
.
validate
(
response_data
,
response_schema
)
@pytest.mark.parametrize
(
"
peer_address,peer_type
"
,
[
(
'
109.105.110.54
'
,
'
vpn-rr-peer-info
'
),
(
'
2001:07f8:001c:024a:0000:0000:316e:0001
'
,
'
ix-public-peer-info
'
),
(
'
2001:07f8:000b:0100:01d1:a5d1:0310:0029
'
,
'
ix-public-peer-info
'
),
(
'
195.66.224.238
'
,
'
ix-public-peer-info
'
),
VPN_RR_PEER_INFO_KEYS
=
{
'
vpn-rr-peer-info
'
}
IX_PUBLIC_PEER_INFO_KEYS
=
{
'
ix-public-peer-info
'
,
'
ix-public-peer-group
'
}
@pytest.mark.parametrize
(
"
peer_address,expected_response_keys
"
,
[
(
'
109.105.110.54
'
,
VPN_RR_PEER_INFO_KEYS
),
(
'
2001:07f8:001c:024a:0000:0000:316e:0001
'
,
IX_PUBLIC_PEER_INFO_KEYS
),
(
'
2001:07f8:000b:0100:01d1:a5d1:0310:0029
'
,
IX_PUBLIC_PEER_INFO_KEYS
),
(
'
195.66.224.238
'
,
IX_PUBLIC_PEER_INFO_KEYS
),
]
)
def
test_peer_info
(
client_with_mocked_data
,
peer_address
,
peer_type
):
def
test_peer_info
(
client_with_mocked_data
,
peer_address
,
expected_response_keys
):
response_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
object
"
,
...
...
@@ -53,7 +58,6 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
"
required
"
:
[
"
name
"
,
"
description
"
],
"
additionalProperties
"
:
False
},
"
ix-public-peer
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
...
...
@@ -72,12 +76,19 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
},
"
required
"
:
[
"
name
"
,
"
description
"
,
"
as
"
],
"
additionalProperties
"
:
False
}
},
"
ix-public-peer-group
"
:
{
"
type
"
:
"
array
"
,
"
items
"
:
{
"
$ref
"
:
"
#/definitions/ip-address
"
}
},
},
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
ix-public-peer-info
"
:
{
"
$ref
"
:
"
#/definitions/ix-public-peer
"
},
"
ix-public-peer-group
"
:
{
"
$ref
"
:
"
#/definitions/ix-public-peer-group
"
},
"
vpn-rr-peer-info
"
:
{
"
$ref
"
:
"
#/definitions/vpn-rr-peer
"
}
},
"
additionalProperties
"
:
False
...
...
@@ -91,10 +102,7 @@ def test_peer_info(client_with_mocked_data, peer_address, peer_type):
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
response_schema
)
assert
len
(
response_data
)
==
1
,
\
"
peer should be only vpn-rr or ix-public, not both
"
assert
peer_type
in
response_data
assert
set
(
response_data
.
keys
())
==
expected_response_keys
def
test_peer_not_found
(
client_with_mocked_data
):
...
...
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