Exemplo n.º 1
0
def getCloudInfo(midIP):
	text = rUrl(midIP+':8080'+'/cloud/getInfo')
	if text.count('403 Forbidden') != 0:
		return 'Host is forbidden'
	elif not text.startswith('error') and  text != '':
		cloud_info = {}
		c = getXML(text,'content')[0]
		cloud_info['UUID'] = str(getXMLVal(c,'UUID'))
		cloud_info['name'] = str(getXMLVal(c,'name'))
		net = getXML(c,'network')[0]
		cloud_info['networkID'] = str(net.attributes['id'].value)
		cloud_info['mask'] = str(net.attributes['mask'].value)
		cloud_info['defaultRoute'] = str(net.attributes['defaultRoute'].value)
		if(str(getXMLVal(c,'dns')) != ''):
			cloud_info['dnsPool'] = str(getXMLVal(c,'dns')).split(',')
		else:
			cloud_info['dnsPool'] = []
		if(str(getXMLVal(c,'guest')) != ''):
			cloud_info['guestPool'] = str(getXMLVal(c,'guest')).split(',')
		else:
			cloud_info['guestPool'] = []
		cloud_info['automode'] = str(getXMLVal(c,'autoMode'))
		return cloud_info
	else:
		return 'Not found Cloud API'
Exemplo n.º 2
0
def setHostLogDetail(data):
	xml = getXML(data,'task')[0]
	taskID = int(xml.attributes['taskID'].value)
	log = HostLog.objects.get(taskID=taskID)
	x = int(getXMLVal(xml,'status'))
	log.status = ['queued','working','finish'][x]
	currentfinishStatus = ['None','success','error'][int(getXMLVal(xml,'finishStatus'))]
	if log.action == 'host_add':
		if log.status == 'finish' and currentfinishStatus == 'success':
			log.hostID = int(getXML(data,'host')[0].attributes['hostID'].value)
	log.startTime = str(getXMLVal(xml,'createTimestamp'))
	log.finishTime = str(getXMLVal(xml,'finishTimestamp'))
	log.finishMessage = str(getXMLVal(xml,'finishMessage'))
	if currentfinishStatus == 'error':
		log.error = True
	elif currentfinishStatus == 'success':
		log.error = False
	log.save()
	return log
Exemplo n.º 3
0
def setVMLogDetail(data):
	xml = getXML(data,'task')[0]
	taskID = int(xml.attributes['taskID'].value)
	log = VMLog.objects.get(taskID=taskID)
	x = int(getXMLVal(xml,'status'))
	log.status = ['queued','working','finish'][x]
	currentfinishStatus = ['None','success','error'][int(getXMLVal(xml,'finishStatus'))]
	if log.action == 'create':
		if log.status == 'finish' and currentfinishStatus == 'success':
			log.vmImageID = int(getXML(data,'guest')[0].attributes['guestID'].value)
			if get_or_none(VM,imageID=int(getXML(data,'guest')[0].attributes['guestID'].value)) == None:
				recordNewVMtoDB(getVMinfo(log.vmImageID),log.viID)
	log.startTime = str(getXMLVal(xml,'createTimestamp'))
	log.finishTime = str(getXMLVal(xml,'finishTimestamp'))
	log.finishMessage = str(getXMLVal(xml,'finishMessage'))
	if currentfinishStatus == 'error':
		log.error = True
	elif currentfinishStatus == 'success':
		log.error = False
	log.save()
	return log
