Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Merge requests
!904
Fixes after consul-setup that work with existing integration tests
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Fixes after consul-setup that work with existing integration tests
consul-setup-tangostationcontrol-fixes
into
consul-setup
Overview
6
Commits
1
Pipelines
0
Changes
3
Merged
Jan David Mol
requested to merge
consul-setup-tangostationcontrol-fixes
into
consul-setup
1 year ago
Overview
6
Commits
1
Pipelines
0
Changes
3
Fixes scraping consul's metrics
Hardens log scraping against broken configs
Use IP & MAC from container to forward statistics to
Edited
1 year ago
by
Jan David Mol
0
0
Merge request reports
Compare
consul-setup
version 3
5c92f71d
1 year ago
version 2
07463525
1 year ago
version 1
c577d120
1 year ago
consul-setup (base)
and
latest version
latest version
5c92f71d
1 commit,
1 year ago
version 3
5c92f71d
47 commits,
1 year ago
version 2
07463525
14 commits,
1 year ago
version 1
c577d120
13 commits,
1 year ago
3 files
+
26
−
17
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
tangostationcontrol/tangostationcontrol/common/net.py
+
24
−
15
View file @ 5c92f71d
Edit in single-file editor
Open in Web IDE
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: Apache-2.0
import
netifaces
import
psutil
from
ipaddress
import
IPv4Address
from
socket
import
AddressFamily
__all__
=
[
"
get_mac
"
,
"
get_ip
"
]
def
_get_interface_addresses
(
interface
:
str
)
->
list
:
try
:
return
psutil
.
net_if_addrs
()[
interface
]
except
KeyError
as
e
:
raise
ValueError
(
f
"
Cannot find interface
{
interface
}
"
)
from
e
def
get_mac
(
interface
:
str
)
->
str
:
def
get_mac
(
interface
:
str
)
->
str
:
"""
Returns the MAC address of the given interface (f.e.
'
eth0
'
).
"""
"""
Returns the MAC address of the given interface (f.e.
'
eth0
'
).
"""
try
:
for
address
in
_get_interface_addresses
(
interface
):
addresses
=
netifaces
.
ifaddresses
(
interface
)
if
address
.
family
==
AddressFamily
.
AF_PACKET
:
return
addresses
[
netifaces
.
AF_LINK
][
0
][
"
addr
"
]
return
address
.
address
except
(
ValueError
,
IndexError
,
KeyError
)
as
e
:
raise
ValueError
(
f
"
Could not obtain MAC address of interface
{
interface
}
"
)
from
e
raise
ValueError
(
f
"
Cannot obtain MAC address of interface
{
interface
}
"
)
def
get_ip
(
interface
:
str
)
->
str
:
"""
Returns the IP address of the given interface (f.e.
'
eth0
'
).
"""
try
:
def
get_ip
(
interface
:
str
)
->
IPv4Address
:
addresses
=
netifaces
.
ifaddresses
(
interface
)
"""
Returns the IPv4 address of the given interface (f.e.
'
eth0
'
).
"""
return
addresses
[
netifaces
.
AF_INET
][
0
][
"
addr
"
]
except
(
ValueError
,
IndexError
,
KeyError
)
as
e
:
for
address
in
_get_interface_addresses
(
interface
):
raise
ValueError
(
f
"
Could not obtain IP address of interface
{
interface
}
"
)
from
e
if
address
.
family
==
AddressFamily
.
AF_INET
:
return
IPv4Address
(
address
.
address
)
raise
ValueError
(
f
"
Cannot obtain IP address of interface
{
interface
}
"
)
Loading