Skip to content

Commit

Permalink
Merge pull request #57 from gboutry/feat/enable-horizon-plugins
Browse files Browse the repository at this point in the history
Enable horizon plugins on plugin enablement
  • Loading branch information
hemanthnakkina authored Nov 16, 2023
2 parents 1ec8ee2 + baa2abc commit 6f34360
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
6 changes: 5 additions & 1 deletion sunbeam-python/sunbeam/plugins/caas/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ def set_tfvars_on_enable(self) -> dict:
return {
"magnum-channel": "2023.2/edge",
"enable-magnum": True,
**self.add_horizon_plugin_to_tfvars("magnum"),
}

def set_tfvars_on_disable(self) -> dict:
"""Set terraform variables to disable the application."""
return {"enable-magnum": False}
return {
"enable-magnum": False,
**self.remove_horizon_plugin_from_tfvars("magnum"),
}

def set_tfvars_on_resize(self) -> dict:
"""Set terraform variables to resize the application."""
Expand Down
32 changes: 32 additions & 0 deletions sunbeam-python/sunbeam/plugins/interface/v1/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,38 @@ def disable_plugin(self) -> None:
"""Disable plugin command."""
super().disable_plugin()

def add_horizon_plugin_to_tfvars(self, plugin: str) -> dict[str, list[str]]:
"""Tf vars to have the given plugin enabled.
Return of the function is expected to be passed to set_tfvars_on_enable.
"""
try:
tfvars = read_config(self.client, self.get_tfvar_config_key())
except ConfigItemNotFoundException:
tfvars = {}

horizon_plugins = tfvars.get("horizon-plugins", [])
if plugin not in horizon_plugins:
horizon_plugins.append(plugin)

return {"horizon-plugins": sorted(horizon_plugins)}

def remove_horizon_plugin_from_tfvars(self, plugin: str) -> dict[str, list[str]]:
"""TF vars to have the given plugin disabled.
Return of the function is expected to be passed to set_tfvars_on_disable.
"""
try:
tfvars = read_config(self.client, self.get_tfvar_config_key())
except ConfigItemNotFoundException:
tfvars = {}

horizon_plugins = tfvars.get("horizon-plugins", [])
if plugin in horizon_plugins:
horizon_plugins.remove(plugin)

return {"horizon-plugins": sorted(horizon_plugins)}


class EnableOpenStackApplicationStep(BaseStep, JujuStepHelper):
"""Generic step to enable OpenStack application using Terraform"""
Expand Down
6 changes: 5 additions & 1 deletion sunbeam-python/sunbeam/plugins/loadbalancer/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ def set_tfvars_on_enable(self) -> dict:
return {
"octavia-channel": "2023.2/edge",
"enable-octavia": True,
**self.add_horizon_plugin_to_tfvars("octavia"),
}

def set_tfvars_on_disable(self) -> dict:
"""Set terraform variables to disable the application."""
return {"enable-octavia": False}
return {
"enable-octavia": False,
**self.remove_horizon_plugin_from_tfvars("octavia"),
}

def set_tfvars_on_resize(self) -> dict:
"""Set terraform variables to resize the application."""
Expand Down
6 changes: 5 additions & 1 deletion sunbeam-python/sunbeam/plugins/orchestration/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ def set_tfvars_on_enable(self) -> dict:
return {
"heat-channel": "2023.2/edge",
"enable-heat": True,
**self.add_horizon_plugin_to_tfvars("heat"),
}

def set_tfvars_on_disable(self) -> dict:
"""Set terraform variables to disable the application."""
return {"enable-heat": False}
return {
"enable-heat": False,
**self.remove_horizon_plugin_from_tfvars("heat"),
}

def set_tfvars_on_resize(self) -> dict:
"""Set terraform variables to resize the application."""
Expand Down

0 comments on commit 6f34360

Please sign in to comment.