コード例 #1
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def cloudinfo(argv,param):
	'''Get cloud information include storage space information;
	'''
	result=[('key','value')]
	generalInfo=requestTo(param[0],param[1],'/cloud/getInfo')
	dom = minidom.parseString(generalInfo)
	result+=[('UUID',getValue(dom,'UUID')) ]
	result+=[('name',getValue(dom,'name')) ]
	result+=[('network ID',getValue(dom,'network','id')) ]
	result+=[('netmask',getValue(dom,'network','mask')) ]
	result+=[('default route',getValue(dom,'network','defaultRoute')) ]
	key='dns'
	if getValue(dom,'dns') not in [None,'']:
		for element in getValue(dom,'dns').split(','):
			result+=[(key,element)]
			key=''
	else:
		result+=[(key,'None')]
		key=''

	simpleIPList=network.getIPPoolStringList(getValue(dom,'guest').split(','))
	key='guest IP Pool'
	for element in simpleIPList:
		result+=[(key,element) ]
		key=''
	
	result+=[('auto mode',converter.autoMode[getValue(dom,'autoMode')]) ]

	storageInfo=requestTo(param[0],param[1],'/cloud/getStorageInfo')
	dom = minidom.parseString(storageInfo)
	capacity=getValue(dom,'capacity')
	free=getValue(dom,'free')
	percent= (float(capacity)-float(free))*100.0/float(capacity)
	result+=[('storage usage','%s/%s (%.2f%%)'%(int(capacity)-int(free),capacity,percent))]
	
	hostInfo=requestTo(param[0],param[1],'/host/getInfo')
	dom = minidom.parseString(hostInfo)
	hostList=dom.getElementsByTagName('host')
	activeCount=0
	for element in hostList:
		if getValue(element,'status')=='1':
			activeCount+=1
	result+=[('active Host','%d/%d'%(activeCount,len(hostList)))]

	guestInfo=requestTo(param[0],param[1],'/guest/getState')
	dom = minidom.parseString(guestInfo)
	guestList=dom.getElementsByTagName('guest')
	activeCount=0
	for element in guestList:
		if getValue(element,'status')=='1':
			activeCount+=1
	result+=[('active Guest','%d/%d'%(activeCount,len(guestList)))]
	
	print getTable(result)
コード例 #2
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def hostmonitor(argv,param):
	'''Show current status of a specific host;
	Usage
		hostmonitor HOST_ID
	'''
	if len(argv)==1:
		try:
			hostID=int(argv[0])
		except:
			print "hostID must be integer"
			return
	else:
		print param[3][getMyFunctionName()].__doc__
		return
	
	panel=MonitorPanel()

	firstRound=True
	while True:
		hostInfo=requestTo(param[0],param[1],'/host/getAllCurrentInfo?hostID=%s'%(str(hostID)))
		dom = minidom.parseString(hostInfo)
		if firstRound:
			if getValue(dom,'host','hostID')==None:
				print "Host not found."
				return
			if getValue(dom,'host','polling')=='error':
				print "Host is not running."
				return
			PressKeyThread().start()
			firstRound=False

		result=[('host ID: '+getValue(dom,'host','hostID'),' '*30)]
		result+=[('CPU Usage',str(getValue(dom,'average'))+'%')]
		
		try:
			memTotal=int(getValue(dom,'memTotal'))
			memFree=int(getValue(dom,'memFree'))
			result+=[('free memory space','%d/%d %.2f%%'%(memFree,memTotal,memFree*100.0/memTotal))]
		except:
			result+=[('free memory space','None')]
		
		result+=[('network transmit rate',str(getValue(dom,'tx'))+' Kbps')]
		result+=[('network recieve rate',str(getValue(dom,'rx'))+' Kbps')]

		try:
			storageFree=int(getValue(dom,'free'))
			storageCapacity=int(getValue(dom,'capacity'))
			result+=[('free storage space','%d/%d %.2f%%'%(storageFree,storageCapacity,storageFree*100.0/storageCapacity))]
		except:
			result+=[('free storage space','None')]

		panel.update(getTable(result))

		if len(threading.enumerate())==1:
			break
		
		time.sleep(1)
	
	print ''
