Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
implemented image list functions... workd with crictl images
Browse files Browse the repository at this point in the history
  • Loading branch information
LondonMae committed Jul 9, 2024
1 parent 8192b5b commit 77dace9
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions grpc_server/test/test_grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

0 comments on commit 77dace9

Please sign in to comment.