Ejemplo n.º 1
0
	def _publish_mem_info(vm):
		"""
		Publish MIN_FREE_MEM and MEM_OVER properties to the VM user template to show the values to the user
		
		Args:
		- vm: VirtualMachineInfo with the VM info.

		Return: True if the information is published successfully or False otherwise 
		"""
		template = ""
		if not vm.min_free_mem:
			template += "MIN_FREE_MEM = %d\n" % Config.MIN_FREE_MEMORY
		if not vm.mem_over_ratio:
			template += "MEM_OVER = %.2f\n" % Config.MEM_OVER
		
		# if there is nothing to update return True
		if not template:
			return True 
		
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.vm.update(ConfigONE.ONE_ID, vm.id, template, 1)
			if not success:
				logger.error("Error updating the template to show the mem info to the VM ID: %s. %s." % (vm.id, res_info))
			return success
		except:
			logger.exception("Error updating the template to show the mem info to the VM ID: %s." % vm.id)
			return False
		
		return True
Ejemplo n.º 2
0
	def _publish_mem_info(vm):
		"""
		Publish MIN_FREE_MEM and MEM_OVER properties to the VM user template to show the values to the user
		
		Args:
		- vm: VirtualMachineInfo with the VM info.

		Return: True if the information is published successfully or False otherwise 
		"""
		template = ""
		if not vm.min_free_mem:
			template += "MIN_FREE_MEM = %d\n" % Config.MIN_FREE_MEMORY
		if not vm.mem_over_ratio:
			template += "MEM_OVER = %.2f\n" % Config.MEM_OVER
		
		# if there is nothing to update return True
		if not template:
			return True 
		
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.vm.update(ConfigONE.ONE_ID, vm.id, template, 1)
			if not success:
				logger.error("Error updating the template to show the mem info to the VM ID: %s. %s." % (vm.id, res_info))
			return success
		except:
			logger.exception("Error updating the template to show the mem info to the VM ID: %s." % vm.id)
			return False
		
		return True
Ejemplo n.º 3
0
	def migrate(vm_id, host_id):
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.vm.migrate(ConfigONE.ONE_ID, vm_id, host_id, True, True)
		except:
			logger.exception("Error migrating the VM %d to the host %d" % (vm_id, host_id))
			return False
		
		if success:
			return True
		else:
			logger.error("Error migrating the VM %d to the host %d: %s" % (vm_id, host_id, res_info))
			return False
Ejemplo n.º 4
0
	def migrate(vm_id, host_id):
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.vm.migrate(ConfigONE.ONE_ID, vm_id, host_id, True, True)
		except:
			logger.exception("Error migrating the VM %d to the host %d" % (vm_id, host_id))
			return False
		
		if success:
			return True
		else:
			logger.error("Error migrating the VM %d to the host %d: %s" % (vm_id, host_id, res_info))
			return False
Ejemplo n.º 5
0
	def get_host_info(host_id):
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.host.info(ConfigONE.ONE_ID, host_id)
		except:
			logger.exception("Error getting the host info: " + host_id)
			return None
		
		if success:
			host_info = HOST(res_info)
			res_host = HostInfo(int(host_info.ID), host_info.NAME, host_info.STATE not in HOST.INVALID_STATES, host_info) 
			return res_host
		else:
			logger.error("Error getting the host info: " + res_info)
			return None
Ejemplo n.º 6
0
	def get_host_info(host_id):
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.host.info(ConfigONE.ONE_ID, host_id)
		except:
			logger.exception("Error getting the host info: " + host_id)
			return None
		
		if success:
			host_info = HOST(res_info)
			res_host = HostInfo(int(host_info.ID), host_info.NAME, host_info.STATE not in HOST.INVALID_STATES, host_info) 
			return res_host
		else:
			logger.error("Error getting the host info: " + res_info)
			return None
Ejemplo n.º 7
0
	def get_vm_list():
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			# To get only ONE_ID user's resources
			#vm_filter = -3
			# To get all
			vm_filter = -2
			(success, res_info, _) = server.one.vmpool.info(ConfigONE.ONE_ID, vm_filter, -1, -1, 3)
		except:
			logger.exception("Error getting the VM list")
			return []

		if success:
			res_vm = VM_POOL(res_info)
			res = []
			for vm in res_vm.VM:
				try:
					host = HostInfo(int(vm.HISTORY_RECORDS.HISTORY[0].HID), vm.HISTORY_RECORDS.HISTORY[0].HOSTNAME)
					new_vm = VirtualMachineInfo(int(vm.ID), host, int(vm.TEMPLATE.MEMORY) * 1024, vm)
					new_vm.user_id = vm.UID
					if vm.USER_TEMPLATE.MEM_TOTAL:
						# to make it work on all ONE versions
						real_memory = vm.TEMPLATE.REALMEMORY
						if not real_memory:
							real_memory = vm.REALMEMORY
						new_vm.set_memory_values(int(real_memory),
											int(vm.USER_TEMPLATE.MEM_TOTAL),
											int(vm.USER_TEMPLATE.MEM_FREE))
						if vm.USER_TEMPLATE.MIN_FREE_MEM:
							new_vm.min_free_mem = vm.USER_TEMPLATE.MIN_FREE_MEM
						if vm.USER_TEMPLATE.MEM_OVER:
							new_vm.mem_over_ratio = vm.USER_TEMPLATE.MEM_OVER
						if vm.USER_TEMPLATE.TIMESTAMP:
							new_vm.timestamp = vm.USER_TEMPLATE.TIMESTAMP

						# publish MEM properties to the VM user template to show the values to the user
						OpenNebula._publish_mem_info(new_vm)

					res.append(new_vm)
				except:
					logger.exception("Error getting the VM info %s." % vm.ID)
				
			return res
		else:
			logger.error("Error getting the VM list: " + res_info)
			return []
Ejemplo n.º 8
0
	def get_host_list():
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.hostpool.info(ConfigONE.ONE_ID)
		except:
			logger.exception("Error getting the host list")
			return None
		
		if success:
			res = []
			for host in HOST_POOL(res_info).HOST:
				new_host = HostInfo(host.ID, host.NAME, host.STATE not in HOST.INVALID_STATES, host)
				res.append(new_host)
			return res
		else:
			logger.error("Error getting the host list: " + res_info)
			return None
Ejemplo n.º 9
0
	def get_host_list():
		server_url = "http://%s:%d/RPC2" % (ConfigONE.ONE_SERVER, ConfigONE.ONE_PORT)
		try:
			server = ServerProxy(server_url,allow_none=True,timeout=10)
			(success, res_info, _) = server.one.hostpool.info(ConfigONE.ONE_ID)
		except:
			logger.exception("Error getting the host list")
			return None
		
		if success:
			res = []
			for host in HOST_POOL(res_info).HOST:
				new_host = HostInfo(host.ID, host.NAME, host.STATE not in HOST.INVALID_STATES, host)
				res.append(new_host)
			return res
		else:
			logger.error("Error getting the host list: " + res_info)
			return None