コード例 #3
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def guestmonitor(argv,param):
	'''Show current status of a specific guest;
	Usage
		guestmonitor GUEST_ID
	'''
	if len(argv)==1:
		try:
			guestID=int(argv[0])
		except:
			print "guestID must be integer"
			return
	else:
		print param[3][getMyFunctionName()].__doc__
		return
	
	panel=MonitorPanel()
	
	firstRound=True
	while True:
		guestInfo=requestTo(param[0],param[1],'/guest/getCustomizedInfo?guestIDs=%s&cpu=1&memory=1&network=1&io=1'%(str(guestID)))
		dom = minidom.parseString(guestInfo)
		if firstRound:
			if getValue(dom,'guest','guestID')==None:
				print "Guest not found"
				return
			elif getValue(dom,'guest','polling')=='error':
				print "Guest is not running"
				return
			PressKeyThread().start()
			firstRound=False

		result=[('guest ID: '+getValue(dom,'guest','guestID'),' '*30)]
		result+=[('CPU Usage',getValue(dom,'average')+'%')]
		result+=[('CPU Time',getValue(dom,'cpuTime')+'ns')]

		memTotal=int(getValue(dom,'memTotal'))
		memUse=int(getValue(dom,'memUse'))
		result+=[('used memory space','%d/%d %.2f%%'%(memUse,memTotal,memUse*100.0/memTotal))]
		
		networkDom=dom.getElementsByTagName('networkInfo')[0]
		result+=[('network transmit rate',getValue(networkDom,'tx')+' bps')]
		result+=[('network recieve rate',getValue(networkDom,'rx')+' bps')]
		
		ioDom=dom.getElementsByTagName('ioInfo')[0]
		result+=[('io read rate',getValue(ioDom,'rx')+' bps')]
		result+=[('io write rate',getValue(ioDom,'wx')+' bps')]	
		
		panel.update(getTable(result))

		if len(threading.enumerate())==1:
			break
		
		time.sleep(1)
	
	print ''
コード例 #4
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def guestinfo(argv,param):
	'''Show information of a specific guest;
	Usage
		guestinfo GUEST_ID
	'''
	if len(argv)==1:
		try:
			guestID=int(argv[0])
		except:
			print "guestID must be integer."
			return
	else:
		print param[3][getMyFunctionName()].__doc__
		return
	
	guestInfo=requestTo(param[0],param[1],'/guest/getInfo?guestID=%s'%(str(guestID)))
	guestState=requestTo(param[0],param[1],'/guest/getState?guestID=%s'%(str(guestID)))
	dom = minidom.parseString(guestInfo)

	if getValue(dom,'guest','guestID')==None:
		print 'Guest not found.'
		return

	result=[('key','value')]
	result+=[
		('guest ID',getValue(dom,'guest','guestID')),
		('lastest host ID',getValue(dom,'lastHostID')),
		('guest name',getValue(dom,'guest','guestName')),
		('MAC Address',getValue(dom,'MAC')),
		('IP Address',getValue(dom,'IP')),
		('template ID',getValue(dom,'templateID')),
		('memory size',getValue(dom,'memory')),
		('virtual CPU core',getValue(dom,'vCPU')),
		('inboundBandwidth',getValue(dom,'inbound')),
		('outboundBandwidth',getValue(dom,'outbound'))
	]
	dom = minidom.parseString(guestState)
	result+=[
		('status',converter.getSimpleGuestStatus(getValue(dom,'status'),getValue(dom,'runningState'))),
		('activity',converter.guestActivity[getValue(dom,'activity')])
	]
	print getTable(result)
コード例 #5
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def hostinfo(argv,param):
	'''Show information of a specific host;
	Usage
		hostinfo HOST_ID
	'''
	if len(argv)==1:
		try:
			hostID=int(argv[0])
		except:
			print "hostID must be integer."
			return
	else:
		print param[3][getMyFunctionName()].__doc__
		return
	
	hostInfo=requestTo(param[0],param[1],'/host/getInfo?hostID=%s'%(str(hostID)))
	dom = minidom.parseString(hostInfo)
	
	if getValue(dom,'host','hostID')==None:
		print "Host not found."
		return

	result=[('key','value')]
	result+=[
		('host ID',getValue(dom,'host','hostID')),
		('host name',getValue(dom,'host','hostName')),
		('status',converter.hostStatus[getValue(dom,'status')]),
		('activity',converter.hostActivity[getValue(dom,'activity')]),
		('MAC Address',getValue(dom,'MAC')),
		('IP Address',getValue(dom,'IP')),
		('Memory size',getValue(dom,'size')),
		('CPU model',getValue(dom,'model')),
		('CPU core',getValue(dom,'number')),
		('CPU speed(MHz)',getValue(dom,'frequency')),
		('Guest Holder',converter.hostIsHost[getValue(dom,'isHost')]),
		('Global Controller',converter.hostFunction[getValue(dom,'isGlobalController')]),
		('Information Server',converter.hostFunction[getValue(dom,'isInformationServer')]),
		('NFS Server',converter.hostFunction[getValue(dom,'isNFSServer')]),
		('CA Server',converter.hostFunction[getValue(dom,'isCA')])
	]
	print getTable(result)
