Beispiel #1
0
	def select_host_to_migrate(self, vm_info):
		"""
		Get the ID of the HOST to migrate. It selects the HOST with more free memory.
		If no node has enough memory or cpus to host the VM to migrate, return None.
		"""
		host_list = self.cmp.get_host_list()
		
		hosts_mem = {} 
		# Select the node with more memory free
		for host in host_list:
			hosts_mem[host] = host.raw.HOST_SHARE.FREE_MEM
		
		hosts_mem = sorted(hosts_mem.items(), key=lambda x: x[1], reverse = True)
		
		cpus = vm_info.raw.TEMPLATE.CPU
		if vm_info.total_memory:
			free_memory = vm_info.total_memory
		else:
			# If the monitored total memory is not available use the CMP original allocated one 
			free_memory = vm_info.allocated_memory

		powered = None
		while powered != False:
			for host, host_mem in hosts_mem:
				# ONE FREE_CPU is a Percentage
				host_free_cpus = host.raw.HOST_SHARE.FREE_CPU/100
				if host.active and host_mem > free_memory and host_free_cpus > cpus:
					return host
			
			# only try to poweron a host once
			if powered is None:
				# Let's try to power on a host
				powered = Monitor.power_on_host(free_memory, cpus)
			else:
				# otherwise continue
				powered = False
		
		return None
Beispiel #2
0
	def select_host_to_migrate(self, vm_info):
		"""
		Get the ID of the HOST to migrate. It selects the HOST with more free memory.
		If no node has enough memory or cpus to host the VM to migrate, return None.
		"""
		host_list = self.cmp.get_host_list()
		
		hosts_mem = {} 
		# Select the node with more memory free
		for host in host_list:
			hosts_mem[host] = host.raw.HOST_SHARE.FREE_MEM
		
		hosts_mem = sorted(hosts_mem.items(), key=lambda x: x[1], reverse = True)
		
		cpus = vm_info.raw.TEMPLATE.CPU
		if vm_info.total_memory:
			free_memory = vm_info.total_memory
		else:
			# If the monitored total memory is not available use the CMP original allocated one 
			free_memory = vm_info.allocated_memory

		powered = None
		while powered != False:
			for host, host_mem in hosts_mem:
				# ONE FREE_CPU is a Percentage
				host_free_cpus = host.raw.HOST_SHARE.FREE_CPU/100
				if host.active and host_mem > free_memory and host_free_cpus > cpus:
					return host
			
			# only try to poweron a host once
			if powered is None:
				# Let's try to power on a host
				powered = Monitor.power_on_host(free_memory, cpus)
			else:
				# otherwise continue
				powered = False
		
		return None
Beispiel #3
0
	def __init__(self, cmpo = None):
		Monitor.__init__(self, OpenNebula())
Beispiel #4
0
	def __init__(self, cmpo = None):
		Monitor.__init__(self, OpenNebula())