From 42c474d2739d0aa3b4df8d4504b9d61723a4ac86 Mon Sep 17 00:00:00 2001 From: novokrest Date: Wed, 2 May 2018 12:40:16 +0300 Subject: [PATCH] deploy: Add tools/deploy delete command. --- tools/deploy | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/deploy b/tools/deploy index a4d8eb9..2983dbf 100755 --- a/tools/deploy +++ b/tools/deploy @@ -165,6 +165,21 @@ def log(options: argparse.Namespace) -> None: print('log: Error {}: {}. Aborting.'.format(r.status_code, r.text)) sys.exit(1) +def delete(options: argparse.Namespace) -> None: + check_common_options(options) + headers = {'key': options.key} + url = urllib.parse.urljoin(options.server, 'bots/delete') + payload = {'name': options.botname} + r = requests.post(url, headers=headers, json=payload) + if r.status_code == requests.codes.ok and r.text == 'done': + print('delete: The bot has been removed from the botfarm.') + return + if r.status_code == 401: + print('delete: Authentication error with the server. Aborting.') + else: + print('delete: Error {}: {}. Aborting.'.format(r.status_code, r.text)) + sys.exit(1) + def main() -> None: usage = """tools/deploy [options] @@ -187,6 +202,10 @@ To stop the bot, use: To get logs of the bot, use: tools/deploy log mybot --server=$SERVER --key=$TOKEN +To delete the bot, use: + + tools/deploy delete mybot --server=$SERVER --key=$TOKEN + """ parser = argparse.ArgumentParser(usage=usage) parser.add_argument('command', help='Command to run.') @@ -222,6 +241,7 @@ To get logs of the bot, use: 'start': start, 'stop': stop, 'log': log, + 'delete': delete, } if options.command in commands: commands[options.command](options)