+def find_sockets(path):
+ """ Find any possible sockets to connect to and return them """
+ return glob.glob(os.path.join(path, SOCKET_NAME + '*'))
+
+
+def print_socket_options(prefix, paths):
+ """ Given a set of socket paths, give the commands needed to connect """
+ cmd = sys.argv[0]
+ if prefix != DEFAULT_PREFIX:
+ cmd += " -f " + prefix
+ for s in sorted(paths):
+ sock_name = os.path.basename(s)
+ if sock_name.endswith(TELEMETRY_VERSION):
+ print("- {} # Connect with '{}'".format(os.path.basename(s),
+ cmd))
+ else:
+ print("- {} # Connect with '{} -i {}'".format(os.path.basename(s),
+ cmd,
+ s.split(':')[-1]))
+
+
+def get_dpdk_runtime_dir(fp):
+ """ Using the same logic as in DPDK's EAL, get the DPDK runtime directory
+ based on the file-prefix and user """
+ run_dir = os.environ.get('RUNTIME_DIRECTORY')
+ if not run_dir:
+ if (os.getuid() == 0):
+ run_dir = '/var/run'
+ else:
+ run_dir = os.environ.get('XDG_RUNTIME_DIR', '/tmp')
+ return os.path.join(run_dir, 'dpdk', fp)
+
+
+def list_fp():
+ """ List all available file-prefixes to user """
+ path = get_dpdk_runtime_dir('')
+ sockets = glob.glob(os.path.join(path, "*", SOCKET_NAME + "*"))
+ prefixes = []
+ if not sockets:
+ print("No DPDK apps with telemetry enabled available")
+ else:
+ print("Valid file-prefixes:\n")
+ for s in sockets:
+ prefixes.append(os.path.relpath(os.path.dirname(s), start=path))
+ for p in sorted(set(prefixes)):
+ print(p)
+ print_socket_options(p, glob.glob(os.path.join(path, p,
+ SOCKET_NAME + "*")))
+
+
+def handle_socket(args, path):