summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Styk <mastyk@redhat.com>2020-03-23 12:03:46 +0100
committerMartin Styk <mastyk@redhat.com>2020-03-23 12:11:39 +0100
commit8c2dc189445ebe3e92a9d0c4983704fd98c23439 (patch)
tree499b51a5360b37fd2179568184d006d8d4673986
parent11831c548818bfec248bacb051f381f4800041b0 (diff)
add support to delete task from task library
This support is already implemented in UI. However, it is not possible to do same operation via beaker client. Bug: 1816102 Change-Id: Id3def2100327797c144414050e059998a95a5a3a Signed-off-by: Martin Styk <mastyk@redhat.com>
-rw-r--r--Client/src/bkr/client/commands/cmd_task_delete.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/Client/src/bkr/client/commands/cmd_task_delete.py b/Client/src/bkr/client/commands/cmd_task_delete.py
new file mode 100644
index 0000000..997ec00
--- /dev/null
+++ b/Client/src/bkr/client/commands/cmd_task_delete.py
@@ -0,0 +1,94 @@
+# -*- coding: utf-8 -*-
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+"""
+.. _bkr-task-delete:
+
+bkr task-delete: Delete tasks to Beaker's task library
+===================================================
+
+.. program:: bkr task-delete
+
+Synopsis
+--------
+
+:program:`bkr task-delete` [*options*] <task_name>...
+
+Description
+-----------
+
+Deletes one or more task RPM packages to Beaker's task library. These tasks
+will be no longer available for jobs queued with the Beaker scheduler.
+
+Options
+-------
+
+Common :program:`bkr` options are described in the :ref:`Options
+<common-options>` section of :manpage:`bkr(1)`.
+
+Exit status
+-----------
+
+Non-zero on error, otherwise zero.
+
+Examples
+--------
+
+Delete a particular task::
+
+ bkr task-delete /distribution/beaker/dogfood
+
+Notes
+-----
+
+This command is only available to Beaker administrators.
+
+See also
+--------
+
+:manpage:`bkr(1)`
+"""
+
+from __future__ import print_function
+
+import json
+import sys
+
+from six.moves import xmlrpc_client
+
+from bkr.client import BeakerCommand
+
+
+class Task_Delete(BeakerCommand):
+ """
+ Delete task from task library
+ """
+ enabled = True
+
+ def options(self):
+ self.parser.usage = "%%prog %s [options] <task_name>..." % self.normalized_name
+
+ def run(self, *args, **kwargs):
+ tasks = args
+
+ self.set_hub(**kwargs)
+ failed = False
+ for task in tasks:
+ try:
+ task_id = self.hub.tasks.to_dict(task)['id']
+ output = json.loads(self.hub.tasks.disable_from_ui(task_id))
+ print('{}: {}'.format('success' if output['success'] else 'failed', task))
+ failed = not output['success']
+ except (KeyboardInterrupt, SystemExit):
+ raise
+ except xmlrpc_client.Fault as ex:
+ failed = True
+ sys.stderr.write(ex.faultString + '\n')
+ except Exception as ex:
+ failed = True
+ sys.stderr.write('Exception: %s\n' % ex)
+ exit(failed)