コード例 #6
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def templatelist(argv,param):
	'''List ID, OS and size of all template;
	'''
	templateInfo=requestTo(param[0],param[1],'/template/getInfo')
	dom = minidom.parseString(templateInfo)
	templateList=dom.getElementsByTagName('template')
	
	if len(templateList)==0:
		print "Error, template not found"
		return

	result=[('ID','OS','size')]
	
	for element in templateList:
		result.append((
			getValue(element,'template','templateID'),
			getValue(element,'OS'),
			getValue(element,'size')
		))
		
	print getTable(result)
コード例 #7
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def templateinfo(argv,param):
	'''Show information of specific template;
	Usage
		templateinfo TEMPLATE_ID
	'''
	if len(argv)==1:
		try:
			templateID=int(argv[0])
		except:
			print "templateID must be integer"
			return
	else:
		print param[3][getMyFunctionName()].__doc__
		return

	templateInfo=requestTo(param[0],param[1],'/template/getInfo?templateID=%s'%(str(templateID)))
	dom = minidom.parseString(templateInfo)
	
	if getValue(dom,'template','templateID')==None:
		print 'Template not found.'
		return

	result=[('key','value')]
	result+=[
	('template ID',getValue(dom,'template','templateID')),
	('OS',getValue(dom,'OS')),
	('minimum memory',getValue(dom,'minimumMemory')),
	('maximum memory',getValue(dom,'maximumMemory')),
	('activity',converter.templateActivity[getValue(dom,'activity')])
	]
	key='description'
	desc=getValue(dom,'description').replace('\n',' ')
	desc_width=50
	i=0
	while i<len(desc):
		result+=[(key,desc[i:i+desc_width])]
		key=''
		i+=desc_width

	print getTable(result)
コード例 #8
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def guestlist(argv,param):
	'''List ID, name and status of all guest;
	'''
	guestInfo=requestTo(param[0],param[1],'/guest/getState')
	dom = minidom.parseString(guestInfo)
	guestList=dom.getElementsByTagName('guest')
	
	if len(guestList)==0:
		print "No guest found."
		return

	result=[('ID','guest name','status','activity')]
	
	for element in guestList:
		
		result.append((
			getValue(element,'guest','guestID'),
			getValue(element,'guest','guestName'),
			converter.getSimpleGuestStatus(getValue(element,'status'),getValue(element,'runningState')),
			converter.guestActivity[getValue(element,'activity')]
		))
		
	print getTable(result)
コード例 #9
0
ファイル: shellMethod.py プロジェクト: znut/maekin-cloud
def hostlist(argv,param):
	'''List ID, name and status of all host;
	Usage:
		hostlist [OPTIONS]
	Options:
		-a for activity
		-i for IP address
		-s for service that host provide	
	'''
	optionList=tuple()
	for option in argv:
		if option=='-a':
			optionList+=('activity',)
		elif option=='-i':
			optionList+=('IP',)
		elif option=='-s':
			optionList+=('service',)
		else:
			print param[3][getMyFunctionName()].__doc__
			return

	hostInfo=requestTo(param[0],param[1],'/host/getInfo')
	dom = minidom.parseString(hostInfo)
	hostList=dom.getElementsByTagName('host')
	
	if len(hostList)==0:
		print "Error, host not found"
		return

	result=[('ID','host name','status')+optionList]
	
	for element in hostList:
		currentTuple=(
			getValue(element,'host','hostID'),
			getValue(element,'host','hostName'),
			converter.hostStatus[getValue(element,'status')],
		)
		if '-a' in argv:
			currentTuple+=(converter.hostActivity[getValue(element,'activity')],)
		if '-i' in argv:
			currentTuple+=(getValue(element,'IP'),)
		
		if '-s' in argv:
			#get list of string that make many line
			allFunction=[]
			
			if getValue(element,'isGlobalController')!='0':
				allFunction.append(converter.hostFunction[getValue(element,'isGlobalController')]+' Global Controller')
			if getValue(element,'isInformationServer')!='0':
				allFunction.append(converter.hostFunction[getValue(element,'isInformationServer')]+' Information Server')
			if getValue(element,'isNFSServer')!='0':
				allFunction.append(converter.hostFunction[getValue(element,'isNFSServer')]+' NFS Server')
			if getValue(element,'isCA')!='0':
				allFunction.append(converter.hostFunction[getValue(element,'isCA')]+' CA')

			if allFunction==[]:
				allFunction.append('None')
					
			currentTuple+=(allFunction[0],)
			result.append(currentTuple)
			
			if len(allFunction)>1:	#must add next line
				allFunction.remove(allFunction[0])
				for eachFunction in allFunction:
					result.append(('',)*(len(result[0])-1) + (eachFunction,))
				
		else:
			result.append(currentTuple)
		
	print getTable(result)