|
1 | 1 | """NetApp NVMe driver with dynamic multi-SVM support."""
|
2 | 2 |
|
| 3 | +from contextlib import contextmanager |
| 4 | + |
3 | 5 | from cinder import context
|
4 | 6 | from cinder import exception
|
5 | 7 | from cinder import interface
|
@@ -853,6 +855,11 @@ def create_volume(self, volume):
|
853 | 855 | ) from e
|
854 | 856 |
|
855 | 857 |
|
| 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 | + |
856 | 863 | class NetAppMinimalLibrary(NetAppNVMeStorageLibrary):
|
857 | 864 | """Minimal overriding library.
|
858 | 865 |
|
@@ -949,6 +956,32 @@ def check_for_setup_error(self):
|
949 | 956 | """Check for setup errors."""
|
950 | 957 | self.library.check_for_setup_error()
|
951 | 958 |
|
| 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 | + |
952 | 985 | def create_volume(self, volume):
|
953 | 986 | """Create a volume."""
|
954 | 987 | return self.library.create_volume(volume)
|
|
0 commit comments