Skip to content

Commit

Permalink
feat(storage): add NvmeRemoteController class
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun committed Feb 9, 2024
1 parent d28a1cd commit 0f6001f
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion pydpu/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import grpc
from google.protobuf import field_mask_pb2, wrappers_pb2

from .proto.v1 import frontend_nvme_pb2, frontend_nvme_pb2_grpc, opicommon_pb2
from .proto.v1 import (
backend_nvme_pb2,
backend_nvme_pb2_grpc,
frontend_nvme_pb2,
frontend_nvme_pb2_grpc,
opicommon_pb2,
)


class NvmeSubsystem:
Expand Down Expand Up @@ -333,3 +339,102 @@ def stats(self, address):
)
)
return res


class NvmeRemoteController:
"""An object representing Nvme remote controller.
Args:
multipath: multipath mode:
backend_nvme_pb2.NVME_MULTIPATH_DISABLE,
backend_nvme_pb2.NVME_MULTIPATH_FAILOVER,
backend_nvme_pb2.NVME_MULTIPATH_MULTIPATH
hdgst: header digest
ddgst: data digest
"""

def __repr__(self) -> str:
return (
f"{type(self).__name__}({str(self.id)}, "
+ f"multipath={str(self.multipath)}, hdgst={str(self.hdgst)}, "
+ f"ddgst={str(self.ddgst)})"
)

def __init__(self, multipath: int, hdgst: bool, ddgst: bool) -> None:
self.id = "opi-" + str(uuid.uuid1())
self.multipath = multipath
self.hdgst = hdgst
self.ddgst = ddgst
self.name = "nvmeRemoteControllers/{}".format(self.id)

def create(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.CreateNvmeRemoteController(
request=backend_nvme_pb2.CreateNvmeRemoteControllerRequest(
nvme_remote_controller_id=self.id,
nvme_remote_controller=backend_nvme_pb2.NvmeRemoteController(
multipath=self.multipath,
tcp=backend_nvme_pb2.TcpController(
hdgst=self.hdgst,
ddgst=self.ddgst,
),
),
)
)
return res

def update(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.UpdateNvmeRemoteController(
request=backend_nvme_pb2.UpdateNvmeRemoteControllerRequest(
update_mask=field_mask_pb2.FieldMask(paths=["*"]),
nvme_remote_controller=backend_nvme_pb2.NvmeRemoteController(
name=self.name,
multipath=self.multipath,
tcp=backend_nvme_pb2.TcpController(
hdgst=self.hdgst,
ddgst=self.ddgst,
),
),
)
)
return res

def list(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.ListNvmeRemoteControllers(
request=backend_nvme_pb2.ListNvmeRemoteControllersRequest()
)
return res

def delete(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.DeleteNvmeRemoteController(
request=backend_nvme_pb2.DeleteNvmeRemoteControllerRequest(
name=self.name,
)
)
return res

def get(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.GetNvmeRemoteController(
request=backend_nvme_pb2.GetNvmeRemoteControllerRequest(
name=self.name,
)
)
return res

def stats(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.StatsNvmeRemoteController(
request=backend_nvme_pb2.StatsNvmeRemoteControllerRequest(
name=self.name,
)
)
return res

0 comments on commit 0f6001f

Please sign in to comment.