incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rg...@apache.org
Subject svn commit: r1200047 - in /incubator/tashi/trunk/src/tashi: client/ clustermanager/ clustermanager/data/ rpycservices/
Date Wed, 09 Nov 2011 23:54:36 GMT
Author: rgass
Date: Wed Nov  9 23:54:36 2011
New Revision: 1200047

URL: http://svn.apache.org/viewvc?rev=1200047&view=rev
Log:
- adding support to query vm images via the tashi client.
users can now say "tashi getImages" to be presented with a list of available VM images located
in the directory as specified in the conf file.

- adding support to copy a vm image via the tashi client.
Users can now copy a VM image "tashi copyImage --src src.qcow2 --dst dst.qcow2".  This allows
you to keep people out of the directory with all the VM images.

This is the initial version of these feature.  Need to keep track of who copies an image,
if it is public, who can copy/use, etc.  Need to eventually keep track of this info and dump
into the baseDataObject.



Modified:
    incubator/tashi/trunk/src/tashi/client/tashi-client.py
    incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py
    incubator/tashi/trunk/src/tashi/clustermanager/data/datainterface.py
    incubator/tashi/trunk/src/tashi/clustermanager/data/getentoverride.py
    incubator/tashi/trunk/src/tashi/clustermanager/data/ldapoverride.py
    incubator/tashi/trunk/src/tashi/rpycservices/rpycservices.py
    incubator/tashi/trunk/src/tashi/rpycservices/rpyctypes.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=1200047&r1=1200046&r2=1200047&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/tashi-client.py (original)
+++ incubator/tashi/trunk/src/tashi/client/tashi-client.py Wed Nov  9 23:54:36 2011
@@ -207,6 +207,8 @@ def getMyInstances():
 # Used to define default views on functions and to provide extra functionality (getVmLayout)
 extraViews = {
 'getSlots': (getSlots, None),
+'getImages': (None, ['id', 'imageName']), 
+'copyImage': (None, None), 
 'createMany': (createMany, ['id', 'hostId', 'name', 'user', 'state', 'disk', 'memory', 'cores']),
 'destroyMany': (destroyMany, None),
 'getVmLayout': (getVmLayout, ['id', 'name', 'state', 'instances', 'usedMemory', 'memory',
'usedCores', 'cores']),
@@ -227,6 +229,8 @@ argLists = {
 'pauseVm': [('instance', checkIid, lambda: requiredArg('instance'), True)],
 'unpauseVm': [('instance', checkIid, lambda: requiredArg('instance'), True)],
 'getSlots': [('cores', int, lambda: 1, False), ('memory', int, lambda: 128, False)],
+'getImages': [],
+'copyImage': [('src', str, lambda: requiredArg('src'),True), ('dst', str, lambda: requiredArg('dst'),
True)],
 'getHosts': [],
 'getUsers': [],
 'getNetworks': [],
@@ -252,6 +256,7 @@ convertArgs = {
 'vmmSpecificCall': '[instance, arg]',
 'unregisterHost' : '[hostId]',
 'getSlots' : '[cores, memory]',
+'copyImage' : '[src, dst]',
 }
 
 # Descriptions
@@ -275,6 +280,8 @@ description = {
 'getVmLayout': 'Utility function that displays what VMs are placed on what hosts',
 'vmmSpecificCall': 'Direct access to VM manager specific functionality',
 'unregisterHost' : 'Unregisters host. Registration happens when starting node manager',
+'getImages' : 'Gets a list of available VM images',
+'copyImage' : 'Copies a VM image',
 }
 
 # Example use strings
@@ -296,6 +303,8 @@ examples = {
 'getInstances': [''],
 'getMyInstances': [''],
 'getVmLayout': [''],
+'getImages': [''],
+'copyImage': ['--src src.qcow2 --dst dst.qcow2'],
 'vmmSpecificCall': ['--instance 12345 --arg startVnc', '--instance foobar --arg stopVnc'],
 'unregisterHost' : ['--hostId 2'],
 }

Modified: incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py?rev=1200047&r1=1200046&r2=1200047&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py Wed Nov  9 23:54:36
2011
@@ -1,4 +1,4 @@
- # Licensed to the Apache Software Foundation (ASF) under one
+# 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
 # regarding copyright ownership.  The ASF licenses this file
@@ -230,7 +230,8 @@ class ClusterManagerService(object):
 				self.__checkInstances()
 			except:
 				self.log.exception('monitorCluster iteration failed')
-			self.log.info("Sleeping for %d seconds" % sleepFor)
+			#  XXXrgass too chatty.  Remove
+			#self.log.info("Sleeping for %d seconds" % sleepFor)
 			time.sleep(sleepFor)
 
 
@@ -414,7 +415,23 @@ class ClusterManagerService(object):
 	
 	def getInstances(self):
 		return self.data.getInstances().values()
+
+	def getImages(self):
+		return self.data.getImages()
 	
+	def copyImage(self, src, dst):
+		imageSrc = self.dfs.getLocalHandle("images/" + src)
+		imageDst = self.dfs.getLocalHandle("images/" + dst)
+		try:
+			#  Attempt to restrict to the image directory
+			if ".." not in imageSrc and ".." not in imageDst:
+				self.dfs.copy(imageSrc, imageDst)
+				self.log.info('DFS image copy: %s->%s' % (imageSrc, imageDst))
+			else:
+				self.log.warning('DFS image copy bad path: %s->%s' % (imageSrc, imageDst))
+		except Exception, e:
+			self.log.exception('DFS image copy failed: %s (%s->%s)' % (e, imageSrc, imageDst))
+
 	def vmmSpecificCall(self, instanceId, arg):
 		instance = self.data.getInstance(instanceId)
 		hostname = self.data.getHost(instance.hostId).name
@@ -457,9 +474,10 @@ class ClusterManagerService(object):
 			oldHost.state = HostState.Normal
 
 		# let the host communicate what it is running
-		for instance in instances:
-			self.log.info('Accounting: id %d host %d vmId %d user %d cores %d memory %d' % (instance.id,
host.id, instance.vmId, instance.userId, instance.cores, instance.memory))
-			self.instanceLastContactTime.setdefault(instance.id, 0)
+		# XXXrgass - This is too chatty for the console, I think we should remove this.
+		#for instance in instances:
+			#self.log.info('Accounting: id %d host %d vmId %d user %d cores %d memory %d' % (instance.id,
host.id, instance.vmId, instance.userId, instance.cores, instance.memory))
+			#self.instanceLastContactTime.setdefault(instance.id, 0)
 
 		self.data.releaseHost(oldHost)
 		return host.id

