Apply Juju SDK class layout style
The class layout style can be found in the official style guide [1]
[1]: https://juju.is/docs/sdk/styleguide#heading--class-layout
Change-Id: I325c8a3dd6666de6605612bd1120e861d8ba327c
diff --git a/src/charm.py b/src/charm.py
index fa22157..6e4fb2e 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -63,30 +63,6 @@
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- def _check_for_config_errors(self, config):
- missing = []
- for mandatory in self.MANDATORY_CONFIG:
- if mandatory not in config:
- missing.append(mandatory)
-
- if missing:
- return f"Mandatory options are missing: {', '.join(missing)}"
-
- if config["protocol"] not in ["block", "iscsi"]:
- return (
- f"""Invalid 'protocol' option provided: '{config["protocol"]}';"""
- "valid are 'block' and 'iscsi'"
- )
-
- if config["protocol"] == "block":
- return "'protocol' value 'block' not yet supported"
-
- if not (0 < config["sp-api-http-port"] < 65536):
- return (
- f"""'sp-api-http-port' ('{config["sp-api-http-port"]}')"""
- "is not a valid port (0-65535)"
- )
-
def on_config(self, event):
config = dict(self.framework.model.config)
conf_error = self._check_for_config_errors(config)
@@ -97,7 +73,7 @@
return
- self.create_storpool_conf(StorPoolConfItems.from_config(config))
+ create_storpool_conf(StorPoolConfItems.from_config(config))
super().on_config(event)
@@ -134,19 +110,35 @@
]
)
- self.create_storpool_conf(StorPoolConfItems.from_config(config))
+ create_storpool_conf(StorPoolConfItems.from_config(config))
self._stored.is_started = True
return options
- @staticmethod
- def create_storpool_conf(sp_conf_items: StorPoolConfItems):
- pathlib.Path("/etc/storpool.conf").write_text(
- "# Do not edit; this file is generated by the cinder-storpool charm.\n"
- + sp_conf_items.to_ini_key_value_pairs(),
- encoding="UTF-8",
- )
+ def _check_for_config_errors(self, config):
+ missing = []
+ for mandatory in self.MANDATORY_CONFIG:
+ if mandatory not in config:
+ missing.append(mandatory)
+
+ if missing:
+ return f"Mandatory options are missing: {', '.join(missing)}"
+
+ if config["protocol"] not in ["block", "iscsi"]:
+ return (
+ f"""Invalid 'protocol' option provided: '{config["protocol"]}';"""
+ "valid are 'block' and 'iscsi'"
+ )
+
+ if config["protocol"] == "block":
+ return "'protocol' value 'block' not yet supported"
+
+ if not (0 < config["sp-api-http-port"] < 65536):
+ return (
+ f"""'sp-api-http-port' ('{config["sp-api-http-port"]}')"""
+ "is not a valid port (0-65535)"
+ )
@charm_class
@@ -154,6 +146,14 @@
release = "yoga"
+def create_storpool_conf(sp_conf_items: StorPoolConfItems):
+ pathlib.Path("/etc/storpool.conf").write_text(
+ "# Do not edit; this file is generated by the cinder-storpool charm.\n"
+ + sp_conf_items.to_ini_key_value_pairs(),
+ encoding="UTF-8",
+ )
+
+
if __name__ == "__main__":
# main(get_charm_class_for_release())
# main(CinderStorPoolCharm)