From 2672fc833362c4b61d5ddeec5cc43101ef6f1cd0 Mon Sep 17 00:00:00 2001
From: Seblu <sebastien.luttringer@smartjog.com>
Date: Mon, 14 Feb 2011 12:44:51 +0100
Subject: [PATCH] command kill and uptime now use TqlCommand

---
 cccli/command/__init__.py   | 11 ++++----
 cccli/command/connection.py | 53 -------------------------------------
 cccli/command/kill.py       | 22 +++++++++++++++
 cccli/command/shell.py      |  9 +++++++
 cccli/command/uptime.py     | 30 +++++++++++++++++++++
 5 files changed, 67 insertions(+), 58 deletions(-)
 delete mode 100644 cccli/command/connection.py
 create mode 100644 cccli/command/kill.py
 create mode 100644 cccli/command/uptime.py

diff --git a/cccli/command/__init__.py b/cccli/command/__init__.py
index 58782b2..1b77071 100644
--- a/cccli/command/__init__.py
+++ b/cccli/command/__init__.py
@@ -6,17 +6,18 @@ CloudControl CLI Commands Package
 '''
 
 # bunch of command
-from cccli.command.shell import *
-from cccli.command.alias import *
-from cccli.command.connection import *
 from cccli.command.account import *
+from cccli.command.alias import *
+from cccli.command.host import *
 from cccli.command.right import *
+from cccli.command.shell import *
 from cccli.command.tag import *
-from cccli.command.host import *
 from cccli.command.vm import *
 
 # by command module
-from cccli.command.list import Command_list
 from cccli.command.expert import Command_expert
+from cccli.command.kill import Command_kill
+from cccli.command.list import Command_list
 from cccli.command.server import Command_server
 from cccli.command.tagdisplay import Command_tagdisplay
+from cccli.command.uptime import Command_uptime
diff --git a/cccli/command/connection.py b/cccli/command/connection.py
deleted file mode 100644
index 189f9b5..0000000
--- a/cccli/command/connection.py
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/env python
-#coding=utf8
-
-'''
-CloudControl Connection related commands
-'''
-
-from cccli.exception import *
-from sjrpc.core.exceptions import *
-from cccli.printer import Printer, color
-from cccli.command.command import Command
-
-class Command_uptime(Command):
-    '''Show connection uptime'''
-
-    def __call__(self, argv):
-        if len(argv) == 1:
-            argv.append("a=%s"%self.cli.settings["login"])
-        tql = "".join(argv[1:]) + "$con"
-        try:
-            objs = self.cli.rpc.call("list", tql)
-        except RpcError as e:
-            raise cmdError("RPCError: %s"%str(e))
-        for o in objs:
-            if "a" in o and "con" in o:
-                self.printer.out("%s: %ss"%(o["a"], o["con"]))
-
-    def usage(self):
-        return "Usage: uptime [tql]"
-
-
-class Command_whoami(Command):
-    '''Show connection login'''
-
-    def __call__(self, argv):
-        if len(argv) != 1:
-            raise cmdBadArgument()
-        self.printer.out(self.cli.settings["login"])
-
-
-class Command_kill(Command):
-    '''Kill a server connection'''
-
-    def __call__(self, argv):
-        if len(argv) != 2:
-            raise cmdBadArgument()
-        try:
-            self.cli.rpc.call("kill", argv[1])
-        except RpcError as e:
-            raise cmdError("RPCError: %s"%str(e))
-
-    def usage(self):
-        return "usage: kill <tql>"
diff --git a/cccli/command/kill.py b/cccli/command/kill.py
new file mode 100644
index 0000000..935b4e9
--- /dev/null
+++ b/cccli/command/kill.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+#coding=utf8
+
+'''
+CloudControl Connection related commands
+'''
+
+from cccli.exception import *
+from sjrpc.core.exceptions import *
+from cccli.printer import Printer, color
+from cccli.command.command import TqlCommand
+
+class Command_kill(TqlCommand):
+    '''Kill a server connection'''
+
+    def __call__(self, argv):
+        # args parse
+        self.parse_args(argv)
+        if len(self.args) != 1:
+            raise cmdBadArgument()
+        # rpccall
+        self.rpccall("kill", self.args[0])
diff --git a/cccli/command/shell.py b/cccli/command/shell.py
index 19c48ca..cb89deb 100644
--- a/cccli/command/shell.py
+++ b/cccli/command/shell.py
@@ -26,6 +26,15 @@ class Command_version(Command):
         self.printer.out(cccli.version)
 
 
+class Command_whoami(Command):
+    '''Show connection login'''
+
+    def __call__(self, argv):
+        if len(argv) != 1:
+            raise cmdBadArgument()
+        self.printer.out(self.cli.settings["login"])
+
+
 class Command_history(Command):
     '''Show commands history'''
     def __call__(self, argv):
diff --git a/cccli/command/uptime.py b/cccli/command/uptime.py
new file mode 100644
index 0000000..1212f1e
--- /dev/null
+++ b/cccli/command/uptime.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+#coding=utf8
+
+'''
+CloudControl Connection related commands
+'''
+
+from cccli.exception import *
+from sjrpc.core.exceptions import *
+from cccli.printer import Printer, color
+from cccli.command.command import TqlCommand
+
+class Command_uptime(TqlCommand):
+    '''Show connection uptime'''
+
+    def __init__(self, cli, argv0):
+        TqlCommand.__init__(self, cli, argv0)
+        self.set_usage("%prog [options] [tql]")
+
+    def __call__(self, argv):
+        # args parse
+        self.parse_args(argv)
+        if len(self.args) == 0:
+            _tql = "a=%s$con"%self.cli.settings["login"]
+        else:
+            _tql ="".join(self.args) + "$con" 
+        objs = self.rpccall("list", _tql)
+        for o in objs:
+            if "a" in o and "con" in o:
+                self.printer.out("%s: %ss"%(o["a"], o["con"]))
-- 
GitLab