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/02/12 21:49:37 UTC
svn commit: r743897 - in /incubator/tashi/trunk/src/tashi: ./ agents/
client/ clustermanager/ messaging/ nodemanager/ nodemanager/vmcontrol/
Author: mryan3
Date: Thu Feb 12 21:49:36 2009
New Revision: 743897
URL: http://svn.apache.org/viewvc?rev=743897&view=rev
Log:
A first pass at making Tashi compatible with Python 2.4
See TASHI-3
Primary changes include class declarations using object as the parent type
instead of just and empty set of parenthesis. Also, try...except...finally
blocks are try...try...except...finally.
Modified:
incubator/tashi/trunk/src/tashi/agents/dhcpdnsscheduler.py
incubator/tashi/trunk/src/tashi/agents/examplepolicy.py
incubator/tashi/trunk/src/tashi/client/tashi-client.py
incubator/tashi/trunk/src/tashi/client/test.py
incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py
incubator/tashi/trunk/src/tashi/messaging/messaging.py
incubator/tashi/trunk/src/tashi/messaging/soapmessaging.py
incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py
incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py
incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/vmcontrolinterface.py
incubator/tashi/trunk/src/tashi/util.py
Modified: incubator/tashi/trunk/src/tashi/agents/dhcpdnsscheduler.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/agents/dhcpdnsscheduler.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/agents/dhcpdnsscheduler.py (original)
+++ incubator/tashi/trunk/src/tashi/agents/dhcpdnsscheduler.py Thu Feb 12 21:49:36 2009
@@ -1,3 +1,5 @@
+#! /usr/bin/env python
+
#( Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -30,7 +32,7 @@
from tashi.services import clustermanagerservice
from tashi.util import getConfig, boolean
-class DhcpDnsScheduler():
+class DhcpDnsScheduler(object):
def __init__(self, config, client, transport):
self.config = config
self.client = client
Modified: incubator/tashi/trunk/src/tashi/agents/examplepolicy.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/agents/examplepolicy.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/agents/examplepolicy.py (original)
+++ incubator/tashi/trunk/src/tashi/agents/examplepolicy.py Thu Feb 12 21:49:36 2009
@@ -1,3 +1,5 @@
+#! /usr/bin/env python
+
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -28,7 +30,7 @@
from tashi.services import clustermanagerservice
from tashi.util import getConfig
-class ExamplePolicy():
+class ExamplePolicy(object):
def __init__(self, client, transport):
self.client = client
self.transport = transport
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=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/tashi-client.py (original)
+++ incubator/tashi/trunk/src/tashi/client/tashi-client.py Thu Feb 12 21:49:36 2009
@@ -27,7 +27,7 @@
from thrift.transport.TSocket import TSocket
from tashi.services import clustermanagerservice
-from tashi import vmStates, hostStates, boolean, getConfig
+from tashi import vmStates, hostStates, boolean, getConfig, stringPartition
users = {}
machineTypes = {}
@@ -85,7 +85,7 @@
disks = []
for strDisk in strDisks:
strDisk = strDisk.strip()
- (l, s, r) = strDisk.partition(":")
+ (l, s, r) = stringPartition(strDisk, ":")
if (r == ""):
r = "False"
r = boolean(r)
@@ -101,7 +101,7 @@
nics = []
for strNic in strNics:
strNic = strNic.strip()
- (l, s, r) = strNic.partition(":")
+ (l, s, r) = stringPartition(strNic, ":")
l = int(l)
nic = NetworkConfiguration(d={'mac':r, 'network':l})
nics.append(nic)
@@ -115,7 +115,7 @@
hints = {}
for strHint in strHints:
strHint = strHint.strip()
- (l, s, r) = strHint.partition("=")
+ (l, s, r) = stringPartition(strHint, "=")
hints[l] = r
return hints
except:
@@ -398,53 +398,54 @@
client._transport = transport
client._transport.open()
try:
- if (function not in argLists):
- usage()
- possibleArgs = argLists[function]
- args = sys.argv[2:]
- vals = {}
- for arg in args:
- if (arg == "--help" or arg == "--examples"):
- usage(function)
- for parg in possibleArgs:
- (parg, conv, default, required) = parg
- val = None
- for i in range(0, len(args)):
- arg = args[i]
- if (arg.startswith("--") and arg[2:] == parg):
- val = conv(args[i+1])
- if (val == None):
- val = default()
- vals[parg] = val
- for arg in args:
- if (arg.startswith("--hide-")):
- show_hide.append((False, arg[7:]))
- if (arg.startswith("--show-")):
- show_hide.append((True, arg[7:]))
- f = getattr(client, function, None)
- if (f is None):
- f = extraViews[function][0]
- if (function in convertArgs):
- fargs = eval(convertArgs[function], globals(), vals)
- else:
- fargs = []
- res = f(*fargs)
- if (res != None):
- keys = extraViews.get(function, (None, None))[1]
- try:
- if (type(res) == types.ListType):
- makeTable(res, keys)
- else:
- pprint(res)
- except Exception, e:
- print e
- except TashiException, e:
- print "TashiException:"
- print e.msg
- exitCode = e.errno
- except Exception, e:
- print e
- usage(function)
+ try:
+ if (function not in argLists):
+ usage()
+ possibleArgs = argLists[function]
+ args = sys.argv[2:]
+ vals = {}
+ for arg in args:
+ if (arg == "--help" or arg == "--examples"):
+ usage(function)
+ for parg in possibleArgs:
+ (parg, conv, default, required) = parg
+ val = None
+ for i in range(0, len(args)):
+ arg = args[i]
+ if (arg.startswith("--") and arg[2:] == parg):
+ val = conv(args[i+1])
+ if (val == None):
+ val = default()
+ vals[parg] = val
+ for arg in args:
+ if (arg.startswith("--hide-")):
+ show_hide.append((False, arg[7:]))
+ if (arg.startswith("--show-")):
+ show_hide.append((True, arg[7:]))
+ f = getattr(client, function, None)
+ if (f is None):
+ f = extraViews[function][0]
+ if (function in convertArgs):
+ fargs = eval(convertArgs[function], globals(), vals)
+ else:
+ fargs = []
+ res = f(*fargs)
+ if (res != None):
+ keys = extraViews.get(function, (None, None))[1]
+ try:
+ if (type(res) == types.ListType):
+ makeTable(res, keys)
+ else:
+ pprint(res)
+ except Exception, e:
+ print e
+ except TashiException, e:
+ print "TashiException:"
+ print e.msg
+ exitCode = e.errno
+ except Exception, e:
+ print e
+ usage(function)
finally:
client._transport.close()
sys.exit(exitCode)
Modified: incubator/tashi/trunk/src/tashi/client/test.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/client/test.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/test.py (original)
+++ incubator/tashi/trunk/src/tashi/client/test.py Thu Feb 12 21:49:36 2009
@@ -38,7 +38,7 @@
import tashi.client.client
-class ClientConnection():
+class ClientConnection(object):
'''Creates an rpc proxy'''
def __init__(self, host, port):
self.host = host
Modified: incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py Thu Feb 12 21:49:36 2009
@@ -34,7 +34,7 @@
def RPC(oldFunc):
return convertExceptions(oldFunc)
-class ClusterManagerService():
+class ClusterManagerService(object):
"""RPC service for the ClusterManager"""
def __init__(self, config, data):
@@ -350,50 +350,51 @@
self.data.releaseHost(oldHost)
raise TashiException(d={'errno':Errors.NoSuchHostId, 'msg':'Host id and hostname mismatch'})
try:
- self.lastContacted[host.id] = time.time()
- oldHost.version = host.version
- oldHost.memory = host.memory
- oldHost.cores = host.cores
- oldHost.up = True
- oldHost.decayed = False
- if (host.version != version and not self.allowMismatchedVersions):
- oldHost.state = HostState.VersionMismatch
- if (host.version == version and oldHost.state == HostState.VersionMismatch):
- oldHost.state = HostState.Normal
- for instance in instances:
- try:
- oldInstance = self.data.acquireInstance(instance.id)
- except TashiException, e:
- if (e.errno == Errors.NoSuchInstanceId):
- self.log.info('Host %s reported an instance %d that did not previously exist (decay)' % (host.name, instance.id))
- oldHost.decayed = True
- continue
- #oldInstance = self.data.registerInstance(instance)
- else:
- raise
- try:
- if (oldInstance.hostId != host.id):
- self.log.info('Host %s is claiming instance %d actually owned by hostId %s (decay)' % (host.name, oldInstance.id, str(oldInstance.hostId)))
+ try:
+ self.lastContacted[host.id] = time.time()
+ oldHost.version = host.version
+ oldHost.memory = host.memory
+ oldHost.cores = host.cores
+ oldHost.up = True
+ oldHost.decayed = False
+ if (host.version != version and not self.allowMismatchedVersions):
+ oldHost.state = HostState.VersionMismatch
+ if (host.version == version and oldHost.state == HostState.VersionMismatch):
+ oldHost.state = HostState.Normal
+ for instance in instances:
+ try:
+ oldInstance = self.data.acquireInstance(instance.id)
+ except TashiException, e:
+ if (e.errno == Errors.NoSuchInstanceId):
+ self.log.info('Host %s reported an instance %d that did not previously exist (decay)' % (host.name, instance.id))
+ oldHost.decayed = True
+ continue
+ #oldInstance = self.data.registerInstance(instance)
+ else:
+ raise
+ try:
+ if (oldInstance.hostId != host.id):
+ self.log.info('Host %s is claiming instance %d actually owned by hostId %s (decay)' % (host.name, oldInstance.id, str(oldInstance.hostId)))
+ oldHost.decayed = True
+ continue
+ oldInstance.decayed = (oldInstance.state != instance.state)
+ self.updateDecay(self.decayedInstances, oldInstance)
+ if (oldInstance.decayed):
+ self.log.info('State reported as %s instead of %s for instance %d on host %s (decay)' % (vmStates[instance.state], vmStates[oldInstance.state], instance.id, host.name))
+ finally:
+ self.data.releaseInstance(oldInstance)
+ instanceIds = [instance.id for instance in instances]
+ for instanceId in [instance.id for instance in self.data.getInstances().itervalues() if instance.hostId == host.id]:
+ if (instanceId not in instanceIds):
+ self.log.info('instance %d was not reported by host %s as expected (decay)' % (instanceId, host.name))
+ instance = self.data.acquireInstance(instanceId)
+ instance.decayed = True
+ self.updateDecay(self.decayedInstances, instance)
oldHost.decayed = True
- continue
- oldInstance.decayed = (oldInstance.state != instance.state)
- self.updateDecay(self.decayedInstances, oldInstance)
- if (oldInstance.decayed):
- self.log.info('State reported as %s instead of %s for instance %d on host %s (decay)' % (vmStates[instance.state], vmStates[oldInstance.state], instance.id, host.name))
- finally:
- self.data.releaseInstance(oldInstance)
- instanceIds = [instance.id for instance in instances]
- for instanceId in [instance.id for instance in self.data.getInstances().itervalues() if instance.hostId == host.id]:
- if (instanceId not in instanceIds):
- self.log.info('instance %d was not reported by host %s as expected (decay)' % (instanceId, host.name))
- instance = self.data.acquireInstance(instanceId)
- instance.decayed = True
- self.updateDecay(self.decayedInstances, instance)
- oldHost.decayed = True
- self.data.releaseInstance(instance)
- except Exception, e:
- oldHost.decayed = True
- raise
+ self.data.releaseInstance(instance)
+ except Exception, e:
+ oldHost.decayed = True
+ raise
finally:
self.updateDecay(self.decayedHosts, oldHost)
self.data.releaseHost(oldHost)
Modified: incubator/tashi/trunk/src/tashi/messaging/messaging.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/messaging/messaging.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/messaging/messaging.py (original)
+++ incubator/tashi/trunk/src/tashi/messaging/messaging.py Thu Feb 12 21:49:36 2009
@@ -30,7 +30,7 @@
from threadpool import ThreadPoolClass, threadpool, ThreadPool
from threadpool import threadpoolmethod, threaded, synchronized, synchronizedmethod
-class RWLock():
+class RWLock(object):
"""RWLock: Simple reader/writer lock implementation
FIXME: this implementation will starve writers!
Methods:
@@ -60,7 +60,7 @@
-class MessageBroker():
+class MessageBroker(object):
def __init__(self):
self.sublock = RWLock()
self.subscribers = []
@@ -123,7 +123,7 @@
for message in messages:
self.publish(message)
-class Subscriber():
+class Subscriber(object):
def __init__(self, broker, pmatch={}, nmatch={}, synchronized=False):
self.broker = broker
self.lock = threading.Lock()
@@ -187,7 +187,7 @@
-class Publisher():
+class Publisher(object):
'''Superclass for pub/sub publishers
FIXME: use finer-grained locking'''
Modified: incubator/tashi/trunk/src/tashi/messaging/soapmessaging.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/messaging/soapmessaging.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/messaging/soapmessaging.py (original)
+++ incubator/tashi/trunk/src/tashi/messaging/soapmessaging.py Thu Feb 12 21:49:36 2009
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -76,7 +76,7 @@
-class MessageBrokerSoapProxy():
+class MessageBrokerSoapProxy(object):
def __init__(self, host, port):
self.host = host
self.port = port
@@ -130,7 +130,7 @@
def stop(self):
self.server.stop()
-class SubscriberSoapProxy():
+class SubscriberSoapProxy(object):
def __init__(self, host, port):
self.host = host
self.port = port
Modified: incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py (original)
+++ incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py Thu Feb 12 21:49:36 2009
@@ -31,7 +31,7 @@
from tashi.nodemanager import RPC
from tashi import boolean, vmStates, logged, ConnectionManager, timed, version
-class NodeManagerService():
+class NodeManagerService(object):
"""RPC handler for the NodeManager
Perhaps in the future I can hide the dfs from the
Modified: incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py (original)
+++ incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py Thu Feb 12 21:49:36 2009
@@ -40,40 +40,41 @@
listenSocket.bind(("0.0.0.0", port))
#print "bound"
try:
- listenSocket.listen(5)
- ls = listenSocket.fileno()
- input = child.monitorFd
- output = child.monitorFd
- #print "listen"
- select.select([ls], [], [])
- (s, clientAddr) = listenSocket.accept()
- while s:
- if (output != -1):
- (rl, wl, el) = select.select([s, output], [], [])
- else:
- (rl, wl, el) = select.select([s], [], [])
- if (len(rl) > 0):
- if (rl[0] == s):
- #print "from s"
- buf = s.recv(4096)
- if (buf == ""):
- s.close()
- listenSocket.close()
- s = None
- continue
- if (output != -1):
- os.write(child.monitorFd, buf)
- elif (rl[0] == output):
- #print "from output"
- buf = os.read(output, 4096)
- #print "read complete"
- if (buf == ""):
- output = -1
- else:
- s.send(buf)
- except:
- s.close()
- listenSocket.close()
+ try:
+ listenSocket.listen(5)
+ ls = listenSocket.fileno()
+ input = child.monitorFd
+ output = child.monitorFd
+ #print "listen"
+ select.select([ls], [], [])
+ (s, clientAddr) = listenSocket.accept()
+ while s:
+ if (output != -1):
+ (rl, wl, el) = select.select([s, output], [], [])
+ else:
+ (rl, wl, el) = select.select([s], [], [])
+ if (len(rl) > 0):
+ if (rl[0] == s):
+ #print "from s"
+ buf = s.recv(4096)
+ if (buf == ""):
+ s.close()
+ listenSocket.close()
+ s = None
+ continue
+ if (output != -1):
+ os.write(child.monitorFd, buf)
+ elif (rl[0] == output):
+ #print "from output"
+ buf = os.read(output, 4096)
+ #print "read complete"
+ if (buf == ""):
+ output = -1
+ else:
+ s.send(buf)
+ except:
+ s.close()
+ listenSocket.close()
finally:
#print "Thread exiting"
pass
@@ -284,8 +285,14 @@
"""Universal function to start a VM -- used by instantiateVM, resumeVM, and prepReceiveVM"""
global lastCmd
(image, macAddr, memory, cores, diskModel, instanceId, opts) = self.instanceToOld(instance)
- sourceString = "" if not source else "-incoming %s" % (source)
- snapshotString = "" if diskModel == "persistent" else "-snapshot"
+ if (not source):
+ sourceString = ""
+ else:
+ sourceString = "-incoming %s" % (source)
+ if (diskModel == "persistent"):
+ snapshotString = ""
+ else:
+ snapshotString = "-snapshot"
modelString = opts.get("nicModel", "e1000")
clockString = opts.get("clock", "dynticks")
imageLocal = self.dfs.getLocalHandle("images/" + image)
@@ -368,7 +375,10 @@
macAddr = instance.nics[0].mac
memory = instance.typeObj.memory
cores = instance.typeObj.cores
- diskModel = "persistent" if instance.disks[0].persistent else "transient"
+ if (instance.disks[0].persistent):
+ diskModel = "persistent"
+ else:
+ diskModel = "transient"
instanceId = instance.id
opts = instance.hints
# if (diskModel != "transient"):
@@ -446,7 +456,8 @@
stdin.close()
r = stdout.read()
lc = int(r.strip())
- time.sleep(1.0 if lc < 1 else 0.0)
+ if (lc < 1):
+ time.sleep(1.0)
return transportCookie
def migrateVm(self, vmId, target, transportCookie):
Modified: incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/vmcontrolinterface.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/vmcontrolinterface.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/vmcontrolinterface.py (original)
+++ incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/vmcontrolinterface.py Thu Feb 12 21:49:36 2009
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-class VmControlInterface():
+class VmControlInterface(object):
"""Interface description for VM controllers -- like Qemu, Xen, etc"""
def __init__(self, config, dfs, nm):
Modified: incubator/tashi/trunk/src/tashi/util.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/util.py?rev=743897&r1=743896&r2=743897&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/util.py (original)
+++ incubator/tashi/trunk/src/tashi/util.py Thu Feb 12 21:49:36 2009
@@ -33,7 +33,10 @@
"""Decorator that is used to mark a function as temporarily broken"""
def newFunc(*args, **kw):
raise RuntimeError("%s is broken!" % (oldFunc.__name__))
- newFunc.__doc__ = "[Broken] " + "" if oldFunc.__doc__ is None else oldFunc.__doc__
+ if (oldFunc.__doc__ is None):
+ newFunc.__doc__ = "[Broken]"
+ else:
+ newFunc.__doc__ = "[Broken] " + oldFunc.__doc__
newFunc.__name__ = oldFunc.__name__
newFunc.__module__ = oldFunc.__module__
return newFunc
@@ -238,6 +241,15 @@
if (os.getenv("DEBUG", "0") == "1"):
threading.Thread(target=lambda: realDebugConsole(globalDict)).start()
+def stringPartition(s, field):
+ index = s.find(field)
+ if (index == -1):
+ return (s, "", "")
+ l = s[:index]
+ sep = s[index:index+len(field)]
+ r = s[index+len(field):]
+ return (l, sep, r)
+
def enumToStringDict(cls):
d = {}
for i in cls.__dict__: