Refactor to use VPPApiJSONFiles

This commit is contained in:
Pim van Pelt
2023-01-08 13:24:54 +01:00
parent fe794ed286
commit c81a035091

View File

@ -3,7 +3,7 @@ The functions in this file interact with the VPP API to retrieve certain
interface metadata. interface metadata.
""" """
from vpp_papi import VPPApiClient from vpp_papi import VPPApiClient, VPPApiJSONFiles
import os import os
import fnmatch import fnmatch
import logging import logging
@ -30,19 +30,13 @@ class VPPApi:
if self.connected: if self.connected:
return True return True
vpp_json_dir = "/usr/share/vpp/api/" vpp_json_dir = VPPApiJSONFiles.find_api_dir([])
vpp_jsonfiles = VPPApiJSONFiles.find_api_files(api_dir=vpp_json_dir)
# construct a list of all the json api files if not vpp_jsonfiles:
jsonfiles = []
for root, dirnames, filenames in os.walk(vpp_json_dir):
for filename in fnmatch.filter(filenames, "*.api.json"):
jsonfiles.append(os.path.join(root, filename))
if not jsonfiles:
logger.error("no json api files found") logger.error("no json api files found")
return False return False
self.vpp = VPPApiClient(apifiles=jsonfiles, server_address=self.address) self.vpp = VPPApiClient(apifiles=vpp_jsonfiles, server_address=self.address)
try: try:
logger.info("Connecting to VPP") logger.info("Connecting to VPP")
self.vpp.connect(self.clientname) self.vpp.connect(self.clientname)