1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-23 05:13:01 +00:00
kiwi-scp/kiwi_scp/commands/cmd_down.py

59 lines
1.8 KiB
Python
Raw Normal View History

2021-11-27 17:13:31 +00:00
from typing import List
import click
from .cli import KiwiCommand, KiwiCommandType
from .decorators import kiwi_command
from ..executable import COMPOSE_EXE
2021-12-02 16:08:14 +00:00
from ..instance import Instance
from ..project import Project
from ..services import Services
2021-11-27 17:13:31 +00:00
@click.option(
"-f/-F",
"--force/--no-force",
help=f"skip confirmation",
)
@kiwi_command(
short_help="Bring down kiwi services",
)
class DownCommand(KiwiCommand):
"""Bring down the whole instance, a project or service(s) inside a project"""
2021-12-01 16:49:19 +00:00
type = KiwiCommandType.SERVICES
enabled_only = True
2021-11-27 17:13:31 +00:00
@classmethod
def run_for_instance(cls, instance: Instance, force: bool = None) -> None:
if not force:
if not KiwiCommand.danger_confirm(
"This will bring down the entire instance.",
"",
"This may not be what you intended, because:",
" - Bringing down the instance stops ALL services in here",
):
return
super().run_for_instance(instance)
# TODO net-down
@classmethod
def run_for_project(cls, instance: Instance, project: Project, **kwargs) -> None:
2021-11-27 17:13:31 +00:00
COMPOSE_EXE.run(["down"], **project.process_kwargs)
@classmethod
2021-11-27 17:33:46 +00:00
def run_for_filtered_services(cls, instance: Instance, project: Project, services: Services,
new_service_names: List[str], **kwargs) -> None:
if not services:
2021-11-27 17:13:31 +00:00
if not click.confirm(
"Did not find any of those services. \n"
f"Bring down the entire project {project.name} instead?",
default=True
):
return
2021-11-27 17:33:46 +00:00
COMPOSE_EXE.run(["stop", *services.names], **project.process_kwargs)
COMPOSE_EXE.run(["rm", "-f", *services.names], **project.process_kwargs)