Modified: incubator/tashi/trunk/src/tashi/clustermanager/data/datainterface.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/data/datainterface.py?rev=1200047&r1=1200046&r2=1200047&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/data/datainterface.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/data/datainterface.py Wed Nov  9 23:54:36
2011
@@ -63,7 +63,7 @@ class DataInterface(object):
 	
 	def getUser(self, id):
 		raise NotImplementedError
-		
+
 	def registerHost(self, hostname, memory, cores, version):
 		raise NotImplementedError
 	

Modified: incubator/tashi/trunk/src/tashi/clustermanager/data/getentoverride.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/data/getentoverride.py?rev=1200047&r1=1200046&r2=1200047&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/data/getentoverride.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/data/getentoverride.py Wed Nov  9 23:54:36
2011
@@ -17,7 +17,8 @@
 
 import subprocess
 import time
-from tashi.rpycservices.rpyctypes import User
+import os
+from tashi.rpycservices.rpyctypes import User, LocalImages
 from tashi.clustermanager.data import DataInterface
 from tashi.util import instantiateImplementation
 
@@ -25,6 +26,8 @@ class GetentOverride(DataInterface):
 	def __init__(self, config):
 		DataInterface.__init__(self, config)
 		self.baseDataObject = instantiateImplementation(config.get("GetentOverride", "baseData"),
config)
+		self.dfs = instantiateImplementation(config.get("ClusterManager", "dfs"), config)
+
 		self.users = {}
 		self.lastUserUpdate = 0.0
 		self.fetchThreshold = float(config.get("GetentOverride", "fetchThreshold"))
@@ -64,6 +67,17 @@ class GetentOverride(DataInterface):
 	
 	def getNetwork(self, id):
 		return self.baseDataObject.getNetwork(id)
