Skip to content

Commit

Permalink
Merge pull request #319 from gboutry/refactor/package-structure
Browse files Browse the repository at this point in the history
Refactor package structure
  • Loading branch information
hemanthnakkina authored Aug 27, 2024
2 parents 6d07915 + 371bac0 commit 1ae478d
Show file tree
Hide file tree
Showing 101 changed files with 1,157 additions and 1,122 deletions.
72 changes: 36 additions & 36 deletions sunbeam-python/sunbeam/commands/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
import click
from rich.console import Console

import sunbeam.jobs.questions
import sunbeam.core.questions
from sunbeam import utils
from sunbeam.clusterd.client import Client
from sunbeam.commands.terraform import (
TerraformException,
TerraformHelper,
TerraformInitStep,
)
from sunbeam.jobs.common import BaseStep, Result, ResultType, Status
from sunbeam.jobs.juju import (
from sunbeam.core.common import BaseStep, Result, ResultType, Status
from sunbeam.core.juju import (
ActionFailedException,
JujuHelper,
LeaderNotFoundException,
run_sync,
)
from sunbeam.core.terraform import (
TerraformException,
TerraformHelper,
TerraformInitStep,
)

CLOUD_CONFIG_SECTION = "CloudConfig"
LOG = logging.getLogger(__name__)
Expand All @@ -44,31 +44,31 @@

def user_questions():
return {
"run_demo_setup": sunbeam.jobs.questions.ConfirmQuestion(
"run_demo_setup": sunbeam.core.questions.ConfirmQuestion(
"Populate OpenStack cloud with demo user, default images, flavors etc",
default_value=True,
),
"username": sunbeam.jobs.questions.PromptQuestion(
"username": sunbeam.core.questions.PromptQuestion(
"Username to use for access to OpenStack", default_value="demo"
),
"password": sunbeam.jobs.questions.PasswordPromptQuestion(
"password": sunbeam.core.questions.PasswordPromptQuestion(
"Password to use for access to OpenStack",
default_function=utils.generate_password,
password=True,
),
"cidr": sunbeam.jobs.questions.PromptQuestion(
"cidr": sunbeam.core.questions.PromptQuestion(
"Network range to use for project network",
default_value="192.168.122.0/24",
validation_function=ipaddress.ip_network,
),
"nameservers": sunbeam.jobs.questions.PromptQuestion(
"nameservers": sunbeam.core.questions.PromptQuestion(
"List of nameservers guests should use for DNS resolution",
default_function=lambda: " ".join(utils.get_nameservers()),
),
"security_group_rules": sunbeam.jobs.questions.ConfirmQuestion(
"security_group_rules": sunbeam.core.questions.ConfirmQuestion(
"Enable ping and SSH access to instances?", default_value=True
),
"remote_access_location": sunbeam.jobs.questions.PromptQuestion(
"remote_access_location": sunbeam.core.questions.PromptQuestion(
"Local or remote access to VMs",
choices=[utils.LOCAL_ACCESS, utils.REMOTE_ACCESS],
default_value=utils.LOCAL_ACCESS,
Expand All @@ -78,63 +78,63 @@ def user_questions():

def ext_net_questions():
return {
"cidr": sunbeam.jobs.questions.PromptQuestion(
"cidr": sunbeam.core.questions.PromptQuestion(
"CIDR of network to use for external networking",
default_value="10.20.20.0/24",
validation_function=ipaddress.ip_network,
),
"gateway": sunbeam.jobs.questions.PromptQuestion(
"gateway": sunbeam.core.questions.PromptQuestion(
"IP address of default gateway for external network",
default_value=None,
validation_function=ipaddress.ip_address,
),
"start": sunbeam.jobs.questions.PromptQuestion(
"start": sunbeam.core.questions.PromptQuestion(
"Start of IP allocation range for external network",
default_value=None,
validation_function=ipaddress.ip_address,
),
"end": sunbeam.jobs.questions.PromptQuestion(
"end": sunbeam.core.questions.PromptQuestion(
"End of IP allocation range for external network",
default_value=None,
validation_function=ipaddress.ip_address,
),
"network_type": sunbeam.jobs.questions.PromptQuestion(
"network_type": sunbeam.core.questions.PromptQuestion(
"Network type for access to external network",
choices=["flat", "vlan"],
default_value="flat",
),
"segmentation_id": sunbeam.jobs.questions.PromptQuestion(
"segmentation_id": sunbeam.core.questions.PromptQuestion(
"VLAN ID to use for external network", default_value=0
),
}


def ext_net_questions_local_only():
return {
"cidr": sunbeam.jobs.questions.PromptQuestion(
"cidr": sunbeam.core.questions.PromptQuestion(
(
"CIDR of OpenStack external network - arbitrary but must not "
"be in use"
),
default_value="10.20.20.0/24",
validation_function=ipaddress.ip_network,
),
"start": sunbeam.jobs.questions.PromptQuestion(
"start": sunbeam.core.questions.PromptQuestion(
"Start of IP allocation range for external network",
default_value=None,
validation_function=ipaddress.ip_address,
),
"end": sunbeam.jobs.questions.PromptQuestion(
"end": sunbeam.core.questions.PromptQuestion(
"End of IP allocation range for external network",
default_value=None,
validation_function=ipaddress.ip_address,
),
"network_type": sunbeam.jobs.questions.PromptQuestion(
"network_type": sunbeam.core.questions.PromptQuestion(
"Network type for access to external network",
choices=["flat", "vlan"],
default_value="flat",
),
"segmentation_id": sunbeam.jobs.questions.PromptQuestion(
"segmentation_id": sunbeam.core.questions.PromptQuestion(
"VLAN ID to use for external network", default_value=0
),
}
Expand Down Expand Up @@ -268,7 +268,7 @@ def run(self, status: Status | None = None) -> Result:
:return:
"""
self.variables = sunbeam.jobs.questions.load_answers(
self.variables = sunbeam.core.questions.load_answers(
self.client, CLOUD_CONFIG_SECTION
)
self.ext_network = self.variables.get("external_network", {})
Expand Down Expand Up @@ -333,7 +333,7 @@ def is_skip(self, status: Status | None = None) -> Result:
:return: ResultType.SKIPPED if the Step should be skipped,
ResultType.COMPLETED or ResultType.FAILED otherwise
"""
self.variables = sunbeam.jobs.questions.load_answers(
self.variables = sunbeam.core.questions.load_answers(
self.client, CLOUD_CONFIG_SECTION
)
if "user" not in self.variables:
Expand Down Expand Up @@ -409,14 +409,14 @@ def prompt(self, console: Console | None = None) -> None:
:param console: the console to prompt on
:type console: rich.console.Console (Optional)
"""
self.variables = sunbeam.jobs.questions.load_answers(
self.variables = sunbeam.core.questions.load_answers(
self.client, CLOUD_CONFIG_SECTION
)
for section in ["user", "external_network"]:
if not self.variables.get(section):
self.variables[section] = {}

user_bank = sunbeam.jobs.questions.QuestionBank(
user_bank = sunbeam.core.questions.QuestionBank(
questions=user_questions(),
console=console,
preseed=self.preseed.get("user"),
Expand All @@ -428,15 +428,15 @@ def prompt(self, console: Console | None = None) -> None:
)
# External Network Configuration
if self.variables["user"]["remote_access_location"] == utils.LOCAL_ACCESS:
ext_net_bank = sunbeam.jobs.questions.QuestionBank(
ext_net_bank = sunbeam.core.questions.QuestionBank(
questions=ext_net_questions_local_only(),
console=console,
preseed=self.preseed.get("external_network"),
previous_answers=self.variables.get("external_network"),
accept_defaults=self.accept_defaults,
)
else:
ext_net_bank = sunbeam.jobs.questions.QuestionBank(
ext_net_bank = sunbeam.core.questions.QuestionBank(
questions=ext_net_questions(),
console=console,
preseed=self.preseed.get("external_network"),
Expand Down Expand Up @@ -499,7 +499,7 @@ def prompt(self, console: Console | None = None) -> None:
user_bank.security_group_rules.ask()
)

sunbeam.jobs.questions.write_answers(
sunbeam.core.questions.write_answers(
self.client, CLOUD_CONFIG_SECTION, self.variables
)

Expand Down Expand Up @@ -531,7 +531,7 @@ def is_skip(self, status: Status | None = None) -> Result:
:return: ResultType.SKIPPED if the Step should be skipped,
ResultType.COMPLETED or ResultType.FAILED otherwise
"""
self.variables = sunbeam.jobs.questions.load_answers(
self.variables = sunbeam.core.questions.load_answers(
self.client, CLOUD_CONFIG_SECTION
)
if self.variables["user"]["run_demo_setup"]:
Expand All @@ -541,7 +541,7 @@ def is_skip(self, status: Status | None = None) -> Result:

def run(self, status: Status | None = None) -> Result:
"""Execute configuration using terraform."""
self.variables = sunbeam.jobs.questions.load_answers(
self.variables = sunbeam.core.questions.load_answers(
self.client, CLOUD_CONFIG_SECTION
)
self.tfhelper.write_tfvars(self.variables, self.answer_file)
Expand Down Expand Up @@ -569,7 +569,7 @@ def is_skip(self, status: Status | None = None) -> Result:
:return: ResultType.SKIPPED if the Step should be skipped,
ResultType.COMPLETED or ResultType.FAILED otherwise
"""
self.variables = sunbeam.jobs.questions.load_answers(
self.variables = sunbeam.core.questions.load_answers(
self.client, CLOUD_CONFIG_SECTION
)
if self.variables["user"]["run_demo_setup"]:
Expand Down
8 changes: 4 additions & 4 deletions sunbeam-python/sunbeam/commands/dashboard_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import click
from rich.console import Console

from sunbeam.commands.openstack import OPENSTACK_MODEL
from sunbeam.jobs import juju
from sunbeam.jobs.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.jobs.deployment import Deployment
from sunbeam.core import juju
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.deployment import Deployment
from sunbeam.core.openstack import OPENSTACK_MODEL

LOG = logging.getLogger(__name__)
console = Console()
Expand Down
16 changes: 8 additions & 8 deletions sunbeam-python/sunbeam/commands/generate_cloud_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
import yaml
from rich.console import Console

import sunbeam.jobs.questions
import sunbeam.core.questions
from sunbeam.clusterd.client import Client
from sunbeam.commands.configure import CLOUD_CONFIG_SECTION, retrieve_admin_credentials
from sunbeam.commands.openstack import OPENSTACK_MODEL
from sunbeam.commands.terraform import TerraformHelper
from sunbeam.jobs.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.jobs.common import (
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.common import (
BaseStep,
Result,
ResultType,
Status,
run_plan,
)
from sunbeam.jobs.deployment import Deployment
from sunbeam.jobs.juju import JujuHelper, ModelNotFoundException, run_sync
from sunbeam.core.deployment import Deployment
from sunbeam.core.juju import JujuHelper, ModelNotFoundException, run_sync
from sunbeam.core.openstack import OPENSTACK_MODEL
from sunbeam.core.terraform import TerraformHelper

LOG = logging.getLogger(__name__)
console = Console()
Expand Down Expand Up @@ -83,7 +83,7 @@ def is_skip(self, status: Status | None = None) -> Result:
return Result(ResultType.COMPLETED)

# Check if run_demo_setup is done to get demo user information
self.variables = sunbeam.jobs.questions.load_answers(
self.variables = sunbeam.core.questions.load_answers(
self.client, CLOUD_CONFIG_SECTION
)
if "user" not in self.variables:
Expand Down
10 changes: 5 additions & 5 deletions sunbeam-python/sunbeam/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
from snaphelpers import Snap

from sunbeam.clusterd.service import ConfigItemNotFoundException
from sunbeam.commands.juju import WriteCharmLogStep, WriteJujuStatusStep
from sunbeam.commands.openstack import OPENSTACK_MODEL
from sunbeam.jobs.common import (
from sunbeam.core.common import (
FORMAT_TABLE,
FORMAT_YAML,
run_plan,
)
from sunbeam.jobs.deployment import Deployment
from sunbeam.jobs.juju import JujuHelper
from sunbeam.core.deployment import Deployment
from sunbeam.core.juju import JujuHelper
from sunbeam.core.openstack import OPENSTACK_MODEL
from sunbeam.steps.juju import WriteCharmLogStep, WriteJujuStatusStep
from sunbeam.utils import argument_with_deprecated_option

LOG = logging.getLogger(__name__)
Expand Down
6 changes: 3 additions & 3 deletions sunbeam-python/sunbeam/commands/juju_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
from rich.console import Console
from snaphelpers import Snap

from sunbeam.commands.juju import (
from sunbeam.core.common import BaseStep, run_plan
from sunbeam.core.deployment import Deployment
from sunbeam.steps.juju import (
RegisterRemoteJujuUserStep,
SwitchToController,
UnregisterJujuController,
)
from sunbeam.jobs.common import BaseStep, run_plan
from sunbeam.jobs.deployment import Deployment

LOG = logging.getLogger(__name__)
console = Console()
Expand Down
8 changes: 4 additions & 4 deletions sunbeam-python/sunbeam/commands/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from snaphelpers import Snap

from sunbeam.commands.configure import retrieve_admin_credentials
from sunbeam.commands.openstack import OPENSTACK_MODEL
from sunbeam.commands.terraform import TerraformException
from sunbeam.jobs.deployment import Deployment
from sunbeam.jobs.juju import JujuHelper, ModelNotFoundException, run_sync
from sunbeam.core.deployment import Deployment
from sunbeam.core.juju import JujuHelper, ModelNotFoundException, run_sync
from sunbeam.core.openstack import OPENSTACK_MODEL
from sunbeam.core.terraform import TerraformException

LOG = logging.getLogger(__name__)
console = Console()
Expand Down
6 changes: 3 additions & 3 deletions sunbeam-python/sunbeam/commands/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
ClusterServiceUnavailableException,
ManifestItemNotFoundException,
)
from sunbeam.jobs.common import FORMAT_TABLE, FORMAT_YAML
from sunbeam.jobs.deployment import Deployment
from sunbeam.jobs.manifest import Manifest
from sunbeam.core.common import FORMAT_TABLE, FORMAT_YAML
from sunbeam.core.deployment import Deployment
from sunbeam.core.manifest import Manifest
from sunbeam.utils import argument_with_deprecated_option

LOG = logging.getLogger(__name__)
Expand Down
8 changes: 4 additions & 4 deletions sunbeam-python/sunbeam/commands/openrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from rich.console import Console

from sunbeam.commands.configure import retrieve_admin_credentials
from sunbeam.commands.openstack import OPENSTACK_MODEL
from sunbeam.jobs import juju
from sunbeam.jobs.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.jobs.deployment import Deployment
from sunbeam.core import juju
from sunbeam.core.checks import VerifyBootstrappedCheck, run_preflight_checks
from sunbeam.core.deployment import Deployment
from sunbeam.core.openstack import OPENSTACK_MODEL

LOG = logging.getLogger(__name__)
console = Console()
Expand Down
Loading

0 comments on commit 1ae478d

Please sign in to comment.