You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by mr...@apache.org on 2009/03/04 19:44:00 UTC

svn commit: r750123 - in /incubator/tashi/trunk/src/tashi: client/tashi-client.py util.py

Author: mryan3
Date: Wed Mar  4 19:44:00 2009
New Revision: 750123

URL: http://svn.apache.org/viewvc?rev=750123&view=rev
Log:
Factor out createClient function and put it in tashi.util


Modified:
    incubator/tashi/trunk/src/tashi/client/tashi-client.py
    incubator/tashi/trunk/src/tashi/util.py

Modified: incubator/tashi/trunk/src/tashi/client/tashi-client.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/client/tashi-client.py?rev=750123&r1=750122&r2=750123&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/tashi-client.py (original)
+++ incubator/tashi/trunk/src/tashi/client/tashi-client.py Wed Mar  4 19:44:00 2009
@@ -27,7 +27,7 @@
 from thrift.transport.TSocket import TSocket
 
 from tashi.services import clustermanagerservice
-from tashi import vmStates, hostStates, boolean, getConfig, stringPartition
+from tashi import vmStates, hostStates, boolean, getConfig, stringPartition, createClient
 
 users = {}
 
@@ -375,20 +375,8 @@
 	if (len(sys.argv) < 2):
 		usage()
 	function = sys.argv[1]
-	(config,configFiles) = getConfig(["Client"])
-	cfgHost = config.get('Client', 'clusterManagerHost')
-	cfgPort = config.get('Client', 'clusterManagerPort')
-	cfgTimeout = float(config.get('Client', 'clusterManagerTimeout'))
-	host = os.getenv('TASHI_CM_HOST', cfgHost)
-	port = os.getenv('TASHI_CM_PORT', cfgPort)
-	timeout = float(os.getenv('TASHI_CM_TIMEOUT', cfgTimeout)) * 1000.0
-	socket = TSocket(host, int(port))
-	socket.setTimeout(timeout)
-	transport = TBufferedTransport(socket)
-	protocol = TBinaryProtocol(transport)
-	client = clustermanagerservice.Client(protocol)
-	client._transport = transport
-	client._transport.open()
+	(config, configFiles) = getConfig(["Client"])
+	(client, transport) = createClient(config)
 	try:
 		try:
 			if (function not in argLists):

Modified: incubator/tashi/trunk/src/tashi/util.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/util.py?rev=750123&r1=750122&r2=750123&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/util.py (original)
+++ incubator/tashi/trunk/src/tashi/util.py Wed Mar  4 19:44:00 2009
@@ -27,6 +27,11 @@
 import traceback
 import types
 
+from thrift.transport.TSocket import TServerSocket, TSocket
+from thrift.server.TServer import TThreadedServer
+from thrift.protocol.TBinaryProtocol import TBinaryProtocol
+from thrift.transport.TTransport import TBufferedTransport
+from tashi.services import clustermanagerservice
 from tashi.services.ttypes import TashiException, Errors, InstanceState, HostState
 
 def broken(oldFunc):
@@ -250,6 +255,22 @@
 	r = s[index+len(field):]
 	return (l, sep, r)
 
+def createClient(config):
+	cfgHost = config.get('Client', 'clusterManagerHost')
+	cfgPort = config.get('Client', 'clusterManagerPort')
+	cfgTimeout = config.get('Client', 'clusterManagerTimeout')
+	host = os.getenv('TASHI_CM_HOST', cfgHost)
+	port = os.getenv('TASHI_CM_PORT', cfgPort)
+	timeout = float(os.getenv('TASHI_CM_TIMEOUT', cfgTimeout)) * 1000.0
+	socket = TSocket(host, int(port))
+	socket.setTimeout(timeout)
+	transport = TBufferedTransport(socket)
+	protocol = TBinaryProtocol(transport)
+	client = clustermanagerservice.Client(protocol)
+	transport.open()
+	client._transport = transport
+	return (client, transport)
+
 def enumToStringDict(cls):
 	d = {}
 	for i in cls.__dict__: