From 77dace9a66f30826302b75ed0601b4d37687926b Mon Sep 17 00:00:00 2001 From: London Bielicke Date: Tue, 9 Jul 2024 13:35:48 -0600 Subject: [PATCH] implemented image list functions... workd with crictl images --- grpc_server/test/test_grpc_server.py | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/grpc_server/test/test_grpc_server.py b/grpc_server/test/test_grpc_server.py index cec072845..7bdd43a7f 100644 --- a/grpc_server/test/test_grpc_server.py +++ b/grpc_server/test/test_grpc_server.py @@ -6,6 +6,44 @@ from concurrent import futures import subprocess +# ImageService defines the public APIs for managing images. +class ImageServiceServicer(cri_pb2_grpc.ImageServiceServicer): + # Lists existing images + def ListImages(self, request, context): + print("in List Images") # DEBUG + + # creates empty respone + response = cri_pb2.ListImagesResponse() + + # calls ch-image list and stores stdout + cmd = "/usr/local/src/charliecloud/bin/ch-image" + ca = [cmd, "list"] + output = subprocess.check_output(ca, stderr=subprocess.STDOUT) + + # images as strings + # note: decode changes bytes to string, split converts string to array, and finally remove the empty string + images = output.decode("utf-8").split("\n")[:-1] + + # for every image in charliecloud cache: + # create an image object with the name as the ID and append to the repeated field + for img in images: + response.images.append(cri_pb2.Image(id=img)) # note: incomplete... image missing fields + + print(response.images) # DEBUG + return response + + # ImageFSInfo returns information of the filesystem that is used to store images. + def ImageFsInfo(self, request, context): + print("In Image Fs Info") # DEBUG + + # dummy placeholders + filesystem_info = cri_pb2.FilesystemUsage() + response = cri_pb2.ImageFsInfoResponse(image_filesystems=[filesystem_info]) + + return response + + + # organise version information to return as protobuf VERSION_INFO = { "KubeVersion": "v1", # version of the kubelet runtime api "RuntimeName": "Charliecloud", # name of the container runtime (const) @@ -29,13 +67,21 @@ def Version(self, request, context): return response + # dummy start container function + def StartContainer(self, request, context): + print("start container:", request.container_id) # DEBUG + return cri_pb2.StartContainerResponse() + + def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) cri_pb2_grpc.add_RuntimeServiceServicer_to_server(RuntimeServiceServicer(), server) + cri_pb2_grpc.add_ImageServiceServicer_to_server(ImageServiceServicer(), server) server.add_insecure_port(f'unix:///tmp/test.sock') server.start() print("Server listening on port 50052...") # DEBUG server.wait_for_termination() if __name__ == '__main__': + # start gRPC server serve()