Move _TimeoutExpired to utils
[ganeti-local] / lib / luxi.py
index e4c0ff7..4371613 100644 (file)
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2006, 2007 Google Inc.
+# Copyright (C) 2006, 2007, 2011 Google Inc.
 #
 # 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
@@ -34,6 +34,7 @@ import collections
 import time
 import errno
 import logging
+import warnings
 
 from ganeti import serializer
 from ganeti import constants
@@ -277,9 +278,9 @@ def ParseRequest(msg):
     logging.error("LUXI request not a dict: %r", msg)
     raise ProtocolError("Invalid LUXI request (not a dict)")
 
-  method = request.get(KEY_METHOD, None) # pylint: disable-msg=E1103
-  args = request.get(KEY_ARGS, None) # pylint: disable-msg=E1103
-  version = request.get(KEY_VERSION, None) # pylint: disable-msg=E1103
+  method = request.get(KEY_METHOD, None) # pylint: disable=E1103
+  args = request.get(KEY_ARGS, None) # pylint: disable=E1103
+  version = request.get(KEY_VERSION, None) # pylint: disable=E1103
 
   if method is None or args is None:
     logging.error("LUXI request missing method or arguments: %r", msg)
@@ -296,6 +297,8 @@ def ParseResponse(msg):
   # Parse the result
   try:
     data = serializer.LoadJson(msg)
+  except KeyboardInterrupt:
+    raise
   except Exception, err:
     raise ProtocolError("Error while deserializing response: %s" % str(err))
 
@@ -306,7 +309,7 @@ def ParseResponse(msg):
     raise ProtocolError("Invalid response from server: %r" % data)
 
   return (data[KEY_SUCCESS], data[KEY_RESULT],
-          data.get(KEY_VERSION, None)) # pylint: disable-msg=E1103
+          data.get(KEY_VERSION, None)) # pylint: disable=E1103
 
 
 def FormatResponse(success, result, version=None):
@@ -414,7 +417,7 @@ class Client(object):
       old_transp = self.transport
       self.transport = None
       old_transp.Close()
-    except Exception: # pylint: disable-msg=W0703
+    except Exception: # pylint: disable=W0703
       pass
 
   def _SendMethodCall(self, data):
@@ -426,6 +429,12 @@ class Client(object):
       self._CloseTransport()
       raise
 
+  def Close(self):
+    """Close the underlying connection.
+
+    """
+    self._CloseTransport()
+
   def CallMethod(self, method, args):
     """Send a generic request and return the response.
 
@@ -493,7 +502,7 @@ class Client(object):
   def Query(self, what, fields, filter_):
     """Query for resources/items.
 
-    @param what: One of L{constants.QR_OP_LUXI}
+    @param what: One of L{constants.QR_VIA_LUXI}
     @type fields: List of strings
     @param fields: List of requested fields
     @type filter_: None or list
@@ -508,7 +517,7 @@ class Client(object):
   def QueryFields(self, what, fields):
     """Query for available fields.
 
-    @param what: One of L{constants.QR_OP_LUXI}
+    @param what: One of L{constants.QR_VIA_LUXI}
     @type fields: None or list of strings
     @param fields: List of requested fields
     @rtype: L{objects.QueryFieldsResponse}
@@ -543,4 +552,6 @@ class Client(object):
     return self.CallMethod(REQ_QUERY_TAGS, (kind, name))
 
   def QueryLocks(self, fields, sync):
+    warnings.warn("This LUXI call is deprecated and will be removed, use"
+                  " Query(\"%s\", ...) instead" % constants.QR_LOCK)
     return self.CallMethod(REQ_QUERY_LOCKS, (fields, sync))