Skip to content

Commit 30f4811

Browse files
committed
Load SRV6_PFPLM_PATH from env variables (.env file) in 8r-1c-srv6-pm
1 parent 2c7814f commit 30f4811

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

nets/8r-1c-srv6-pm/nodeconf/common/ebpf_py_cli.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,43 @@
22

33
import os
44
import sys
5-
6-
sys.path.append(os.path.abspath("/opt/srv6-pm-xdp-ebpf/srv6-pfplm"))
5+
from dotenv import load_dotenv
6+
7+
# Load environment variables from .env file
8+
load_dotenv()
9+
10+
SRV6_PFPLM_PATH = '/opt/srv6-pm-xdp-ebpf/srv6-pfplm'
11+
12+
# Environment variables have priority over hardcoded paths
13+
# If an environment variable is set, we must use it instead of
14+
# the hardcoded constant
15+
if os.getenv('SRV6_PFPLM_PATH') is not None:
16+
# Check if the SRV6_PFPLM_PATH variable is set
17+
if os.getenv('SRV6_PFPLM_PATH') == '':
18+
print('Error : Set SRV6_PFPLM_PATH variable in .env\n')
19+
sys.exit(-2)
20+
# Check if the SRV6_PFPLM_PATH variable points to an existing folder
21+
if not os.path.exists(SRV6_PFPLM_PATH):
22+
print('Error : SRV6_PFPLM_PATH variable in '
23+
'.env points to a non existing folder')
24+
sys.exit(-2)
25+
# SRV6_PFPLM_PATH in .env is correct. We use it.
26+
SRV6_PFPLM_PATH = os.getenv('SRV6_PFPLM_PATH')
27+
else:
28+
# SRV6_PFPLM_PATH in .env is not set, we use the hardcoded path
29+
#
30+
# Check if the SRV6_PFPLM_PATH variable is set
31+
if SRV6_PFPLM_PATH == '':
32+
print('Error : Set SRV6_PFPLM_PATH variable in .env or %s' % sys.argv[0])
33+
sys.exit(-2)
34+
# Check if the SRV6_PFPLM_PATH variable points to an existing folder
35+
if not os.path.exists(SRV6_PFPLM_PATH):
36+
print('Error : SRV6_PFPLM_PATH variable in '
37+
'%s points to a non existing folder' % sys.argv[0])
38+
print('Error : Set SRV6_PFPLM_PATH variable in .env or %s\n' % sys.argv[0])
39+
sys.exit(-2)
40+
41+
sys.path.append(os.path.abspath(SRV6_PFPLM_PATH))
742

843
from xdp_srv6_pfplm_helper_user import EbpfException, EbpfPFPLM
944

0 commit comments

Comments
 (0)