1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 21:03:00 +00:00
kiwi-scp/kiwi_scp/subcommands/purge.py

46 lines
1.3 KiB
Python
Raw Normal View History

2020-08-20 12:15:38 +00:00
# system
import logging
import subprocess
# local
from ._hidden import _find_net
from ..config import LoadedConfig
from ..executable import Executable
from ..misc import are_you_sure
2021-09-22 01:06:43 +00:00
from ..subcommand import SubCommand
2020-08-20 12:15:38 +00:00
class PurgeCommand(SubCommand):
"""kiwi purge"""
def __init__(self):
super().__init__(
'purge',
action="Tearing down",
2020-08-20 12:40:49 +00:00
description="Remove all running docker artifacts of this instance"
2020-08-20 12:15:38 +00:00
)
def _run_instance(self, runner, args):
net_name = LoadedConfig.get()['network:name']
if not _find_net(net_name):
logging.info(f"Network '{net_name}' does not exist")
return True
try:
if are_you_sure("This will bring down this instance's hub network!"):
if runner.run('down'):
Executable('docker').run([
'network', 'rm', net_name
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
logging.info(f"Network '{net_name}' removed")
else:
return False
except subprocess.CalledProcessError:
logging.error(f"Error removing network '{net_name}'")
return False
return True