Skip to content

Commit

Permalink
Merge 5a591ab into 11516d7
Browse files Browse the repository at this point in the history
  • Loading branch information
lyz-code committed May 24, 2022
2 parents 11516d7 + 5a591ab commit 47cb4a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
13 changes: 5 additions & 8 deletions src/drode/adapters/aws.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Gather the integration with the AWS boto library."""

import logging
from dataclasses import dataclass
from typing import Dict, List

import boto3
from botocore.exceptions import ClientError, NoRegionError
from pydantic import BaseModel # noqa: E0611
from pydantic import Field

log = logging.getLogger(__name__)

Expand All @@ -21,11 +22,10 @@ class AWSStateError(Exception):
InstanceInfo = Dict[str, str]


@dataclass
class AutoscalerInfo:
class AutoscalerInfo(BaseModel):
"""Model the response of the AWS API regarding ASGs."""

instances: List[InstanceInfo]
instances: List[InstanceInfo] = Field(default_factory=list)
template: str = ""


Expand Down Expand Up @@ -76,10 +76,7 @@ def get_autoscaling_group(autoscaling_name: str) -> AutoscalerInfo:
ec2 = boto3.client("ec2")
autoscaling = boto3.client("autoscaling")

autoscaler_info = AutoscalerInfo(
template="",
instances=[],
)
autoscaler_info = AutoscalerInfo()

try:
autoscaling_group = autoscaling.describe_auto_scaling_groups(
Expand Down
2 changes: 1 addition & 1 deletion src/drode/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def project_status(config: Config, aws: AWS) -> ProjectStatus:
raise ConfigError("The autoscaler name is not a string")
autoscaler_info = aws.get_autoscaling_group(autoscaler_name)
except ConfigError:
autoscaler_info = AutoscalerInfo(instances=[])
autoscaler_info = AutoscalerInfo()

project[environment] = autoscaler_info

Expand Down
11 changes: 7 additions & 4 deletions src/drode/views.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
"""Define the representations of the data."""

from typing import TYPE_CHECKING

import tabulate

from drode.adapters.aws import AutoscalerInfo
from drode.services import ProjectStatus
if TYPE_CHECKING:
from drode.adapters.aws import AutoscalerInfo
from drode.services import ProjectStatus


def print_autoscaling_group_info(autoscaler_info: AutoscalerInfo) -> None:
def print_autoscaling_group_info(autoscaler_info: "AutoscalerInfo") -> None:
"""Print the information of the autoscaler information in table format."""
print(f"Active Template: {autoscaler_info.template}")
print(
tabulate.tabulate(autoscaler_info.instances, headers="keys", tablefmt="simple")
)


def print_status(project_status: ProjectStatus) -> None:
def print_status(project_status: "ProjectStatus") -> None:
"""Print the project environment status."""
for environment, autoscaler_info in project_status.items():
if len(autoscaler_info.instances) == 0:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/services/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_project_status_works_for_undefined_autoscaling_groups(
result = services.project_status(config, aws)

assert result == {
"Production": AutoscalerInfo(instances=[]),
"Staging": AutoscalerInfo(instances=[]),
"Production": AutoscalerInfo(),
"Staging": AutoscalerInfo(),
}


Expand Down

0 comments on commit 47cb4a5

Please sign in to comment.