Exemplo n.º 4
0
def getTemplate(temID=''):
	if temID == '':
		text = cloud_rURL("/template/getInfo")
		template_list = []
		if text.startswith('error') or text == '':
			return ''
		for a in getXML(text,'template'):
			template = {}
			template['id'] = str(a.attributes['templateID'].value)
			template['OS'] = str(getXMLVal(a,'OS'))
			if 'windows' in str.lower(template['OS']):
				template['ostype'] = 'windows'
			elif 'centos' in str.lower(template['OS']):
				template['ostype'] = 'centos'
			elif 'ubuntu' in str.lower(template['OS']):
				template['ostype'] = 'ubuntu'
			elif 'linux' in str.lower(template['OS']):
				template['ostype'] = 'linux'
			else:
				template['ostype'] = 'OS'
			template['description'] = str(getXMLVal(a,'description'))
			template['minimumMemory'] = str(getXMLVal(a,'minimumMemory'))
			template['maximumMemory'] = str(getXMLVal(a,'maximumMemory'))
			template_list.append(template)
			if len(Template.objects.filter(templateID=template['id']))==0:
				newTem = Template.objects.create(OS=template['OS'],templateID=template['id'],description=template['description'],minMem =template['minimumMemory'],maxMem=template['maximumMemory'],ostype=template['ostype'])
				VI.objects.get(id=0).template.add(newTem)
		return template_list
	else:
		text = cloud_rURL("/template/getInfo?templateID="+temID)
		a = getXML(text,'template')[0]
		template = {}
		template['id'] = str(a.attributes['templateID'].value)
		template['OS'] = str(getXMLVal(a,'OS'))
		if 'windows' in str.lower(template['OS']):
			template['ostype'] = 'windows'
		elif 'centos' in str.lower(template['OS']):
			template['ostype'] = 'centos'
		elif 'ubuntu' in str.lower(template['OS']):
			template['ostype'] = 'ubuntu'
		elif 'linux' in str.lower(template['OS']):
			template['ostype'] = 'linux'
		else:
			template['ostype'] = 'OS'
		template['description'] = str(getXMLVal(a,'description'))
		template['minimumMemory'] = str(getXMLVal(a,'minimumMemory'))
		template['maximumMemory'] = str(getXMLVal(a,'maximumMemory'))
		return template
Exemplo n.º 5
0
def getHostStat(targetHostID=''):
	hostListStat = []
	if targetHostID == '':
		alldata = cloud_rURL('/host/getAllCurrentInfo')
	else:
		alldata = cloud_rURL('/host/getAllCurrentInfo?hostID='+targetHostID)
	for data in getXML(alldata,'host'):
		hostID = str(data.attributes['hostID'].value)
		if  str(data.attributes['polling'].value) == 'success':
			hostStat= {}
			hostStat['hostID'] = hostID
			hostStat['cpuAverage'] 	= str(getXMLVal(getXML(data,'cpuInfo')[0],'average'))
			hostStat['memTotal'] 	= str(getXMLVal(getXML(data,'memoryInfo')[0],'memTotal'))
			hostStat['memFree'] 	= str(getXMLVal(getXML(data,'memoryInfo')[0],'memFree'))
			hostStat['netRX'] 	= str(getXMLVal(getXML(data,'networkInfo')[0],'rx'))
			hostStat['netTX'] 	= str(getXMLVal(getXML(data,'networkInfo')[0],'tx'))
			hostStat['storageCap'] 	= str(getXMLVal(getXML(data,'storageInfo')[0],'capacity'))
			hostStat['storageFree'] 	= str(getXMLVal(getXML(data,'storageInfo')[0],'free'))
			hostStat['storageMaekinUsage'] 	= str(getXMLVal(getXML(data,'storageInfo')[0],'maekinUsage'))
			hostStat['storageImageUsage'] 	= str(getXMLVal(getXML(data,'storageInfo')[0],'imageUsage'))
			hostListStat.append(hostStat)
	return hostListStat
Exemplo n.º 6
0
def extractHostInfo(a):
	hostinfo = {}
	hostinfo['id'] = str(a.attributes['hostID'].value)
	hostinfo['hostName'] = str(a.attributes['hostName'].value)
	hostinfo['status'] = ['shutoff','running','suspended'][int(getXMLVal(a,'status'))]
	hostinfo['activity'] = ['None','preparing to shutdown','booting','preparing to suspend','waking up'][int(getXMLVal(a,'activity'))]
	hostinfo['MAC'] = str(getXMLVal(a,'MAC'))
	hostinfo['IP'] = str(getXMLVal(a,'IP'))
	hostinfo['isHost'] = ['no','yes'][int(getXMLVal(a,'isHost'))]
	hostinfo['isGlobalController'] = ['no','master','slave'][int(getXMLVal(a,'isGlobalController'))]
	hostinfo['isInformationServer'] = ['no','master','slave'][int(getXMLVal(a,'isInformationServer'))]
	hostinfo['isNFSServer'] =['no','master','slave'][int(getXMLVal(a,'isNFSServer'))]
	hostinfo['isCA'] = str(getXMLVal(a,'isCA'))
	hostinfo['mem_size'] = str(getXMLVal(a,'size'))
	hostinfo['mem_type'] = str(getXMLVal(a,'type'))
	hostinfo['mem_speed'] = str(getXMLVal(a,'speed'))
	hostinfo['cpu_model'] = str(getXMLVal(a,'model'))
	hostinfo['cpu_number'] = str(getXMLVal(a,'number'))
	hostinfo['cpu_freq'] = str(getXMLVal(a,'frequency'))
	hostinfo['cpu_cache'] = str(getXMLVal(a,'cache'))
	return hostinfo
