Skip to content

Commit

Permalink
feat(storage): add NvmePath 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 0f6001f commit 0a602ce
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions pydpu/storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2022 Dell Inc, or its subsidiaries.

import ipaddress
import uuid

import grpc
Expand Down Expand Up @@ -438,3 +439,127 @@ def stats(self, address):
)
)
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

0 comments on commit 0a602ce

Please sign in to comment.