Skip to content

Commit bbb4e4d

Browse files
nidzraicardoe
authored andcommitted
chore(cinder-understack): add functions to track SVM for a pool
We need to be able to track the SVM with a pool. Unfortunately flexvols which are 1:1 with pool names for a backend are unique in a SVM but they can be repeated between SVMs. So we must prefix the pool name with our SVM name and then strip it off when we need just the pool name.
1 parent ab773a3 commit bbb4e4d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

python/cinder-understack/cinder_understack/dynamic_netapp_driver.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""NetApp NVMe driver with dynamic multi-SVM support."""
22

3+
from contextlib import contextmanager
4+
35
from cinder import context
46
from cinder import exception
57
from cinder import interface
@@ -853,6 +855,11 @@ def create_volume(self, volume):
853855
) from e
854856

855857

858+
# We use a + because of the special meaning of # in
859+
# cinder/volume/volume_utils.py extract_host()
860+
_SVM_NAME_DELIM = "+"
861+
862+
856863
class NetAppMinimalLibrary(NetAppNVMeStorageLibrary):
857864
"""Minimal overriding library.
858865
@@ -949,6 +956,32 @@ def check_for_setup_error(self):
949956
"""Check for setup errors."""
950957
self.library.check_for_setup_error()
951958

959+
def _svmify_pool(self, pool: dict, svm_name: str, **kwargs) -> dict:
960+
"""Applies SVM info to a pool so we can target it and track it."""
961+
# We need to prefix our pool_name, which is 1:1 with the FlexVol
962+
# name on the SVM, with the SVM name. This is because the name of
963+
# a FlexVol is unique within 1 SVM. Two different SVMs can have
964+
# the same FlexVol however so we need to prefix it. We avoid
965+
# using # as our separator because it has special meaning to
966+
# cinder. See the cinder/volume/volume_utils.py extract_host()
967+
# function for details.
968+
pool_name = pool["pool_name"]
969+
pool["pool_name"] = f"{svm_name}{_SVM_NAME_DELIM}{pool_name}"
970+
pool["netapp_vserver"] = svm_name
971+
pool.update(kwargs)
972+
return pool
973+
974+
@contextmanager
975+
def _fix_volume_pool_name(self, svm_name: str, volume):
976+
"""Strips out the SVM name from the volume host and restores."""
977+
original_host = volume.get("host")
978+
if not original_host:
979+
yield original_host
980+
else:
981+
volume["host"] = original_host.replace(f"{svm_name}{_SVM_NAME_DELIM}", "")
982+
yield volume
983+
volume["host"] = original_host
984+
952985
def create_volume(self, volume):
953986
"""Create a volume."""
954987
return self.library.create_volume(volume)

0 commit comments

Comments
 (0)