+
+	def getImages(self):
+		count = 0
+		myList = []
+		for i in self.dfs.list("images"):
+			myFile = self.dfs.getLocalHandle("images/" + i)
+			if os.path.isfile(myFile):
+				image = LocalImages(d={'id':count, 'imageName':i})
+				myList.append(image)
+				count += 1
+		return myList
 	
 	def fetchFromGetent(self):
 		now = time.time()

Modified: incubator/tashi/trunk/src/tashi/clustermanager/data/ldapoverride.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/data/ldapoverride.py?rev=1200047&r1=1200046&r2=1200047&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/data/ldapoverride.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/data/ldapoverride.py Wed Nov  9 23:54:36
2011
@@ -67,7 +67,7 @@ class LdapOverride(DataInterface):
 	
 	def getNetwork(self, id):
 		return self.baseDataObject.getNetwork(id)
-	
+
 	def fetchFromLdap(self):
 		now = time.time()
 		if (now - self.lastUserUpdate > self.fetchThreshold):

Modified: incubator/tashi/trunk/src/tashi/rpycservices/rpycservices.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/rpycservices/rpycservices.py?rev=1200047&r1=1200046&r2=1200047&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/rpycservices/rpycservices.py (original)
+++ incubator/tashi/trunk/src/tashi/rpycservices/rpycservices.py Wed Nov  9 23:54:36 2011
@@ -19,7 +19,7 @@ import rpyc
 from tashi.rpycservices.rpyctypes import *
 import cPickle
 
-clusterManagerRPCs = ['createVm', 'shutdownVm', 'destroyVm', 'suspendVm', 'resumeVm', 'migrateVm',
'pauseVm', 'unpauseVm', 'getHosts', 'getNetworks', 'getUsers', 'getInstances', 'vmmSpecificCall',
'registerNodeManager', 'vmUpdate', 'activateVm', 'registerHost']
+clusterManagerRPCs = ['createVm', 'shutdownVm', 'destroyVm', 'suspendVm', 'resumeVm', 'migrateVm',
'pauseVm', 'unpauseVm', 'getHosts', 'getNetworks', 'getUsers', 'getInstances', 'vmmSpecificCall',
'registerNodeManager', 'vmUpdate', 'activateVm', 'registerHost', 'getImages', 'copyImage']
 nodeManagerRPCs = ['instantiateVm', 'shutdownVm', 'destroyVm', 'suspendVm', 'resumeVm', 'prepReceiveVm',
'prepSourceVm', 'migrateVm', 'receiveVm', 'pauseVm', 'unpauseVm', 'getVmInfo', 'listVms',
'vmmSpecificCall', 'getHostInfo', 'liveCheck']
 
 def clean(args):

Modified: incubator/tashi/trunk/src/tashi/rpycservices/rpyctypes.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/rpycservices/rpyctypes.py?rev=1200047&r1=1200046&r2=1200047&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/rpycservices/rpyctypes.py (original)
+++ incubator/tashi/trunk/src/tashi/rpycservices/rpyctypes.py Wed Nov  9 23:54:36 2011
@@ -143,6 +143,37 @@ class Network(object):
 	def __ne__(self, other):
 		return not (self == other)
 
+class LocalImages(object):
+	def __init__(self, d=None):
+		self.id = None
+		self.userId = None
+		self.imageName = None
+		self.isPublic = None
+		self.explicitUserIds = None
+		if isinstance(d, dict):
+			if 'id' in d:
+				self.id = d['id']
+			if 'userId' in d:
+				self.userId = d['userId']
+			if 'imageName' in d:
+				self.imageName = d['imageName']
+			if 'isPublic' in d:
+				self.isPublic = d['isPublic']
+			if 'explicitUserIds' in d:
+				self.explicitUserIds = d['explicitUserIds']
+
+	def __str__(self): 
+		return str(self.__dict__)
+
+	def __repr__(self): 
+		return repr(self.__dict__)
+
+	def __eq__(self, other):
+		return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+	def __ne__(self, other):
+		return not (self == other)
+
 class User(object):
 	def __init__(self, d=None):
 		self.id = None



Mime
View raw message