Export,
GaneshaConfParser,
RGWFSAL,
- RawBlock)
+ RawBlock,
+ format_block)
from .exception import NFSException, NFSInvalidOperation, FSNotFound
from .utils import (
CONF_PREFIX,
self.pool, self.namespace, obj)
# Add created obj url to common config obj
- ioctx.append(config_obj, GaneshaConfParser.write_block(
+ ioctx.append(config_obj, format_block(
self._create_url_block(obj)).encode('utf-8'))
_check_rados_notify(ioctx, config_obj)
log.debug("Added %s url to %s", obj, config_obj)
def _save_export(self, cluster_id: str, export: Export) -> None:
self.exports[cluster_id].append(export)
self._rados(cluster_id).write_obj(
- GaneshaConfParser.write_block(export.to_export_block()),
+ format_block(export.to_export_block()),
export_obj_name(export.export_id),
conf_obj_name(export.cluster_id)
)
need_nfs_service_restart: bool) -> None:
self.exports[cluster_id].append(export)
self._rados(cluster_id).update_obj(
- GaneshaConfParser.write_block(export.to_export_block()),
+ format_block(export.to_export_block()),
export_obj_name(export.export_id), conf_obj_name(export.cluster_id),
should_notify=not need_nfs_service_restart)
if need_nfs_service_restart:
blocks.append(self.parse_block_or_section())
return blocks
- @staticmethod
- def write_block_body(block: RawBlock, depth: int = 0) -> str:
- conf_str = ""
- for blo in block.blocks:
- conf_str += GaneshaConfParser.write_block(blo, depth)
-
- for key, val in block.values.items():
- if val is not None:
- conf_str += _indentation(depth)
- fval = _format_val(block.block_name, key, val)
- conf_str += '{} = {};\n'.format(key, fval)
- return conf_str
-
- @staticmethod
- def write_block(block: RawBlock, depth: int = 0) -> str:
- if block.block_name == "%url":
- return '%url "{}"\n\n'.format(block.values['value'])
-
- conf_str = ""
- conf_str += _indentation(depth)
- conf_str += format(block.block_name)
- conf_str += " {\n"
- conf_str += GaneshaConfParser.write_block_body(block, depth + 1)
- conf_str += _indentation(depth)
- conf_str += "}\n"
- return conf_str
-
class FSAL(object):
def __init__(self, name: str) -> None:
if not isinstance(other, Export):
return False
return self.to_dict() == other.to_dict()
+
+
+def _format_block_body(block: RawBlock, depth: int = 0) -> str:
+ conf_str = ""
+ for blo in block.blocks:
+ conf_str += format_block(blo, depth)
+
+ for key, val in block.values.items():
+ if val is not None:
+ conf_str += _indentation(depth)
+ fval = _format_val(block.block_name, key, val)
+ conf_str += '{} = {};\n'.format(key, fval)
+ return conf_str
+
+
+def format_block(block: RawBlock, depth: int = 0) -> str:
+ """Format a raw block object into text suitable as a ganesha configuration
+ block.
+ """
+ if block.block_name == "%url":
+ return '%url "{}"\n\n'.format(block.values['value'])
+
+ conf_str = ""
+ conf_str += _indentation(depth)
+ conf_str += format(block.block_name)
+ conf_str += " {\n"
+ conf_str += _format_block_body(block, depth + 1)
+ conf_str += _indentation(depth)
+ conf_str += "}\n"
+ return conf_str