예제 #1
0
def report_usage_to_placement_manager(vmid, cpu_usage, mem_usage, io_usage):

	try:
		host = get_host_name(vmid)
		domain_object = get_domain_object(vmid)
		#print domain_object
		process_action_on_current_usage(host, vmid, domain_object, float(cpu_usage), float(mem_usage), float(io_usage))	

	except Exception as e:
		print e
예제 #2
0
def report_usage_to_placement_manager(vmid, cpu_usage, mem_usage, io_usage):

    try:
        host = get_host_name(vmid)
        domain_object = get_domain_object(vmid)
        #print domain_object
        process_action_on_current_usage(host, vmid, domain_object,
                                        float(cpu_usage), float(mem_usage),
                                        float(io_usage))

    except Exception as e:
        print e
예제 #3
0
파일: virtdc.py 프로젝트: OnePaaS/virtdc
def main(argv):
	
	parser = argparse.ArgumentParser(description="an api for data centers", version='virtdc 0.1.0')
	
	subparsers = parser.add_subparsers(help='Grouped command', dest='subparser_name')

	create_parser = subparsers.add_parser('create',help='create new domain from the base image')
	create_parser.add_argument('vmid', action = 'store', help ='get the vmid')
	create_parser.add_argument('cpu', action = 'store', help ='get the cpu')
	create_parser.add_argument('memory', action = 'store', help ='get memory in KiB')
	create_parser.add_argument('maxmemory', action = 'store', help ='get maximum memory in KiB')
	create_parser.add_argument('io', action = 'store', help ='get the io in KiB')

	terminate_parser = subparsers.add_parser('terminate',help='terminate running domain')
	terminate_parser.add_argument('vmid', action = 'store', help ='get the vmid')

	list_parser = subparsers.add_parser('list',help='list running domain')
	#list_parser.add_argument('hostname', action = 'store', help ='get the host')

	dominfo_parser = subparsers.add_parser('dominfo',help='domain information')
	dominfo_parser.add_argument('vmid', action = 'store', help ='get the domain id')

	hostinfo_parser = subparsers.add_parser('hostinfo',help='host information')
	hostinfo_parser.add_argument('hostname', action = 'store', help ='get the host')

	forcemigrate_parser = subparsers.add_parser('force-migrate',help='migrate domain from source host to dest host')
	forcemigrate_parser.add_argument('vmid', action = 'store', help ='get the domain')
	forcemigrate_parser.add_argument('sourcehost', action = 'store', help ='get the source host')
	forcemigrate_parser.add_argument('desthost', action = 'store', help ='get the dest host')

	removehost_parser = subparsers.add_parser('removehost',help='remove host')
	removehost_parser.add_argument('hostname', action = 'store', help ='get the host')

	loadbalance_parser = subparsers.add_parser('loadbalance',help='loadbalance host')
	#loadbalance_parser.add_argument('hostname', action = 'store', help ='get the host')

	consolidate_parser = subparsers.add_parser('consolidate',help='consolidate host')

	addhost_parser = subparsers.add_parser('addhost',help='add new host')
	addhost_parser.add_argument('hostname', action = 'store', help ='get the host')
	addhost_parser.add_argument('cpu', action = 'store', help ='get the cpu')
	addhost_parser.add_argument('memory', action = 'store', help ='get memory in KiB')
	addhost_parser.add_argument('io', action = 'store', help ='get the io in KiB')	

	getip_parser = subparsers.add_parser('getip',help='get domain ip')
	getip_parser.add_argument('vmid', action = 'store', help ='get the domain id')

	#mail api configuration
	setsmtpserver_parser = subparsers.add_parser('setsmtpserver',help='set smtp server')
	setsmtpserver_parser.add_argument('serverip', action = 'store', help ='get the server ip')

	setfrommailaddress_parser = subparsers.add_parser('setfrommailaddress',help='set from mailaddress')
	setfrommailaddress_parser.add_argument('mailid', action = 'store', help ='get the from mail address')

	addsupportmail_parser = subparsers.add_parser('addsupportmail',help='add support mail address')
	addsupportmail_parser.add_argument('mailid', action = 'store', help ='get the mail address')

	monitorcpu_parser = subparsers.add_parser('monitorgraph',help='monitor domain usage')
	#monitorcpu_parser.add_argument('vmid', action = 'store', help ='get the domain id')

	simulate_google_data = subparsers.add_parser('simulategoogledata',help='simulate google workload in virtdc')
	#monitorcpu_parser.add_argument('vmid', action = 'store', help ='get the domain id')

	args = parser.parse_args()

	if args.subparser_name == 'create':
		#print 'Call create vm_submit job'
		vmid =args.vmid
		cpu = args.cpu
		memory = args.memory
		max_memory = args.maxmemory
		io = args.io
		create_vm(vmid, cpu, memory, max_memory, io)
		
	elif args.subparser_name == 'terminate':
		#print 'Call vm_terminate job'
		vmid = args.vmid
		host_name = get_host_name(vmid)
		if host_name == None:
			print 'The requested domain '+str(vmid) +' cannot be terminated'
		else:
			print 'Host Name : '+str(host_name)
			vm_termination = terminate_guest(host_name, vmid)
			if vm_termination is False:
				print 'The requested domain '+str(vmid) +' cannot be terminated'
			else:
				print 'The requested domain '+str(vmid) +' terminated successfully'
		
	elif args.subparser_name == 'list':
		#print 'Call vm_list'
		list_host_domain_information()
	elif args.subparser_name == 'dominfo':
		#print 'Call vm_dominfo'
		vmid = args.vmid
		show_domain_info(vmid)
	elif args.subparser_name == 'hostinfo':
		#print 'Call vm_hostinfo'
		host_name = args.hostname
		dom_info = show_host_info(host_name)
		if dom_info == False:
			print 'Host name not found/not configured to this cluster'
	# Python argparse Namespace of '-' will be converted to '_'
	elif args.subparser_name == 'force-migrate':
		#print 'Call vm_migrate'
		#print args
		vmid = args.vmid
		source_host = args.sourcehost
		dest_host = args.desthost
		force_migrate(vmid, source_host, dest_host)
	elif args.subparser_name == 'removehost':
		print 'Call host_removehost'
	elif args.subparser_name == 'loadbalance':
		result = load_balance()
		if result is True:
			print 'load balance completes'
		else:
			print 'load balance failed!'
	elif args.subparser_name == 'consolidate':
		result = consolidate()
		if result is True:
                        print 'consolidate completes'
                else:
                        print 'consolidate failed!'
	elif args.subparser_name == 'addhost':
		print 'Call vm_addhost'
		#Add entry to nodeinfo XML and then run Host_Info_Tracker.py
		#So from next new domain creation will consider this space
		
	elif args.subparser_name == 'monitorgraph':
		#print 'Call vm_monitorgraph'
		#vmid = args.vmid
		monitorgraph()
	elif args.subparser_name == 'simulategoogledata':
		#print 'Call vm_monitorgraph'
		#vmid = args.vmid
		#print 'Test'		
		try:
        		simulate_data()
    		except KeyboardInterrupt:
        		print "\n[Terminate]: Keyboard interrupted, running termination killing process..."
        		os.system("/var/lib/virtdc/setup/kill_after_terminate.py")
		
	elif args.subparser_name == 'getip':
		vmid = args.vmid
		ip_addr = get_ip(vmid)
		if ip_addr is None:
			print  'IP address not found'
		else:
			print ip_addr

	elif args.subparser_name == 'list':
		print 'Call vm_list'
	elif args.subparser_name == 'list':
		print 'Call vm_list'
	elif args.subparser_name == 'list':
		print 'Call vm_list'
	elif args.subparser_name == 'list':
		print 'Call vm_list'
	elif args.subparser_name == 'list':
		print 'Call vm_list'
	else:
		a=0