2020-09-02 22:04:12 +00:00
|
|
|
"""Base Controller"""
|
2020-10-16 09:38:49 +00:00
|
|
|
from typing import Dict, List
|
2020-09-02 22:04:12 +00:00
|
|
|
|
|
|
|
from structlog import get_logger
|
2020-10-16 09:38:49 +00:00
|
|
|
from structlog.testing import capture_logs
|
2020-09-02 22:04:12 +00:00
|
|
|
|
2020-10-16 09:31:31 +00:00
|
|
|
from passbook.lib.sentry import SentryIgnoredException
|
2020-09-02 22:04:12 +00:00
|
|
|
from passbook.outposts.models import Outpost
|
|
|
|
|
|
|
|
|
2020-10-16 09:31:31 +00:00
|
|
|
class ControllerException(SentryIgnoredException):
|
|
|
|
"""Exception raise when anything fails during controller run"""
|
|
|
|
|
|
|
|
|
2020-09-02 22:04:12 +00:00
|
|
|
class BaseController:
|
|
|
|
"""Base Outpost deployment controller"""
|
|
|
|
|
|
|
|
deployment_ports: Dict[str, int]
|
|
|
|
|
|
|
|
outpost: Outpost
|
|
|
|
|
2020-10-16 10:54:52 +00:00
|
|
|
def __init__(self, outpost: Outpost):
|
|
|
|
self.outpost = outpost
|
2020-09-02 22:04:12 +00:00
|
|
|
self.logger = get_logger(
|
|
|
|
controller=self.__class__.__name__, outpost=self.outpost
|
|
|
|
)
|
|
|
|
self.deployment_ports = {}
|
|
|
|
|
2020-10-16 20:22:15 +00:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def up(self):
|
2020-09-02 22:04:12 +00:00
|
|
|
"""Called by scheduled task to reconcile deployment/service/etc"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-10-16 20:22:15 +00:00
|
|
|
def up_with_logs(self) -> List[str]:
|
|
|
|
"""Call .up() but capture all log output and return it."""
|
2020-10-16 09:38:49 +00:00
|
|
|
with capture_logs() as logs:
|
2020-10-16 20:22:15 +00:00
|
|
|
self.up()
|
2020-10-16 19:31:55 +00:00
|
|
|
return [f"{x['controller']}: {x['event']}" for x in logs]
|
2020-10-16 09:38:49 +00:00
|
|
|
|
2020-10-16 20:22:15 +00:00
|
|
|
def down(self):
|
|
|
|
"""Handler to delete everything we've created"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-09-02 22:04:12 +00:00
|
|
|
def get_static_deployment(self) -> str:
|
|
|
|
"""Return a static deployment configuration"""
|
|
|
|
raise NotImplementedError
|