Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-dashboard-manager
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
brian
brian-dashboard-manager
Commits
62efb3e6
Commit
62efb3e6
authored
4 months ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
add vlan_type support
parent
829a08f8
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
brian_dashboard_manager/inventory_provider/interfaces.py
+46
-3
46 additions, 3 deletions
brian_dashboard_manager/inventory_provider/interfaces.py
with
46 additions
and
3 deletions
brian_dashboard_manager/inventory_provider/interfaces.py
+
46
−
3
View file @
62efb3e6
import
requests
import
requests
import
logging
import
logging
import
jsonschema
import
jsonschema
from
collections
import
defaultdict
from
requests.exceptions
import
HTTPError
from
requests.exceptions
import
HTTPError
from
enum
import
Enum
,
auto
from
enum
import
Enum
,
auto
...
@@ -54,6 +55,12 @@ class PORT_TYPES(Enum):
...
@@ -54,6 +55,12 @@ class PORT_TYPES(Enum):
UNKNOWN
=
auto
()
UNKNOWN
=
auto
()
class
VLAN_TYPES
(
Enum
):
ACCESS
=
auto
()
TRUNK
=
auto
()
VLAN
=
auto
()
# only used in INTERFACE_LIST_SCHEMA and sphinx docs
# only used in INTERFACE_LIST_SCHEMA and sphinx docs
_DASHBOARD_IDS
=
[
d
.
name
for
d
in
list
(
BRIAN_DASHBOARDS
)]
_DASHBOARD_IDS
=
[
d
.
name
for
d
in
list
(
BRIAN_DASHBOARDS
)]
...
@@ -61,6 +68,8 @@ _PORT_TYPES = [t.name for t in list(PORT_TYPES)]
...
@@ -61,6 +68,8 @@ _PORT_TYPES = [t.name for t in list(PORT_TYPES)]
_INTERFACE_TYPES
=
[
i
.
name
for
i
in
list
(
INTERFACE_TYPES
)]
_INTERFACE_TYPES
=
[
i
.
name
for
i
in
list
(
INTERFACE_TYPES
)]
_VLAN_TYPES
=
[
i
.
name
for
i
in
list
(
VLAN_TYPES
)]
ROUTER_INTERFACES_SCHEMA
=
{
ROUTER_INTERFACES_SCHEMA
=
{
"
type
"
:
"
array
"
,
"
type
"
:
"
array
"
,
"
items
"
:
{
"
items
"
:
{
...
@@ -121,11 +130,12 @@ INTERFACE_LIST_SCHEMA = {
...
@@ -121,11 +130,12 @@ INTERFACE_LIST_SCHEMA = {
'
type
'
:
'
array
'
,
'
type
'
:
'
array
'
,
'
items
'
:
{
'
$ref
'
:
'
#/definitions/db_info
'
}
'
items
'
:
{
'
$ref
'
:
'
#/definitions/db_info
'
}
},
},
'
port_type
'
:
{
'
enum
'
:
_PORT_TYPES
}
'
port_type
'
:
{
'
enum
'
:
_PORT_TYPES
},
'
vlan_type
'
:
{
'
enum
'
:
_VLAN_TYPES
}
},
},
'
required
'
:
[
'
required
'
:
[
'
router
'
,
'
name
'
,
'
description
'
,
'
router
'
,
'
name
'
,
'
description
'
,
'
dashboards
'
]
'
dashboards
'
,
'
vlan_type
'
]
},
},
},
},
...
@@ -337,7 +347,40 @@ def get_interfaces(host):
...
@@ -337,7 +347,40 @@ def get_interfaces(host):
interfaces
=
r
.
json
()
interfaces
=
r
.
json
()
except
HTTPError
:
except
HTTPError
:
logger
.
exception
(
'
Failed to get interfaces
'
)
logger
.
exception
(
'
Failed to get interfaces
'
)
interfaces
=
[]
return
[]
if
'
vlan_type
'
not
in
interfaces
[
0
]:
# inventory-provider changes are a bit slow, so do it on this side until it's released
ports_and_vlans
=
defaultdict
(
lambda
:
defaultdict
(
list
))
for
ifc
in
interfaces
:
router
=
ifc
[
'
router
'
]
name
=
ifc
[
'
name
'
]
if
'
.
'
in
name
:
name
=
name
.
split
(
'
.
'
)[
0
]
ports_and_vlans
[
router
][
name
].
append
(
ifc
)
# Add interface_type to each interface
# It's used as a filter in the dashboard manager to determine which interfaces are trunks & has VLANs
for
router
,
ifcs
in
ports_and_vlans
.
items
():
for
base_ifc
,
ifc_list
in
ifcs
.
items
():
if
len
(
ifc_list
)
==
1
:
ifc_list
[
0
][
'
vlan_type
'
]
=
VLAN_TYPES
.
ACCESS
.
name
continue
ifc_list
.
sort
(
key
=
lambda
x
:
x
[
'
name
'
])
base
=
ifc_list
.
pop
(
0
)
if
base
[
'
name
'
]
!=
base_ifc
:
base
[
'
vlan_type
'
]
=
VLAN_TYPES
.
VLAN
.
name
else
:
base
[
'
vlan_type
'
]
=
VLAN_TYPES
.
TRUNK
.
name
for
ifc
in
ifc_list
:
ifc
[
'
vlan_type
'
]
=
VLAN_TYPES
.
VLAN
.
name
jsonschema
.
validate
(
interfaces
,
INTERFACE_LIST_SCHEMA
)
jsonschema
.
validate
(
interfaces
,
INTERFACE_LIST_SCHEMA
)
...
...
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