-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt existing modules for "transitions"
Signed-off-by: Tobias Wolf <[email protected]>
- Loading branch information
1 parent
07be5c7
commit 61013ca
Showing
11 changed files
with
79 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# type: ignore | ||
|
||
from .main import AnalyzeCephHandler | ||
|
||
MODULE_NAME = "analyze_ceph" | ||
HANDLER_CLASS = AnalyzeCephHandler | ||
REQUIRES = [] | ||
AFTER = [] | ||
PREFLIGHT_REQUIRES = [] | ||
from .main import AnalyzeCephHandler as ModuleHandler # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ..module import ModuleHandler | ||
from typing import Any, Dict | ||
from ..machine import Machine | ||
from ..module import ModuleHandler | ||
|
||
|
||
class AnalyzeCephHandler(ModuleHandler): | ||
def run(self) -> Any: | ||
commands = ["mon dump", "osd dump", "device ls", "fs dump", "node ls"] | ||
|
||
results: Dict[str, Any] = dict() | ||
state = self.machine.get_state("AnalyzeCephHandler") | ||
state.data: Dict[str, Any] = {} # type: ignore | ||
|
||
for command in commands: | ||
parts = command.split(" ") | ||
leaf = results | ||
leaf = state.data | ||
for idx, part in enumerate(parts): | ||
if idx < len(parts) - 1: | ||
leaf[part] = dict() | ||
leaf[part] = {} | ||
else: | ||
leaf[part] = self.ceph.mon_command(command) | ||
leaf = leaf[part] | ||
|
||
self.logger.info("Dictionary created") | ||
results["ssh"] = dict() | ||
results["ssh"]["osd"] = dict() | ||
for node, values in results["node"]["ls"]["osd"].items(): | ||
self.logger.debug("AnalyzeCephHandler commands executed") | ||
|
||
state.data["ssh"] = {} | ||
state.data["ssh"]["osd"] = {} | ||
|
||
for node, values in state.data["node"]["ls"]["osd"].items(): | ||
devices = self.ssh.command(node, "find /dev/ceph-*/*").stdout.splitlines() | ||
results["ssh"]["osd"][node] = {"devices": devices} | ||
state.data["ssh"]["osd"][node] = {"devices": devices} | ||
|
||
self.logger.info("AnalyzeCephHandler ran successfully.") | ||
return results | ||
|
||
@classmethod | ||
def register_state( | ||
_, machine: Machine, config: Dict[str, Any], **kwargs: Any | ||
) -> None: | ||
""" | ||
Register state for transitions | ||
""" | ||
|
||
super().register_state(machine, config, tags=["data"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# type: ignore | ||
|
||
from .main import CephXAuthHandler | ||
|
||
MODULE_NAME = "cephx_auth_config" | ||
HANDLER_CLASS = CephXAuthHandler | ||
REQUIRES = [] | ||
AFTER = [] | ||
PREFLIGHT_REQUIRES = [] | ||
from .main import CephXAuthHandler as ModuleHandler # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ..module import ModuleHandler | ||
from typing import Any | ||
from typing import Any, Dict | ||
from ..machine import Machine | ||
from ..module import ModuleException, ModuleHandler | ||
|
||
|
||
class CephXAuthHandler(ModuleHandler): | ||
def run(self) -> Any: | ||
self.logger.debug("Reconfiguring Ceph to expect cephx auth") | ||
def preflight(self) -> Any: | ||
if not self.is_cephx_set(self.ceph.conf_get("auth_cluster_required")): | ||
raise ModuleException( | ||
"Ceph config value auth_cluster_required does not contain cephx" | ||
) | ||
|
||
self.ceph.conf_set("auth_cluster_required", "cephx") | ||
self.ceph.conf_set("auth_service_required", "cephx") | ||
self.ceph.conf_set("auth_client_required", "cephx") | ||
if not self.is_cephx_set(self.ceph.conf_get("auth_service_required")): | ||
raise ModuleException( | ||
"Ceph config value auth_service_required does not contain cephx" | ||
) | ||
|
||
self.logger.info("Reconfigured Ceph to expect cephx auth") | ||
return {"reconfigured": True} | ||
if not self.is_cephx_set(self.ceph.conf_get("auth_client_required")): | ||
raise ModuleException( | ||
"Ceph config value auth_client_required does not contain cephx" | ||
) | ||
|
||
self.machine.get_state("CephXAuthHandler").verified = True | ||
self.logger.info("Validated Ceph to expect cephx auth") | ||
|
||
def is_cephx_set(self, values: str) -> Any: | ||
return "cephx" in [value.strip() for value in values.split(",")] | ||
|
||
@classmethod | ||
def register_state( | ||
_, machine: Machine, config: Dict[str, Any], **kwargs: Any | ||
) -> None: | ||
""" | ||
Register state for transitions | ||
""" | ||
|
||
super().register_state(machine, config, tags=["verified"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# type: ignore | ||
|
||
from .main import ExampleHandler | ||
|
||
MODULE_NAME = "example" # Name of the module | ||
HANDLER_CLASS = ExampleHandler # Define the handler class for this module | ||
REQUIRES = [] # A list of modules that are required to run before this module. Modules in this list will be imported, even if they are not configured | ||
AFTER = [ | ||
"migrate_monitors" | ||
] # A list of modules that should be run before this module, if they are defined in config | ||
PREFLIGHT_REQUIRES = [ | ||
"analyze_ceph" | ||
] # A list of modules that are required to run the preflight_check of this module. Modules in this list will be imported and run in preflight stage. | ||
from .main import ExampleHandler as ModuleHandler # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# type: ignore | ||
|
||
from .main import MigrateMonitorsHandler | ||
|
||
MODULE_NAME = "migrate_monitors" | ||
HANDLER_CLASS = MigrateMonitorsHandler | ||
REQUIRES = [] | ||
AFTER = [] | ||
PREFLIGHT_REQUIRES = ["analyze_ceph"] | ||
from .main import MigrateMonitorsHandler as ModuleHandler # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ..module import ModuleHandler | ||
from typing import Dict, Any | ||
from ..module import ModuleHandler | ||
|
||
|
||
class MigrateMonitorsHandler(ModuleHandler): | ||
REQUIRES = ["analyze_ceph"] | ||
|
||
def run(self) -> Dict[str, Any]: | ||
self.logger.info("MigrateMonitorsHandler ran successfully.") | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# type: ignore | ||
|
||
from .main import MigrateOSDsHandler | ||
|
||
MODULE_NAME = "migrate_osds" | ||
HANDLER_CLASS = MigrateOSDsHandler | ||
REQUIRES = [] | ||
AFTER = ["migrate_monitors"] | ||
PREFLIGHT_REQUIRES = ["analyze_ceph"] | ||
from .main import MigrateOSDsHandler as ModuleHandler # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters