Skip to content

Commit

Permalink
Add docstring and cleanup for Juju plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelThamm committed Nov 18, 2024
1 parent f389bfa commit 04fc3ce
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions sos/report/plugins/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@


class Juju(Plugin, UbuntuPlugin):
"""The Juju plugin is aimed at collecting Juju-related logs,
configurations, and controller/model state(s).
Logs and agent configuration information (/var/log/juju and /var/lib/juju)
is collected by default since these are useful for troubleshooting.
The Juju state collection is disabled by default and can be enabled with the
'juju-state' option. Collecting Juju state is safe in theory, but it does act
on the live controller(s)/model(s) and is therefore optional.
The default Juju state collection collects all controllers and models that the
'juju-user' (default=ubuntu) has access to.
Specific controllers or models can be collected using the 'controllers' and 'models' options.
Important: The string list is whitespace delimited, NOT colon delimited (sos plugin standard).
This is due to the underlying Juju CLI accepting specific models in the format 'controller:model' and
whitespaces are not allowed in either controller and model names.
Example: models="controller_a:model_x controller_b:model_y"
"""

short_desc = 'Juju orchestration tool'

Expand All @@ -35,19 +55,19 @@ class Juju(Plugin, UbuntuPlugin):
"juju-user",
default="ubuntu",
val_type=str,
desc="Juju client user",
desc="Juju client user.",
),
PluginOpt(
"controllers",
default="",
val_type=str,
desc="collect for specified Juju controllers",
desc="Collect Juju state for specified controllers. Uses a whitespace delimited list.",
),
PluginOpt(
"models",
default="",
val_type=str,
desc="collect for specified Juju models",
desc="Collect Juju state for specified models. Uses a whitespace delimited list.",
),
]

Expand Down Expand Up @@ -127,7 +147,7 @@ def setup(self):
if self.get_option("models"):
for model in self.get_option("models").split(" "):
command = f"juju status -m {model} --format=json"
self.collect_cmd_output(command, runas=juju_user)
self.add_cmd_output(command, runas=juju_user)

# All controllers and all models OR specific controllers and all
# models for each
Expand All @@ -145,7 +165,7 @@ def setup(self):
f"juju status -m {controller}:{short_name} "
f"--format=json"
)
self.collect_cmd_output(command, runas=juju_user)
self.add_cmd_output(command, runas=juju_user)

def postproc(self):
agents_path = "/var/lib/juju/agents/*"
Expand Down

0 comments on commit 04fc3ce

Please sign in to comment.