tashi-admin: send userIds over the wire, not usernames
clustermanagerservice: store userIds for reservations
git-svn-id: https://svn.apache.org/repos/asf/incubator/tashi/trunk@1375310 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/tashi/client/tashi-admin.py b/src/tashi/client/tashi-admin.py
index b7b81dc..0b93a67 100755
--- a/src/tashi/client/tashi-admin.py
+++ b/src/tashi/client/tashi-admin.py
@@ -24,7 +24,6 @@
from tashi.rpycservices.rpyctypes import TashiException
def checkHid(host):
- #userId = getUser()
hosts = client.getHosts()
hostId = None
try:
@@ -39,6 +38,21 @@
# 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 @@
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 @@
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
diff --git a/src/tashi/clustermanager/clustermanagerservice.py b/src/tashi/clustermanager/clustermanagerservice.py
index f590b43..e5b14b7 100644
--- a/src/tashi/clustermanager/clustermanagerservice.py
+++ b/src/tashi/clustermanager/clustermanagerservice.py
@@ -604,15 +604,16 @@
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 @@
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 @@
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 @@
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()