Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit d75e8ad

Browse files
Support creating the OSISM configuration after successful migration
Fixes: #91 Signed-off-by: Tobias Wolf <[email protected]>
1 parent 4e0dfac commit d75e8ad

File tree

7 files changed

+171
-6
lines changed

7 files changed

+171
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ cython_debug/
8888
# Project specific
8989
data.pickle
9090
config.yaml
91+
osism_configuration.yaml
92+
osism_images.yaml
93+
osism_secrets.yaml
9194
.ceph
9295
.k8s
9396
.ssh

config.example.osism.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,4 @@ rook:
4242

4343
migration_modules:
4444
- example
45-
- migrate_osds
46-
- migrate_osd_pools
47-
- migrate_mds
48-
- migrate_mds_pools
49-
- migrate_rgws
50-
- migrate_rgw_pools
45+
- osism_configuration
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .main import OSISMConfigurationHandler as ModuleHandler # noqa
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
from os import path
5+
from typing import Dict
6+
from ..exception import ModuleException
7+
from ..module import ModuleHandler
8+
9+
10+
class OSISMConfigurationHandler(ModuleHandler):
11+
CONFIGURATION_FILE_NAME = "osism_configuration.yaml"
12+
IMAGES_FILE_NAME = "osism_images.yaml"
13+
14+
REQUIRES = [
15+
"migrate_mons",
16+
"migrate_osds",
17+
"migrate_osd_pools",
18+
"migrate_mds",
19+
"migrate_mds_pools",
20+
"migrate_mgrs",
21+
"migrate_rgws",
22+
"migrate_rgw_pools",
23+
]
24+
25+
OSISM_CONFIGURATION_FILE_LOCATION = (
26+
"/opt/configuration/environments/rook/configuration.yml"
27+
)
28+
29+
OSISM_IMAGES_FILE_LOCATION = "/opt/configuration/environments/rook/images.yml"
30+
OSISM_SECRETS_FILE_LOCATION = "/opt/configuration/environments/rook/secrets.yml"
31+
SECRETS_FILE_NAME = "osism_secrets.yaml"
32+
33+
def preflight(self) -> None:
34+
if not os.access("./", os.W_OK):
35+
raise ModuleException(
36+
"OSISM configuration can not be written to the current working directory: {0}".format(
37+
path.abspath("./")
38+
)
39+
)
40+
41+
def execute(self) -> None:
42+
self._write_configuration_yaml()
43+
self._write_images_yaml()
44+
self._write_secrets_yaml()
45+
46+
def get_readable_key_value_state(self) -> Dict[str, str]:
47+
return {"OSISM configuration path": path.abspath("./")}
48+
49+
def _write_configuration_yaml(self) -> None:
50+
analyze_ceph_data = self.machine.get_preflight_state("AnalyzeCephHandler").data
51+
rook_config = self._config["rook"]
52+
53+
(rook_ceph_repository, rook_ceph_version) = rook_config["ceph"]["image"].split(
54+
":", 1
55+
)
56+
osd_hosts_list = [
57+
{"name": osd_host}
58+
for osd_host in analyze_ceph_data["node"]["ls"]["osd"].keys()
59+
]
60+
61+
create_rook_cluster_data = self.machine.get_preflight_state(
62+
"CreateRookClusterHandler"
63+
)
64+
65+
configuration_values = {
66+
"ceph_repository": rook_ceph_repository,
67+
"ceph_version": rook_ceph_version,
68+
"cluster_name": rook_config["cluster"]["name"],
69+
"cluster_namespace": rook_config["cluster"]["namespace"],
70+
"osd_hosts_list": osd_hosts_list,
71+
"mon_count": create_rook_cluster_data.mon_count,
72+
"mgr_count": create_rook_cluster_data.mgr_count,
73+
"mds_count": len(analyze_ceph_data["node"]["ls"]["mds"]),
74+
}
75+
76+
if len(rook_config["ceph"].get("public_network", "")) > 0:
77+
configuration_values["public_network"] = rook_config["ceph"][
78+
"public_network"
79+
]
80+
else:
81+
self.logger.warn(
82+
"Rook Ceph cluster will be configured without a public network and determine it automatically during runtime"
83+
)
84+
85+
if len(rook_config["ceph"].get("cluster_network", "")) > 0:
86+
configuration_values["cluster_network"] = rook_config["ceph"][
87+
"cluster_network"
88+
]
89+
else:
90+
self.logger.info(
91+
"Rook Ceph cluster will be configured without a cluster network"
92+
)
93+
94+
# Render cluster config from template
95+
configuration = self.load_template(
96+
"configuration.yaml.j2", **configuration_values
97+
)
98+
99+
with open(OSISMConfigurationHandler.CONFIGURATION_FILE_NAME, "w") as fp:
100+
fp.write(configuration.raw)
101+
102+
self.logger.info(
103+
"Generated '{0}' to be copied to '{1}'".format(
104+
OSISMConfigurationHandler.CONFIGURATION_FILE_NAME,
105+
OSISMConfigurationHandler.OSISM_CONFIGURATION_FILE_LOCATION,
106+
)
107+
)
108+
109+
def _write_images_yaml(self) -> None:
110+
# Render cluster config from template
111+
images = self.load_template("images.yaml.j2")
112+
113+
with open(OSISMConfigurationHandler.IMAGES_FILE_NAME, "w") as fp:
114+
fp.write(images.raw)
115+
116+
self.logger.info(
117+
"Generated '{0}' to be copied to '{1}'".format(
118+
OSISMConfigurationHandler.IMAGES_FILE_NAME,
119+
OSISMConfigurationHandler.OSISM_IMAGES_FILE_LOCATION,
120+
)
121+
)
122+
123+
def _write_secrets_yaml(self) -> None:
124+
# Render cluster config from template
125+
secrets = self.load_template("secrets.yaml.j2")
126+
127+
with open(OSISMConfigurationHandler.SECRETS_FILE_NAME, "w") as fp:
128+
fp.write(secrets.raw)
129+
130+
self.logger.info(
131+
"Generated '{0}' to be copied to '{1}'".format(
132+
OSISMConfigurationHandler.SECRETS_FILE_NAME,
133+
OSISMConfigurationHandler.OSISM_SECRETS_FILE_LOCATION,
134+
)
135+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
rook_cluster_name: "{{ cluster_name }}"
3+
rook_ceph_cluster_helm_release_name: "{{ cluster_name }}"
4+
rook_ceph_cluster_helm_release_namespace: "{{ cluster_namespace }}"
5+
rook_ceph_image: "{{ ceph_repository }}"
6+
rook_ceph_image_tag: "{{ ceph_version }}"
7+
8+
{% if public_network is defined %}
9+
rook_network_public: "{{ public_network }}"
10+
{% endif %}
11+
12+
{% if cluster_network is defined %}
13+
rook_network_cluster: "{{ cluster_network }}"
14+
{% endif %}
15+
16+
rook_storage_devicefilter: "^sd[b-c]"
17+
rook_storage_nodes: {{ osd_hosts_list }}
18+
19+
rook_mon_count: {{ mon_count }}
20+
rook_mds_count: {{ mds_count }}
21+
rook_mgr_count: {{ mgr_count }}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
# Dummy variable to avoid error because ansible does not recognize the
3+
# file as a good configuration file when no variable in it.
4+
dummy:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
# Dummy variable to avoid error because ansible does not recognize the
3+
# file as a good configuration file when no variable in it.
4+
dummy:

0 commit comments

Comments
 (0)