Exemplo n.º 7
0
def getVMStat(vmlist,getCPU,getMEM,getNET,getIO):
	vmListStat = []
	alldata = cloud_rURL('/guest/getCustomizedInfo?cpu='+getCPU+'&memory='+getMEM+'&network='+getNET+'&io='+getIO+'&guestIDs='+vmlist)
	for data in getXML(alldata,'guest'):
		vmID = int(data.attributes['guestID'].value)
		if  str(data.attributes['polling'].value) == 'success':
			vmStat = {}
			vmStat['vmID'] = vmID
			if getCPU == '1':
				vmStat['cpuAverage'] 	= str(getXMLVal(getXML(data,'cpuInfo')[0],'average'))
				vmStat['cpuCpuTime'] 	= str(getXMLVal(getXML(data,'cpuInfo')[0],'cpuTime'))
			if getMEM == '1':
				vmStat['memTotal'] 	= str(getXMLVal(getXML(data,'memoryInfo')[0],'memTotal'))
				vmStat['memUse'] 	= str(getXMLVal(getXML(data,'memoryInfo')[0],'memUse'))
			if getNET == '1':
				vmStat['netRX'] 	= str(getXMLVal(getXML(data,'networkInfo')[0],'rx'))
				vmStat['netTX'] 	= str(getXMLVal(getXML(data,'networkInfo')[0],'tx'))
				vmStat['netSumRx'] 	= str(getXMLVal(getXML(data,'networkInfo')[0],'sumRx'))
				vmStat['netSumTx'] 	= str(getXMLVal(getXML(data,'networkInfo')[0],'sumTx'))
			if getIO == '1':
				vmStat['ioRX'] 	= str(getXMLVal(getXML(data,'ioInfo')[0],'rx'))
				vmStat['ioTX'] 	= str(getXMLVal(getXML(data,'ioInfo')[0],'wx'))
				vmStat['ioSumRx'] 	= str(getXMLVal(getXML(data,'ioInfo')[0],'sumRx'))
				vmStat['ioSumTx'] 	= str(getXMLVal(getXML(data,'ioInfo')[0],'sumWx'))
			vmListStat.append(vmStat)
	return vmListStat
Exemplo n.º 8
0
def extractVMInfo(a):
	imageID = int(a.attributes['guestID'].value)
	name 	= str(a.attributes['guestName'].value)
	hostid 	= str(getXMLVal(a,'lastHostID'))
	uuid 	= str(getXMLVal(a,'lastUUID'))
	MAC 	= str(getXMLVal(a,'MAC'))
	IP 		= str(getXMLVal(a,'IP'))
	template = str(getXMLVal(a,'templateID'))
	memory 	= str(int(getXMLVal(a,'memory'))/1024/1024)
	vCPU 	= str(getXMLVal(a,'vCPU'))
	inbound = str(getXMLVal(a,'inbound'))
	outbound = str(getXMLVal(a,'outbound'))
	vm 		= {'imageID':imageID,'name':name,'hostid':hostid,'uuid':uuid,'MAC':MAC,'IP':IP,'template':template,'vCPU':vCPU,'memory':memory,'inbound':inbound,'outbound':outbound}
	text2 = cloud_rURL('/guest/getState?guestID='+str(imageID))
	guestRaw = getXML(text2,'guest')
	if len(guestRaw) > 0:
		b = guestRaw[0]
		vm['status'] = ['shutoff','on','saved'][int(getXMLVal(b,'status'))]
		vm['activity'] = ['none','cloning','booting','saveing','restoring'][int(getXMLVal(b,'activity'))]
		vm['runningState'] = ['none','running','out of memory','paused','shutting down','shutoff','crashed'][int(getXMLVal(b,'runningState'))]
		vmobj = get_or_none(VM,imageID=imageID)
		if not vmobj == None:
			vm['ownerVI'] = VM.objects.get(imageID=imageID).ownerVI.id
		else:
			vm['ownerVI'] = 0
		return vm
	else:
		return None