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:
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,
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,
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:
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", ""
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()
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
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
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")
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(
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]:
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
)
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:
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]:
'''