mirror of
https://github.com/ceph/ceph
synced 2025-01-13 14:33:36 +00:00
mgr/nfs: clean up rados object naming code
The naming of rados objects used to store the nfs config was spread all over the code, including inline f-strings, not-static methods, etc. This change unifies the naming by putting constant string prefixes and name generating functions into the utils.py file. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
c51a6755b5
commit
8826614442
@ -10,7 +10,8 @@ from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec, IngressS
|
||||
import orchestrator
|
||||
|
||||
from .exception import NFSInvalidOperation, ClusterNotFound
|
||||
from .utils import available_clusters, restart_nfs_service
|
||||
from .utils import (available_clusters, restart_nfs_service, conf_obj_name,
|
||||
user_conf_obj_name)
|
||||
from .export import NFSRados, exception_handler
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -50,12 +51,6 @@ class NFSCluster:
|
||||
def __init__(self, mgr: 'Module') -> None:
|
||||
self.mgr = mgr
|
||||
|
||||
def _get_common_conf_obj_name(self, cluster_id: str) -> str:
|
||||
return f'conf-nfs.{cluster_id}'
|
||||
|
||||
def _get_user_conf_obj_name(self, cluster_id: str) -> str:
|
||||
return f'userconf-nfs.{cluster_id}'
|
||||
|
||||
def _call_orch_apply_nfs(
|
||||
self,
|
||||
cluster_id: str,
|
||||
@ -89,17 +84,18 @@ class NFSCluster:
|
||||
port=port)
|
||||
completion = self.mgr.apply_nfs(spec)
|
||||
orchestrator.raise_if_exception(completion)
|
||||
log.debug("Successfully deployed nfs daemons with cluster id %s and placement %s", cluster_id, placement)
|
||||
log.debug("Successfully deployed nfs daemons with cluster id %s and placement %s",
|
||||
cluster_id, placement)
|
||||
|
||||
def create_empty_rados_obj(self, cluster_id: str) -> None:
|
||||
common_conf = self._get_common_conf_obj_name(cluster_id)
|
||||
self._rados(cluster_id).write_obj('', self._get_common_conf_obj_name(cluster_id))
|
||||
common_conf = conf_obj_name(cluster_id)
|
||||
self._rados(cluster_id).write_obj('', conf_obj_name(cluster_id))
|
||||
log.info("Created empty object:%s", common_conf)
|
||||
|
||||
def delete_config_obj(self, cluster_id: str) -> None:
|
||||
self._rados(cluster_id).remove_all_obj()
|
||||
log.info("Deleted %s object and all objects in %s",
|
||||
self._get_common_conf_obj_name(cluster_id), cluster_id)
|
||||
conf_obj_name(cluster_id), cluster_id)
|
||||
|
||||
def create_nfs_cluster(
|
||||
self,
|
||||
@ -218,7 +214,7 @@ class NFSCluster:
|
||||
try:
|
||||
if cluster_id in available_clusters(self.mgr):
|
||||
rados_obj = self._rados(cluster_id)
|
||||
conf = rados_obj.read_obj(self._get_user_conf_obj_name(cluster_id))
|
||||
conf = rados_obj.read_obj(user_conf_obj_name(cluster_id))
|
||||
return 0, conf or "", ""
|
||||
raise ClusterNotFound()
|
||||
except Exception as e:
|
||||
@ -230,8 +226,8 @@ class NFSCluster:
|
||||
rados_obj = self._rados(cluster_id)
|
||||
if rados_obj.check_user_config():
|
||||
return 0, "", "NFS-Ganesha User Config already exists"
|
||||
rados_obj.write_obj(nfs_config, self._get_user_conf_obj_name(cluster_id),
|
||||
self._get_common_conf_obj_name(cluster_id))
|
||||
rados_obj.write_obj(nfs_config, user_conf_obj_name(cluster_id),
|
||||
conf_obj_name(cluster_id))
|
||||
log.debug("Successfully saved %s's user config: \n %s", cluster_id, nfs_config)
|
||||
restart_nfs_service(self.mgr, cluster_id)
|
||||
return 0, "NFS-Ganesha Config Set Successfully", ""
|
||||
@ -248,8 +244,8 @@ class NFSCluster:
|
||||
rados_obj = self._rados(cluster_id)
|
||||
if not rados_obj.check_user_config():
|
||||
return 0, "", "NFS-Ganesha User Config does not exist"
|
||||
rados_obj.remove_obj(self._get_user_conf_obj_name(cluster_id),
|
||||
self._get_common_conf_obj_name(cluster_id))
|
||||
rados_obj.remove_obj(user_conf_obj_name(cluster_id),
|
||||
conf_obj_name(cluster_id))
|
||||
restart_nfs_service(self.mgr, cluster_id)
|
||||
return 0, "NFS-Ganesha Config Reset Successfully", ""
|
||||
raise ClusterNotFound()
|
||||
|
@ -11,7 +11,14 @@ from mgr_module import NFS_POOL_NAME as POOL_NAME, NFS_GANESHA_SUPPORTED_FSALS
|
||||
from .export_utils import GaneshaConfParser, Export, RawBlock, CephFSFSAL, RGWFSAL
|
||||
from .exception import NFSException, NFSInvalidOperation, FSNotFound, \
|
||||
ClusterNotFound
|
||||
from .utils import available_clusters, check_fs, restart_nfs_service
|
||||
from .utils import (
|
||||
EXPORT_PREFIX,
|
||||
USER_CONF_PREFIX,
|
||||
export_obj_name,
|
||||
conf_obj_name,
|
||||
available_clusters,
|
||||
check_fs,
|
||||
restart_nfs_service)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nfs.module import Module
|
||||
@ -118,7 +125,7 @@ class NFSRados:
|
||||
with self.rados.open_ioctx(self.pool) as ioctx:
|
||||
ioctx.set_namespace(self.namespace)
|
||||
for obj in ioctx.list_objects():
|
||||
if obj.key.startswith("userconf-nfs"):
|
||||
if obj.key.startswith(USER_CONF_PREFIX):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -244,7 +251,7 @@ class ExportMgr:
|
||||
with self.mgr.rados.open_ioctx(self.rados_pool) as ioctx:
|
||||
ioctx.set_namespace(rados_namespace)
|
||||
for obj in ioctx.list_objects():
|
||||
if obj.key.startswith("export-"):
|
||||
if obj.key.startswith(EXPORT_PREFIX):
|
||||
size, _ = obj.stat()
|
||||
raw_config = obj.read(size)
|
||||
raw_config = raw_config.decode("utf-8")
|
||||
@ -258,8 +265,8 @@ class ExportMgr:
|
||||
self.exports[cluster_id].append(export)
|
||||
self._rados(cluster_id).write_obj(
|
||||
GaneshaConfParser.write_block(export.to_export_block()),
|
||||
f'export-{export.export_id}',
|
||||
f'conf-nfs.{export.cluster_id}'
|
||||
export_obj_name(export.export_id),
|
||||
conf_obj_name(export.cluster_id)
|
||||
)
|
||||
|
||||
def _delete_export(
|
||||
@ -278,7 +285,7 @@ class ExportMgr:
|
||||
if export:
|
||||
if pseudo_path:
|
||||
self._rados(cluster_id).remove_obj(
|
||||
f'export-{export.export_id}', f'conf-nfs.{cluster_id}')
|
||||
export_obj_name(export.export_id), conf_obj_name(cluster_id))
|
||||
self.exports[cluster_id].remove(export)
|
||||
self._delete_export_user(export)
|
||||
if not self.exports[cluster_id]:
|
||||
@ -295,7 +302,7 @@ class ExportMgr:
|
||||
ioctx.set_namespace(cluster_id)
|
||||
export = Export.from_export_block(
|
||||
GaneshaConfParser(
|
||||
ioctx.read(f"export-{ex_id}").decode("utf-8")
|
||||
ioctx.read(export_obj_name(ex_id)).decode("utf-8")
|
||||
).parse()[0],
|
||||
cluster_id
|
||||
)
|
||||
@ -308,7 +315,7 @@ class ExportMgr:
|
||||
self.exports[cluster_id].append(export)
|
||||
self._rados(cluster_id).update_obj(
|
||||
GaneshaConfParser.write_block(export.to_export_block()),
|
||||
f'export-{export.export_id}', f'conf-nfs.{export.cluster_id}')
|
||||
export_obj_name(export.export_id), conf_obj_name(export.cluster_id))
|
||||
|
||||
def format_path(self, path: str) -> str:
|
||||
if path:
|
||||
|
@ -5,6 +5,25 @@ import orchestrator
|
||||
if TYPE_CHECKING:
|
||||
from nfs.module import Module
|
||||
|
||||
EXPORT_PREFIX: str = "export-"
|
||||
CONF_PREFIX: str = "conf-nfs."
|
||||
USER_CONF_PREFIX: str = "userconf-nfs."
|
||||
|
||||
|
||||
def export_obj_name(export_id: int) -> str:
|
||||
"""Return a rados object name for the export."""
|
||||
return f"{EXPORT_PREFIX}{export_id}"
|
||||
|
||||
|
||||
def conf_obj_name(cluster_id: str) -> str:
|
||||
"""Return a rados object name for the config."""
|
||||
return f"{CONF_PREFIX}{cluster_id}"
|
||||
|
||||
|
||||
def user_conf_obj_name(cluster_id: str) -> str:
|
||||
"""Returna a rados object name for the user config."""
|
||||
return f"{USER_CONF_PREFIX}{cluster_id}"
|
||||
|
||||
|
||||
def available_clusters(mgr: 'Module') -> List[str]:
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user