2020-08-17 12:51:11 +00:00
|
|
|
# system
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# local
|
2020-08-18 11:50:21 +00:00
|
|
|
from ._subcommand import FlexCommand
|
2020-08-17 12:51:11 +00:00
|
|
|
from .utils.dockercommand import DockerCommand
|
2020-08-18 12:04:10 +00:00
|
|
|
from .utils._misc import are_you_sure
|
2020-08-17 12:51:11 +00:00
|
|
|
|
|
|
|
|
2020-08-18 11:50:21 +00:00
|
|
|
class DownCommand(FlexCommand):
|
2020-08-17 12:51:11 +00:00
|
|
|
"""kiwi down"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
2020-08-18 11:50:21 +00:00
|
|
|
'down', description="Bring down the whole instance, a project or service(s) inside a project"
|
2020-08-17 12:51:11 +00:00
|
|
|
)
|
|
|
|
|
2020-08-18 11:50:21 +00:00
|
|
|
def _run_instance(self, runner, config, args):
|
|
|
|
if are_you_sure("This will bring down the entire instance."):
|
2020-08-18 12:04:10 +00:00
|
|
|
return super()._run_instance(runner, config, args)
|
2020-08-17 13:00:05 +00:00
|
|
|
|
2020-08-18 11:50:21 +00:00
|
|
|
return False
|
|
|
|
|
2020-08-18 12:04:10 +00:00
|
|
|
def _run_project(self, runner, config, args, project_name):
|
|
|
|
logging.info(f"Bringing down project '{project_name}'")
|
2020-08-18 11:50:21 +00:00
|
|
|
|
|
|
|
DockerCommand('docker-compose').run(
|
|
|
|
config, args, ['down']
|
|
|
|
)
|
|
|
|
return True
|
|
|
|
|
2020-08-18 12:04:10 +00:00
|
|
|
def _run_services(self, runner, config, args, project_name, services):
|
|
|
|
logging.info(f"Bringing down services {services} in project '{project_name}'")
|
2020-08-18 11:50:21 +00:00
|
|
|
|
|
|
|
DockerCommand('docker-compose').run(
|
2020-08-18 12:04:10 +00:00
|
|
|
config, args, ['stop', *services]
|
2020-08-18 11:50:21 +00:00
|
|
|
)
|
|
|
|
DockerCommand('docker-compose').run(
|
2020-08-18 12:04:10 +00:00
|
|
|
config, args, ['rm', '-f', *services]
|
2020-08-18 11:50:21 +00:00
|
|
|
)
|
2020-08-17 13:00:05 +00:00
|
|
|
return True
|