From 367c4e221d8f3903c0d6f157864ae60f84c70d98 Mon Sep 17 00:00:00 2001
From: Seblu <sebastien.luttringer@smartjog.com>
Date: Wed, 2 Mar 2011 18:03:47 +0100
Subject: [PATCH] add command cancel

---
 cccli/command/__init__.py |  1 +
 cccli/command/cancel.py   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 cccli/command/cancel.py

diff --git a/cccli/command/__init__.py b/cccli/command/__init__.py
index 1a62dc8..4a9e2fa 100644
--- a/cccli/command/__init__.py
+++ b/cccli/command/__init__.py
@@ -14,6 +14,7 @@ from cccli.command.tag import *
 from cccli.command.vm import *
 
 # by command module
+from cccli.command.cancel import Command_cancel
 from cccli.command.execute import Command_execute
 from cccli.command.expert import Command_expert
 from cccli.command.jobs import Command_jobs
diff --git a/cccli/command/cancel.py b/cccli/command/cancel.py
new file mode 100644
index 0000000..34ea57b
--- /dev/null
+++ b/cccli/command/cancel.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+#coding=utf8
+
+'''
+CloudControl jobs command
+'''
+
+from cccli.exception import *
+from sjrpc.core.exceptions import *
+from cccli.printer import Printer, color
+from cccli.command.command import OptionCommand
+
+class Command_cancel(OptionCommand):
+    '''Cancel a job'''
+
+    def __init__(self, cli, argv0):
+        OptionCommand.__init__(self, cli, argv0)
+        self.set_usage("%prog [options] <job_id> ...")
+
+    def __call__(self, argv):
+        # Parse argline
+        self.parse_args(argv)
+        # append current login if nothing asked
+        if len(self.args) == 0:
+            raise cmdBadArgument()
+        # ask server
+        for jid in self.args:
+            try:
+                self.cli.rpc.call("cancel", int(jid))
+                self.printer.out("Job %s: cancelled."%jid)
+            except ValueError:
+                self.printer.error("Invalid job id: %s"%jid)
+            except RpcError as e:
+                self.printer.error("%s"%e)
-- 
GitLab