Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add backend nvme classes #185

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 231 additions & 1 deletion pydpu/storage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2022 Dell Inc, or its subsidiaries.

import ipaddress
import uuid

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 @@ -332,4 +339,227 @@
name=self.name,
)
)
return res

Check warning on line 342 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L342

Added line #L342 was not covered by tests


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 (

Check warning on line 357 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L357

Added line #L357 was not covered by tests
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)

Check warning on line 368 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L364-L368

Added lines #L364 - L368 were not covered by tests

def create(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.CreateNvmeRemoteController(

Check warning on line 373 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L371-L373

Added lines #L371 - L373 were not covered by tests
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

Check warning on line 385 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L385

Added line #L385 was not covered by tests

def update(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.UpdateNvmeRemoteController(

Check warning on line 390 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L388-L390

Added lines #L388 - L390 were not covered by tests
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

Check warning on line 403 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L403

Added line #L403 was not covered by tests

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

Check warning on line 408 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L406-L408

Added lines #L406 - L408 were not covered by tests
request=backend_nvme_pb2.ListNvmeRemoteControllersRequest()
)
return res

Check warning on line 411 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L411

Added line #L411 was not covered by tests

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

Check warning on line 416 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L414-L416

Added lines #L414 - L416 were not covered by tests
request=backend_nvme_pb2.DeleteNvmeRemoteControllerRequest(
name=self.name,
)
)
return res

Check warning on line 421 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L421

Added line #L421 was not covered by tests

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

Check warning on line 426 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L424-L426

Added lines #L424 - L426 were not covered by tests
request=backend_nvme_pb2.GetNvmeRemoteControllerRequest(
name=self.name,
)
)
return res

Check warning on line 431 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L431

Added line #L431 was not covered by tests

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

Check warning on line 436 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L434-L436

Added lines #L434 - L436 were not covered by tests
request=backend_nvme_pb2.StatsNvmeRemoteControllerRequest(
name=self.name,
)
)
return res

Check warning on line 441 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L441

Added line #L441 was not covered by tests


ip_to_grpc_version = {
4: opicommon_pb2.NVME_ADDRESS_FAMILY_IPV4,
6: opicommon_pb2.NVME_ADDRESS_FAMILY_IPV6,
}


class NvmeTcpPath:
"""An object representing Nvme TCP path.
Args:
ip: ip address to target controller
port: port of target controller
subnqn: subsystem nqn
hostnqn: host nqn
"""

def __repr__(self) -> str:
return (

Check warning on line 460 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L460

Added line #L460 was not covered by tests
f"{type(self).__name__}({str(self.id)}, ip={str(self.ip)}, "
+ f"adrfam={str(self.adrfam)}, port={str(self.port)}), "
+ f"subnqn={str(self.subnqn)}, hostnqn={str(self.hostnqn)}"
)

def __init__(
self,
remote_controller: NvmeRemoteController,
ip: str,
port: int,
subnqn: str,
hostnqn: str = "",
) -> None:
self.id = "opi-" + str(uuid.uuid1())
self.controller = remote_controller
self.ip = ip
self.port = port
self.subnqn = subnqn
self.hostnqn = hostnqn
self.name = "nvmeRemoteControllers/{}/nvmePaths/{}".format(

Check warning on line 480 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L474-L480

Added lines #L474 - L480 were not covered by tests
remote_controller.id, self.id
)
self.adrfam = ip_to_grpc_version[ipaddress.ip_address(self.ip).version]

Check warning on line 483 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L483

Added line #L483 was not covered by tests

def create(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.CreateNvmePath(

Check warning on line 488 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L486-L488

Added lines #L486 - L488 were not covered by tests
request=backend_nvme_pb2.CreateNvmePathRequest(
parent=self.controller.name,
nvme_path_id=self.id,
nvme_path=backend_nvme_pb2.NvmePath(
trtype=opicommon_pb2.NVME_TRANSPORT_TYPE_TCP,
traddr=self.ip,
fabrics=backend_nvme_pb2.FabricsPath(
trsvcid=self.port,
subnqn=self.subnqn,
adrfam=self.adrfam,
hostnqn=self.hostnqn,
),
),
)
)
return res

Check warning on line 504 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L504

Added line #L504 was not covered by tests

def update(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.UpdateNvmePath(

Check warning on line 509 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L507-L509

Added lines #L507 - L509 were not covered by tests
request=backend_nvme_pb2.UpdateNvmePathRequest(
update_mask=field_mask_pb2.FieldMask(paths=["*"]),
nvme_path=backend_nvme_pb2.NvmePath(
name=self.name,
trtype=opicommon_pb2.NVME_TRANSPORT_TYPE_TCP,
traddr=self.ip,
fabrics=backend_nvme_pb2.FabricsPath(
trsvcid=self.port,
subnqn=self.subnqn,
adrfam=self.adrfam,
hostnqn=self.hostnqn,
),
),
)
)
return res

Check warning on line 525 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L525

Added line #L525 was not covered by tests

def list(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.ListNvmePaths(

Check warning on line 530 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L528-L530

Added lines #L528 - L530 were not covered by tests
request=backend_nvme_pb2.ListNvmePathsRequest(
parent=self.controller.name
)
)
return res

Check warning on line 535 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L535

Added line #L535 was not covered by tests

def delete(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.DeleteNvmePath(

Check warning on line 540 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L538-L540

Added lines #L538 - L540 were not covered by tests
request=backend_nvme_pb2.DeleteNvmePathRequest(
name=self.name,
)
)
return res

Check warning on line 545 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L545

Added line #L545 was not covered by tests

def get(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.GetNvmePath(

Check warning on line 550 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L548-L550

Added lines #L548 - L550 were not covered by tests
request=backend_nvme_pb2.GetNvmePathRequest(
name=self.name,
)
)
return res

Check warning on line 555 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L555

Added line #L555 was not covered by tests

def stats(self, address):
with grpc.insecure_channel(address) as channel:
stub = backend_nvme_pb2_grpc.NvmeRemoteControllerServiceStub(channel)
res = stub.StatsNvmePath(

Check warning on line 560 in pydpu/storage.py

View check run for this annotation

Codecov / codecov/patch

pydpu/storage.py#L558-L560

Added lines #L558 - L560 were not covered by tests
request=backend_nvme_pb2.StatsNvmePathRequest(
name=self.name,
)
)
return res
Loading