incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strou...@apache.org
Subject svn commit: r1375310 - in /incubator/tashi/trunk/src/tashi: client/tashi-admin.py clustermanager/clustermanagerservice.py
Date Mon, 20 Aug 2012 23:20:10 GMT
Author: stroucki
Date: Mon Aug 20 23:20:10 2012
New Revision: 1375310

URL: http://svn.apache.org/viewvc?rev=1375310&view=rev
Log:
tashi-admin: send userIds over the wire, not usernames
clustermanagerservice: store userIds for reservations

Modified:
    incubator/tashi/trunk/src/tashi/client/tashi-admin.py
    incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py

Modified: incubator/tashi/trunk/src/tashi/client/tashi-admin.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/client/tashi-admin.py?rev=1375310&r1=1375309&r2=1375310&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/tashi-admin.py (original)
+++ incubator/tashi/trunk/src/tashi/client/tashi-admin.py Mon Aug 20 23:20:10 2012
@@ -24,7 +24,6 @@ from tashi.utils.config import Config
 from tashi.rpycservices.rpyctypes import TashiException
 
 def checkHid(host):
-	#userId = getUser()
 	hosts = client.getHosts()
 	hostId = None
 	try:
@@ -39,6 +38,21 @@ def checkHid(host):
 	# XXXstroucki permissions for host related stuff?
 	return hostId
 
+def checkUid(user):
+	users = client.getUsers()
+	userId = None
+	try:
+		userId = int(user)
+	except:
+		for u in users:
+			if (u.name == user):
+				userId = u.id
+	if (userId is None):
+		raise TashiException({'msg':"Unknown user %s" % (str(host))})
+
+	# XXXstroucki permissions for host related stuff?
+	return userId
+
 def remoteCommand(command, *args):
 	global client
 	#print "Doing command %s args %s" % (command, args)
@@ -131,7 +145,8 @@ def addReservation(args):
 		sys.exit(-1)
 
 	hostId = checkHid(options.hostname)
-	rv = remoteCommand("addReservation", hostId, options.username)
+	userId = checkUid(options.username)
+	rv = remoteCommand("addReservation", hostId, userId)
 	print rv
 	return 0
 
@@ -148,7 +163,9 @@ def delReservation(args):
 		sys.exit(-1)
 
 	hostId = checkHid(options.hostname)
-	rv = remoteCommand("delReservation", hostId, options.username)
+	userId = checkUid(options.username)
+
+	rv = remoteCommand("delReservation", hostId, userId)
 	print rv
 	return 0
 

Modified: incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py?rev=1375310&r1=1375309&r2=1375310&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/clustermanagerservice.py Mon Aug 20 23:20:10
2012
@@ -604,15 +604,16 @@ class ClusterManagerService(object):
 		return 'Host notes set to "%s".' % hostNotes
 
 	# extern
-	def addReservation(self, hostId, username):
+	def addReservation(self, hostId, userId):
 		host = self.data.acquireHost(hostId)
 		msg = None
+		user = self.__getUser(userId)
 		try:
-			if username not in host.reserved:
-				host.reserved.append(username)
-				msg = "%s added to reservations of host %s" % (username, host.name)
+			if userId not in host.reserved:
+				host.reserved.append(userId)
+				msg = "%s added to reservations of host %s" % (user.name, host.name)
 			else:
-				msg = "%s already in reservations of host %s" % (username, host.name)
+				msg = "%s already in reservations of host %s" % (user.name, host.name)
 		finally:
 			self.data.releaseHost(host)
 
@@ -622,15 +623,16 @@ class ClusterManagerService(object):
 			return "Sorry, an error occurred"
 
 	# extern
-	def delReservation(self, hostId, username):
+	def delReservation(self, hostId, userId):
 		host = self.data.acquireHost(hostId)
 		msg = None
+		user = self.__getUser(userId)
 		try:
-			if username not in host.reserved:
-				msg = "%s not in reservations of host %s" % (username, host.name)
+			if userId not in host.reserved:
+				msg = "%s not in reservations of host %s" % (user.name, host.name)
 			else:
-				host.reserved.remove(username)
-				msg = "%s removed from reservations of host %s" % (username, host.name)
+				host.reserved.remove(userId)
+				msg = "%s removed from reservations of host %s" % (user.name, host.name)
 		finally:
 			self.data.releaseHost(host)
 
@@ -647,7 +649,12 @@ class ClusterManagerService(object):
 		if len(users) == 0:
 			return 'Host %s is not reserved for any users' % (host.name)
 
-		usersstring = ', '.join(map(str, users))
+		namelist = []
+		for u in users:
+			user = self.__getUser(u)
+			namelist.append(user.name)
+
+		usersstring = ', '.join(map(str, namelist))
 
 		return 'Host %s reserved for users %s.' % (host.name, usersstring)
 
@@ -664,6 +671,9 @@ class ClusterManagerService(object):
 	def getUsers(self):
 		return self.data.getUsers().values()
 
+	def __getUser(self, userId):
+		return self.data.getUser(userId)
+
 	# extern
 	def getInstances(self):
 		return self.data.getInstances().values()



Mime
View raw message