This repository was archived by the owner on Aug 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
python/vyos/vpp/interface Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,7 @@ def delete(self):
117
117
a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25')
118
118
a.delete()
119
119
"""
120
+ self .wait_for_vpp_api ()
120
121
return self .vpp .api .gre_tunnel_add_del (
121
122
is_add = False , tunnel = {'src' : self .src_address , 'dst' : self .dst_address }
122
123
)
@@ -128,6 +129,8 @@ def kernel_add(self):
128
129
a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25')
129
130
a.kernel_add()
130
131
"""
132
+ # Wait for VPP API to be ready
133
+ self .wait_for_vpp_api ()
131
134
self .vpp .lcp_pair_add (self .ifname , self .kernel_interface , 'tun' )
132
135
133
136
def kernel_delete (self ):
@@ -137,4 +140,5 @@ def kernel_delete(self):
137
140
a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25')
138
141
a.kernel_delete()
139
142
"""
143
+ self .wait_for_vpp_api ()
140
144
self .vpp .lcp_pair_del (self .ifname , self .kernel_interface )
Original file line number Diff line number Diff line change 15
15
# with this program; if not, write to the Free Software Foundation, Inc.,
16
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
18
+ import time
18
19
from vyos .vpp import VPPControl
19
20
20
21
@@ -47,3 +48,27 @@ def get_state(self):
47
48
"""
48
49
if_index = self .vpp .get_sw_if_index (self .ifname )
49
50
return self .vpp .api .sw_interface_dump (sw_if_index = if_index )[0 ]['flags' ]
51
+
52
+ def wait_for_vpp_api (self , retries = 10 , delay = 1 ):
53
+ """
54
+ Waits for the VPP API to become available.
55
+
56
+ Args:
57
+ retries (int): Number of times to retry checking the API readiness.
58
+ delay (int): Time in seconds to wait between retries.
59
+
60
+ Raises:
61
+ RuntimeError: If the VPP API is not ready after the specified retries.
62
+ """
63
+ for attempt in range (retries ):
64
+ try :
65
+ # Attempt to connect to the VPP API or call a test method
66
+ if self .vpp .api .show_version ():
67
+ print ("VPP API is ready." )
68
+ return
69
+ else :
70
+ raise RuntimeError ("VPP API is not connected." )
71
+ except Exception as e :
72
+ print (f"Attempt { attempt + 1 } /{ retries } : VPP API not ready - { e } " )
73
+ time .sleep (delay )
74
+ raise RuntimeError ("VPP API did not become ready within the expected time." )
You can’t perform that action at this time.
0 commit comments