Beispiel #1
0
    def select(self, ctxt, host):
        """ select a vm in specific host and a dest host """
        nova = Nova()
        mtc = Metric()

        base_q = '''[{"field": "timestamp",
            "op": "ge",
            "value": "2016-01-20T04:30:00"},
            {"field": "timestamp",
            "op": "lt",
            "value": "2016-01-20T05:00:00"},
            {"field": "resource_id",
            "op": "eq",
            "value": "instance_id"}]'''

        instances = nova.getInstancesOnHost(host)
        cpu_avg = dict()

        for itnce in instances:
            query = base_q.replace('instance_id', itnce)
            cpu_avg[itnce] = mtc.getMeterStatistics("cpu_util", query)['avg']

	# NOTE change NOTE select most work heavy vm to migrate
	if cpu_avg:
            vm = max(cpu_avg, key=cpu_avg.get)
        else:
            vm = None

        # NOTE change NOTE select a host randomly
        hosts = nova.getComputeHosts()
        hosts.remove(host)
        dest = random.choice(hosts)
	print "select {0} on host {1} to migrate to {2}".format(vm, host, dest)

        return vm, dest
Beispiel #2
0
def monitor():
    """ monitor host status to decide whether resource reallocation """
    nova = Nova()
    while 1:
    	hosts = nova.getComputeHosts()
        for h in hosts:
	    sttcs = nova.hypervisorDetail(h)
	    if float(sttcs['mem_used']) / sttcs['mem_total'] > 0.3:
		print "host busy", ",migrate vm from ", h
	        trigger_sche(h)
	time.sleep(10)