Skip to content

Commit

Permalink
fix: adapt example to have corret config path, add typing, add
Browse files Browse the repository at this point in the history
rudimentary makefile command to download config from testbed

Signed-off-by: Rafael te Boekhorst <[email protected]>
  • Loading branch information
boekhorstb1 committed Mar 27, 2024
1 parent 81e54f5 commit 18b306a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ run-local-rookify: ## Runs rookify in the local development environment (require
$(eval PYTHONPATH="${PYTHONPATH}:$(pwd)/src")
source ./.venv/bin/activate && \
cd src && python3 -m rookify

download-ceph-folder-from-testbed:
ssh testbed-node-0 'sudo cp -r /etc/ceph ~/ceph_configs && sudo chown -R $$USER:$$USER ~/ceph_configs'
scp -r testbed-node-0:ceph_configs ./.ceph
ssh testbed-node-0 'rm -rf ~/ceph_configs'
2 changes: 1 addition & 1 deletion src/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ logging:
renderer: console # or: json

ceph:
conf_file: ../.ceph/ceph.conf
config: ../.ceph/ceph.conf
keyring: ../.ceph/ceph.client.admin.keyring

ssh:
Expand Down
41 changes: 27 additions & 14 deletions src/rookify/logger.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
import structlog
import logging

def configure_logging(config):
LOG_LEVEL = getattr(logging, config['logging']['level'])
LOG_TIME_FORMAT = config['logging']['format']['time']
LOG_RENDERER = config['logging']['format']['renderer']
from typing import Any, Dict


def configure_logging(config: Dict[str, Any]) -> None:
LOG_LEVEL = getattr(logging, config["logging"]["level"])
LOG_TIME_FORMAT = config["logging"]["format"]["time"]
LOG_RENDERER = config["logging"]["format"]["renderer"]
structlog.configure(
wrapper_class=structlog.make_filtering_bound_logger(LOG_LEVEL),
processors=[
structlog.processors.TimeStamper(fmt=LOG_TIME_FORMAT),
structlog.processors.add_log_level,
],
)
if LOG_RENDERER == "console":
structlog.configure(
processors=[
*structlog.get_config()["processors"],
structlog.dev.ConsoleRenderer(),
]
)
else:
structlog.configure(
wrapper_class=structlog.make_filtering_bound_logger(LOG_LEVEL),
processors=[
structlog.processors.TimeStamper(fmt=LOG_TIME_FORMAT),
structlog.processors.add_log_level
*structlog.get_config()["processors"],
structlog.processors.JSONRenderer(),
]
)
if LOG_RENDERER == "console":
structlog.configure(processors=[*structlog.get_config()["processors"], structlog.dev.ConsoleRenderer()])
else:
structlog.configure(processors=[*structlog.get_config()["processors"], structlog.processors.JSONRenderer()])

def getLogger():


def getLogger() -> structlog.getLogger:
return structlog.get_logger()

2 changes: 2 additions & 0 deletions src/rookify/modules/analyze_ceph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from rookify.logger import getLogger


class AnalyzeCephHandler(ModuleHandler):
def run(self) -> Any:
commands = ["mon dump", "osd dump", "device ls", "fs dump", "node ls"]
Expand All @@ -22,6 +23,7 @@ def run(self) -> Any:
leaf[part] = self.ceph.mon_command(command)
leaf = leaf[part]

log.info("Dictionary created")
results["ssh"] = dict()
results["ssh"]["osd"] = dict()
for node, values in results["node"]["ls"]["osd"].items():
Expand Down
4 changes: 3 additions & 1 deletion src/rookify/modules/migrate_osds/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

from rookify.logger import getLogger


class MigrateOSDsHandler(ModuleHandler):
def preflight(self) -> None:
pass
# result = self.ceph.mon_command("osd dump")
# raise ModuleException('test error')

def run(self) -> Any:
log = getLogger()
osd_config: Dict[str, Any] = dict()
for node, osds in self._data["analyze_ceph"]["node"]["ls"]["osd"].items():
osd_config[node] = {"osds": {}}
Expand All @@ -35,5 +37,5 @@ def run(self) -> Any:
osd["device"] = device
break

print(osd_config)
log.info(osd_config)
return {}

0 comments on commit 18b306a

Please sign in to comment.