Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions sunbeam-python/sunbeam/commands/dashboard_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from rich.console import Console

from sunbeam.core import juju
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.checks import (
JujuLoginCheck,
VerifyBootstrappedCheck,
run_preflight_checks,
)
from sunbeam.core.deployment import Deployment
from sunbeam.core.openstack import OPENSTACK_MODEL

Expand Down Expand Up @@ -37,9 +41,12 @@ def retrieve_dashboard_url(jhelper: juju.JujuHelper) -> str:
def dashboard_url(ctx: click.Context) -> None:
"""Retrieve OpenStack Dashboard URL."""
deployment: Deployment = ctx.obj
preflight_checks = []
preflight_checks.append(VerifyBootstrappedCheck(deployment.get_client()))
preflight_checks = [
VerifyBootstrappedCheck(deployment.get_client()),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

jhelper = juju.JujuHelper(deployment.juju_controller)

with console.status("Retrieving dashboard URL from Horizon service ... "):
Expand Down
13 changes: 10 additions & 3 deletions sunbeam-python/sunbeam/commands/generate_cloud_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import sunbeam.core.questions
from sunbeam.clusterd.client import Client
from sunbeam.commands.configure import retrieve_admin_credentials
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.checks import (
JujuLoginCheck,
VerifyBootstrappedCheck,
run_preflight_checks,
)
from sunbeam.core.common import (
BaseStep,
Result,
Expand Down Expand Up @@ -250,9 +254,12 @@ def cloud_config(

deployment: Deployment = ctx.obj
client = deployment.get_client()
preflight_checks = []
preflight_checks.append(VerifyBootstrappedCheck(client))
preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

jhelper_keystone = deployment.get_juju_helper(keystone=True)
if not jhelper_keystone.model_exists(OPENSTACK_MODEL):
LOG.error(f"Expected model {OPENSTACK_MODEL} missing")
Expand Down
4 changes: 4 additions & 0 deletions sunbeam-python/sunbeam/commands/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from snaphelpers import Snap

from sunbeam.commands.configure import retrieve_admin_credentials
from sunbeam.core.checks import JujuLoginCheck, run_preflight_checks
from sunbeam.core.deployment import Deployment
from sunbeam.core.openstack import OPENSTACK_MODEL
from sunbeam.core.terraform import TerraformException
Expand Down Expand Up @@ -62,6 +63,9 @@ def launch(
if not compute_nodes:
raise click.ClickException("No compute role found. Cannot launch instance.")

# Login to the Juju controller
run_preflight_checks([JujuLoginCheck(deployment.juju_account)], console)

jhelper = deployment.get_juju_helper()
jhelper_keystone = deployment.get_juju_helper(keystone=True)

Expand Down
12 changes: 9 additions & 3 deletions sunbeam-python/sunbeam/commands/openrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from rich.console import Console

from sunbeam.commands.configure import retrieve_admin_credentials
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.checks import (
JujuLoginCheck,
VerifyBootstrappedCheck,
run_preflight_checks,
)
from sunbeam.core.deployment import Deployment
from sunbeam.core.openstack import OPENSTACK_MODEL

Expand All @@ -21,8 +25,10 @@ def openrc(ctx: click.Context) -> None:
"""Retrieve openrc for cloud admin account."""
deployment: Deployment = ctx.obj
client = deployment.get_client()
preflight_checks = []
preflight_checks.append(VerifyBootstrappedCheck(client))
preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

jhelper = deployment.get_juju_helper(keystone=True)
Expand Down
5 changes: 5 additions & 0 deletions sunbeam-python/sunbeam/commands/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from sunbeam.clusterd.service import ConfigItemNotFoundException
from sunbeam.commands.configure import retrieve_admin_credentials
from sunbeam.core.checks import JujuLoginCheck, run_preflight_checks
from sunbeam.core.common import (
FORMAT_TABLE,
FORMAT_YAML,
Expand Down Expand Up @@ -107,6 +108,10 @@ def shell_plan(ctx: click.Context, plan: str | None = None):
with the environment variables set for the specified plan.
"""
deployment: Deployment = ctx.obj

# Login to the Juju controller
run_preflight_checks([JujuLoginCheck(deployment.juju_account)], console)

jhelper_keystone = deployment.get_juju_helper(keystone=True)

with console.status("Fetching OS admin credentials..."):
Expand Down
11 changes: 9 additions & 2 deletions sunbeam-python/sunbeam/commands/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
ClusterServiceUnavailableException,
ConfigItemNotFoundException,
)
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.checks import (
JujuLoginCheck,
VerifyBootstrappedCheck,
run_preflight_checks,
)
from sunbeam.core.common import (
FORMAT_TABLE,
FORMAT_YAML,
Expand Down Expand Up @@ -65,7 +69,10 @@ def _preflight_checks(deployment: Deployment):
"completed succesfully. Please run `sunbeam cluster bootstrap`"
)
raise click.ClickException(message)
preflight_checks = [VerifyBootstrappedCheck(client)]
preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]

run_preflight_checks(preflight_checks, console)

Expand Down
15 changes: 15 additions & 0 deletions sunbeam-python/sunbeam/commands/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from snaphelpers import Snap

from sunbeam.clusterd.service import ManifestItemNotFoundException
from sunbeam.core.checks import JujuLoginCheck, run_preflight_checks
from sunbeam.core.common import (
ResultType,
RiskLevel,
Expand Down Expand Up @@ -126,6 +127,9 @@ def refresh(
deployment: Deployment = ctx.obj
client = deployment.get_client()

# Login to the Juju controller
run_preflight_checks([JujuLoginCheck(deployment.juju_account)], console)

if not manifest_path and not clear_manifest:
# Warn only when the snap channel risk has changed since the manifest
# was last stored (e.g. snap refreshed from stable to beta). We
Expand Down Expand Up @@ -168,7 +172,9 @@ def refresh(
manifest = deployment.get_manifest()

LOG.debug(f"Manifest used for deployment - core: {manifest.core}")

jhelper = JujuHelper(deployment.juju_controller)

upgrade_coordinator: UpgradeCoordinator
if upgrade_release:
upgrade_coordinator = ChannelUpgradeCoordinator(
Expand Down Expand Up @@ -209,6 +215,10 @@ def refresh_mysql(
"""Upgrade mysql-k8s charm to latest revision in channel."""
deployment: Deployment = ctx.obj
client = deployment.get_client()

# Login to the Juju controller
run_preflight_checks([JujuLoginCheck(deployment.juju_account)], console)

manifest = None
if manifest_path:
manifest = deployment.get_manifest(manifest_path)
Expand All @@ -230,6 +240,7 @@ def refresh_mysql(
)

jhelper = JujuHelper(deployment.juju_controller)

upgrade_coordinator = MySQLInChannelUpgradeCoordinator(
deployment, client, jhelper, manifest, reset_mysql_upgrade_state
)
Expand All @@ -255,6 +266,10 @@ def refresh_vault(
"""Upgrade vault-k8s charm to latest stable channel."""
deployment: Deployment = ctx.obj
client = deployment.get_client()

# Login to the Juju controller
run_preflight_checks([JujuLoginCheck(deployment.juju_account)], console)

jhelper = JujuHelper(deployment.juju_controller)

manifest = None
Expand Down
9 changes: 7 additions & 2 deletions sunbeam-python/sunbeam/commands/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rich.console import Console

from sunbeam.clusterd.client import Client
from sunbeam.core.checks import JujuLoginCheck, run_preflight_checks
from sunbeam.core.common import click_option_topology, run_plan
from sunbeam.core.deployment import Deployment
from sunbeam.core.juju import JujuHelper
Expand Down Expand Up @@ -46,18 +47,22 @@ def resize(
client: Client = deployment.get_client()
manifest = deployment.get_manifest()

# Login to the Juju controller
run_preflight_checks([JujuLoginCheck(deployment.juju_account)], console)

openstack_tfhelper = deployment.get_tfhelper("openstack-plan")
microceph_tfhelper = deployment.get_tfhelper("microceph-plan")
cinder_volume_tfhelper = deployment.get_tfhelper("cinder-volume-plan")
jhelper = JujuHelper(deployment.juju_controller)

storage_nodes = client.cluster.list_nodes_by_role("storage")

parameter_source = click.get_current_context().get_parameter_source("force")
if parameter_source == ParameterSource.COMMANDLINE:
LOG.warning("WARNING: Option --force is deprecated and the value is ignored.")

plan = []
jhelper = JujuHelper(deployment.juju_controller)

plan: list = []
if len(storage_nodes):
# Change default-pool-size based on number of storage nodes
plan.extend(
Expand Down
51 changes: 42 additions & 9 deletions sunbeam-python/sunbeam/commands/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from rich.table import Table

from sunbeam.clusterd.service import ConfigItemNotFoundException
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.checks import (
JujuLoginCheck,
VerifyBootstrappedCheck,
run_preflight_checks,
)
from sunbeam.core.common import (
FORMAT_TABLE,
FORMAT_YAML,
Expand Down Expand Up @@ -146,9 +150,12 @@ def add_sso(
) -> None:
"""Add a new identity provider."""
deployment: Deployment = ctx.obj

client = deployment.get_client()
preflight_checks = [VerifyBootstrappedCheck(client)]

preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

cfg = safe_get_sso_config(client)
Expand Down Expand Up @@ -219,8 +226,13 @@ def remove_sso(
"""Remove an identity provider."""
deployment: Deployment = ctx.obj
client = deployment.get_client()
preflight_checks = [VerifyBootstrappedCheck(client)]

preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

cfg = safe_get_sso_config(client)

provider = cfg.get(protocol, {}).get(name)
Expand All @@ -233,6 +245,7 @@ def remove_sso(
click.confirm(msg, abort=True)

jhelper = JujuHelper(deployment.juju_controller)

plan: list[BaseStep] = [
TerraformInitStep(deployment.get_tfhelper("openstack-plan")),
]
Expand Down Expand Up @@ -287,8 +300,13 @@ def update_sso(
"""Update identity provider (openid only)."""
deployment: Deployment = ctx.obj
client = deployment.get_client()
preflight_checks = [VerifyBootstrappedCheck(client)]

preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

try:
cfg = read_config(client, SSO_CONFIG_KEY)
except ConfigItemNotFoundException:
Expand All @@ -309,6 +327,7 @@ def update_sso(
raise click.ClickException(f"Invalid config supplied: {e}")

jhelper = JujuHelper(deployment.juju_controller)

plan = [
TerraformInitStep(deployment.get_tfhelper("openstack-plan")),
UpdateExternalProviderStep(
Expand All @@ -328,6 +347,10 @@ def update_sso(
def get_openid_redirect_uri(ctx: click.Context):
"""Get the OpenID redirect URI."""
deployment: Deployment = ctx.obj

# Login to the Juju controller
run_preflight_checks([JujuLoginCheck(deployment.juju_account)], console)

jhelper = JujuHelper(deployment.juju_controller)
app = "keystone"
action_cmd = "get-admin-account"
Expand Down Expand Up @@ -365,11 +388,16 @@ def purge_sso(
) -> None:
"""Remove all identity providers."""
deployment: Deployment = ctx.obj
jhelper = JujuHelper(deployment.juju_controller)
client = deployment.get_client()
preflight_checks = [VerifyBootstrappedCheck(client)]

preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

jhelper = JujuHelper(deployment.juju_controller)

config = safe_get_sso_config(client)
if not yes_i_mean_it and any(config.values()):
msg = (
Expand Down Expand Up @@ -425,12 +453,17 @@ def set_saml_x509(
) -> None:
"""Set Keystone SAML x509 SP certificate and key."""
deployment: Deployment = ctx.obj
jhelper = JujuHelper(deployment.juju_controller)
client = deployment.get_client()
tfhelper = deployment.get_tfhelper("openstack-plan")
preflight_checks = [VerifyBootstrappedCheck(client)]

preflight_checks = [
VerifyBootstrappedCheck(client),
JujuLoginCheck(deployment.juju_account),
]
run_preflight_checks(preflight_checks, console)

jhelper = JujuHelper(deployment.juju_controller)

run_plan(
[
TerraformInitStep(deployment.get_tfhelper("openstack-plan")),
Expand Down
Loading
Loading