incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strou...@apache.org
Subject svn commit: r1169600 - /incubator/tashi/trunk/src/tashi/client/tashi-client.py
Date Mon, 12 Sep 2011 03:51:23 GMT
Author: stroucki
Date: Mon Sep 12 03:51:23 2011
New Revision: 1169600

URL: http://svn.apache.org/viewvc?rev=1169600&view=rev
Log:
tashi-client: correct command examples
              fix instance name length correction
              extend getVmLayout to provide getSlots (how many VMs of a size can be created
now)

Modified:
    incubator/tashi/trunk/src/tashi/client/tashi-client.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=1169600&r1=1169599&r2=1169600&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/tashi-client.py (original)
+++ incubator/tashi/trunk/src/tashi/client/tashi-client.py Mon Sep 12 03:51:23 2011
@@ -157,9 +157,24 @@ def getVmLayout():
 			hosts[i.hostId].usedCores += i.cores
 	return hosts.values()
 
+def getSlots(cores, memory):
+	hosts = getVmLayout()
+	count = 0
+
+	for h in hosts:
+		countbycores = int((h.cores - h.usedCores) / cores)
+		countbymemory = int((h.memory - h.usedMemory) / memory)
+		count += min(countbycores, countbymemory)
+
+	print "%d" % (count),
+	print (lambda:"instances", lambda:"instance")[count == 1](),
+	print "with %d" % (cores),
+	print (lambda:"cores", lambda:"core")[cores == 1](),
+	print "and %d MB memory could be created." % (memory)
+	
 def createMany(instance, count):
 	# will create instances from 0 to count-1
-	l = len(str(count) - 1)
+	l = len(str(count - 1))
 	basename = instance.name
 	instances = []
 	for i in range(0, count):
@@ -191,6 +206,7 @@ def getMyInstances():
 
 # Used to define default views on functions and to provide extra functionality (getVmLayout)
 extraViews = {
+'getSlots': (getSlots, None),
 'createMany': (createMany, ['id', 'hostId', 'name', 'user', 'state', 'disk', 'memory', 'cores']),
 'destroyMany': (destroyMany, None),
 'getVmLayout': (getVmLayout, ['id', 'name', 'state', 'instances', 'usedMemory', 'memory',
'usedCores', 'cores']),
@@ -210,6 +226,7 @@ argLists = {
 'migrateVm': [('instance', checkIid, lambda: requiredArg('instance'), True), ('targetHostId',
int, lambda: requiredArg('targetHostId'), True)],
 '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)],
 'getHosts': [],
 'getUsers': [],
 'getNetworks': [],
@@ -220,7 +237,7 @@ argLists = {
 'unregisterHost': [('hostId', int, lambda: requiredArg('hostId'), True)],
 }
 
-# Used to convert the dictionary built from the arguments into an object that can be used
by thrift
+# Used to convert the dictionary built from the arguments into an object that can be used
by rpyc
 convertArgs = {
 'createVm': '[Instance(d={"userId":userId,"name":name,"cores":cores,"memory":memory,"disks":disks,"nics":nics,"hints":hints})]',
 'createMany': '[Instance(d={"userId":userId,"name":basename,"cores":cores,"memory":memory,"disks":disks,"nics":nics,"hints":hints}),
count]',
@@ -234,6 +251,7 @@ convertArgs = {
 'unpauseVm': '[instance]',
 'vmmSpecificCall': '[instance, arg]',
 'unregisterHost' : '[hostId]',
+'getSlots' : '[cores, memory]',
 }
 
 # Descriptions
@@ -248,13 +266,14 @@ description = {
 'migrateVm': 'Live-migrates a VM to a different host',
 'pauseVm': 'Pauses a running VM',
 'unpauseVm': 'Unpauses a paused VM',
+'getSlots': 'Get a count of how many VMs could be started in the cluster',
 'getHosts': 'Gets a list of hosts running Node Managers',
 'getUsers': 'Gets a list of users',
 'getNetworks': 'Gets a list of available networks for VMs to be placed on',
-'getInstances': 'Gets a list of all VMs in Tashi',
+'getInstances': 'Gets a list of all VMs in the cluster',
 'getMyInstances': 'Utility function that only lists VMs owned by the current user',
 'getVmLayout': 'Utility function that displays what VMs are placed on what hosts',
-'vmmSpecificCall': 'Direct access to VMM-specific functionality',
+'vmmSpecificCall': 'Direct access to VM manager specific functionality',
 'unregisterHost' : 'Unregisters host. Registration happens when starting node manager',
 }
 
@@ -267,9 +286,10 @@ examples = {
 'destroyMany': ['--basename foobar'],
 'suspendVm': ['--instance 12345', '--instance foobar'],
 'resumeVm': ['--instance 12345', '--instance foobar'],
-'migrateVm': ['--instanc 12345 --targetHostId 73', '--instance foobar --targetHostId 73'],
+'migrateVm': ['--instance 12345 --targetHostId 73', '--instance foobar --targetHostId 73'],
 'pauseVm': ['--instance 12345', '--instance foobar'],
-'unpauseVm': ['---instance 12345', '--instance foobar'],
+'unpauseVm': ['--instance 12345', '--instance foobar'],
+'getSlots': ['--cores 1 --memory 128'],
 'getHosts': [''],
 'getUsers': [''],
 'getNetworks': [''],
@@ -526,8 +546,8 @@ def main():
 		print "TashiException:"
 		print e.msg
 		exitCode = e.errno
-	except Exception, e:
-		print e
+# 	except Exception, e:
+# 		print e
 		# XXXstroucki: exception may be unrelated to usage of function
 		# so don't print usage on exception as if there were a problem
 		# with the arguments



Mime
View raw message