import logging from cliff.command import Command from utils import utils import os class DeleteService(Command): "Deletes a service from Traefik" log = logging.getLogger(__name__) def get_parser(self, prog_name): parser = super().get_parser(prog_name) parser.add_argument('domain', help='The domain for the service') return parser def take_action(self, parsed_args): host = parsed_args.domain # Define the path to the YAML file filePath = f'{utils.getServicesPath()}/{host}.yml' # Check if the service file exists, if not exit if not os.path.exists(filePath): print(f"Service \"{host}\" does not exist") return isInstalled = utils.checkIfKubectlInstalled() if not isInstalled: self.log.error("kubectl is not installed") return 1 utils.deleteService(filePath, host)