From ffe1089718e85b192a17df1db5a91e9d77f678ec Mon Sep 17 00:00:00 2001 From: ldericher Date: Tue, 25 Aug 2020 16:27:16 +0200 Subject: [PATCH] "config" -> "init", "inspect" -> "show", removed "purge" (integrated into instance's "down") --- src/etc/command_help.txt | 5 ++--- src/etc/kiwi_help.txt | 2 +- src/kiwi/subcommands/__init__.py | 10 ++++----- src/kiwi/subcommands/down.py | 23 +++++++++++++++++++- src/kiwi/subcommands/{config.py => init.py} | 10 ++++----- src/kiwi/subcommands/{inspect.py => show.py} | 10 ++++----- 6 files changed, 39 insertions(+), 21 deletions(-) rename src/kiwi/subcommands/{config.py => init.py} (87%) rename src/kiwi/subcommands/{inspect.py => show.py} (90%) diff --git a/src/etc/command_help.txt b/src/etc/command_help.txt index 798a699..30381fd 100644 --- a/src/etc/command_help.txt +++ b/src/etc/command_help.txt @@ -3,11 +3,10 @@ Commands for Operation: down Bring down the whole instance, a project or service(s) inside a project update Update the whole instance, a project or service(s) inside a project restart Restart the whole instance, a project or service(s) inside a project - purge Remove all running docker artifacts of this instance Commands for Instance Management: - config Create or configure kiwi-config instance - inspect Inspect projects in this instance, services inside a project or service(s) inside a project + init Initialize or reconfigure kiwi-config instance + show Show projects in this instance, services inside a project or service(s) inside a project cmd Run raw docker-compose command in a project Commands for Project and Service Management: diff --git a/src/etc/kiwi_help.txt b/src/etc/kiwi_help.txt index 60f6ba2..97b462c 100644 --- a/src/etc/kiwi_help.txt +++ b/src/etc/kiwi_help.txt @@ -1,4 +1,4 @@ -kiwi-config is the tool for container server management. +kiwi-config is the simple tool for managing container servers. Features: - Group services into projects using their own docker-compose.yml diff --git a/src/kiwi/subcommands/__init__.py b/src/kiwi/subcommands/__init__.py index f7829e1..f958982 100644 --- a/src/kiwi/subcommands/__init__.py +++ b/src/kiwi/subcommands/__init__.py @@ -3,18 +3,17 @@ from ._hidden import ConfCopyCommand, NetUpCommand from .build import BuildCommand from .cmd import CmdCommand -from .config import ConfigCommand from .disable import DisableCommand from .down import DownCommand from .enable import EnableCommand -from .inspect import InspectCommand +from .init import InitCommand from .logs import LogsCommand from .new import NewCommand from .pull import PullCommand -from .purge import PurgeCommand from .push import PushCommand from .restart import RestartCommand from .shell import ShellCommand +from .show import ShowCommand from .up import UpCommand from .update import UpdateCommand @@ -24,18 +23,17 @@ __all__ = [ 'BuildCommand', 'CmdCommand', - 'ConfigCommand', 'DisableCommand', 'DownCommand', 'EnableCommand', - 'InspectCommand', + 'InitCommand', 'LogsCommand', 'NewCommand', 'PullCommand', - 'PurgeCommand', 'PushCommand', 'RestartCommand', 'ShellCommand', + 'ShowCommand', 'UpCommand', 'UpdateCommand', ] diff --git a/src/kiwi/subcommands/down.py b/src/kiwi/subcommands/down.py index cd53b3e..9c4032f 100644 --- a/src/kiwi/subcommands/down.py +++ b/src/kiwi/subcommands/down.py @@ -1,5 +1,12 @@ +# system +import logging +import subprocess + # local +from ._hidden import _find_net from ..subcommand import ServiceCommand +from ..config import LoadedConfig +from ..executable import Executable from ..misc import are_you_sure @@ -14,13 +21,27 @@ class DownCommand(ServiceCommand): ) def _run_instance(self, runner, args): + net_name = LoadedConfig.get()['network:name'] + if are_you_sure([ "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_instance(runner, args) + if super()._run_instance(runner, args): + # remove the hub network afterwards + if _find_net(net_name): + Executable('docker').run([ + 'network', 'rm', net_name + ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + logging.info(f"Network '{net_name}' removed") + + else: + logging.info(f"Network '{net_name}' does not exist") + + return True return False diff --git a/src/kiwi/subcommands/config.py b/src/kiwi/subcommands/init.py similarity index 87% rename from src/kiwi/subcommands/config.py rename to src/kiwi/subcommands/init.py index 15f3c9c..acca724 100644 --- a/src/kiwi/subcommands/config.py +++ b/src/kiwi/subcommands/init.py @@ -8,14 +8,14 @@ from ..subcommand import SubCommand from ..config import DefaultConfig, LoadedConfig -class ConfigCommand(SubCommand): - """kiwi config""" +class InitCommand(SubCommand): + """kiwi init""" def __init__(self): super().__init__( - 'config', - action=f"Configuring '{KIWI_CONF_NAME}' in", - description="Create or configure kiwi-config instance" + 'init', + action=f"Initializing '{KIWI_CONF_NAME}' in", + description="Initialize or reconfigure kiwi-config instance" ) # -f switch: Initialize with default config diff --git a/src/kiwi/subcommands/inspect.py b/src/kiwi/subcommands/show.py similarity index 90% rename from src/kiwi/subcommands/inspect.py rename to src/kiwi/subcommands/show.py index a7c139e..a321a97 100644 --- a/src/kiwi/subcommands/inspect.py +++ b/src/kiwi/subcommands/show.py @@ -24,14 +24,14 @@ def _print_list(strings): _print_list(list(strings)) -class InspectCommand(ServiceCommand): - """kiwi inspect""" +class ShowCommand(ServiceCommand): + """kiwi show""" def __init__(self): super().__init__( - 'inspect', num_projects='?', num_services='*', - action="Inspecting", - description="Inspect projects in this instance, services inside a project or service(s) inside a project" + 'show', num_projects='?', num_services='*', + action="Showing", + description="Show projects in this instance, services inside a project or service(s) inside a project" ) def _run_instance(self, runner, args):