def processMonitoring(monitoring):

        for action in monitoring.action:
            server = action.server
            try:
                dispatcher = MonitoringDispatcher.__getMonitoringDispatcher(
                    server.virtualization_type)
            except Exception as e:
                XmlRpcClient.sendAsyncMonitoringActionStatus(
                    action.id, "FAILED", str(e))
                MonitoringDispatcher.logger.error(str(e))
                return

            try:
                #Send async notification
                XmlRpcClient.sendAsyncMonitoringActionStatus(
                    action.id, "ONGOING", "")
                MonitoringDispatcher.logger.debug("After sending ongoing")
                MonitoringDispatcher.__dispatchAction(dispatcher, action,
                                                      server)
            except Exception as e:
                MonitoringDispatcher.logger.error(str(e))
                try:
                    if "No route to host" in str(e):
                        from settings.settingsLoader import VTAM_IP, VTAM_PORT, XMLRPC_USER, XMLRPC_PASS
                        MonitoringDispatcher.logger.error(
                            "Agent cannot reach the VT AM server. Please check that the following settings are correct: https://%s:%s@%s:%s"
                            % (XMLRPC_USER, XMLRPC_PASS, VTAM_IP, VTAM_PORT))
                except:
                    pass
                raise e
Example #2
0
	def processMonitoring(monitoring):

		for action in monitoring.action:
			server = action.server
			try:
				dispatcher = MonitoringDispatcher.__getMonitoringDispatcher(server.virtualization_type)	
			except Exception as e:
				XmlRpcClient.sendAsyncMonitoringActionStatus(action.id,"FAILED",str(e))
				MonitoringDispatcher.logger.error(str(e))	
				return

			try:
				#Send async notification
				XmlRpcClient.sendAsyncMonitoringActionStatus(action.id,"ONGOING","")
				MonitoringDispatcher.logger.debug("After sending ongoing")	
				MonitoringDispatcher.__dispatchAction(dispatcher,action,server)	
			except Exception as e:
				MonitoringDispatcher.logger.error(str(e))	
				try:
					if "No route to host" in str(e):
						from settings.settingsLoader import VTAM_IP, VTAM_PORT, XMLRPC_USER, XMLRPC_PASS
						MonitoringDispatcher.logger.error("Agent cannot reach the VT AM server. Please check that the following settings are correct: https://%s:%s@%s:%s" % (XMLRPC_USER, XMLRPC_PASS, VTAM_IP, VTAM_PORT))
				except:
					pass
				raise e
Example #3
0
    def processProvisioning(provisioning):
        for action in provisioning.action:
            vm = action.server.virtual_machines[0]
            try:
                dispatcher = ProvisioningDispatcher.__getProvisioningDispatcher(
                    vm.virtualization_type)
            except Exception as e:
                XmlRpcClient.sendAsyncProvisioningActionStatus(
                    action.id, "FAILED", str(e))
                ProvisioningDispatcher.logger.error(str(e))
                return

            try:
                #Acquire VM lock
                VmMutexStore.lock(vm)
                #Send async notification
                XmlRpcClient.sendAsyncProvisioningActionStatus(
                    action.id, "ONGOING", "")

                ProvisioningDispatcher.__dispatchAction(dispatcher, action, vm)
            except Exception as e:
                ProvisioningDispatcher.logger.error(str(e))
                raise e
            finally:
                #Release VM lock
                VmMutexStore.unlock(vm)
	def listActiveVMs(vmid, server):
		try:		
			doms = KVMManager.retrieveActiveDomainsByUUID()
			XmlRpcClient.sendAsyncMonitoringActiveVMsInfo(vmid, "SUCCESS", doms, server)
		except Exception as e:
			# Send async notification
			XmlRpcClient.sendAsyncMonitoringActionStatus(vmid, "FAILED", str(e))
			KVMMonitoringDispatcher.logger.error(str(e))
		return
Example #5
0
	def listActiveVMs(id,server):
		try:		
			doms = XendManager.retrieveActiveDomainsByUUID()
			XmlRpcClient.sendAsyncMonitoringActiveVMsInfo(id,"SUCCESS",doms,server)

		except Exception as e:
			#Send async notification
			XmlRpcClient.sendAsyncMonitoringActionStatus(id,"FAILED",str(e))
			XenMonitoringDispatcher.logger.error(str(e))
			return
Example #6
0
def LifeCycleEventCallbacks (conn, dom, event, detail, opaque):
    liblog = open('/opt/ofelia/oxa/log/libvirtmonitor.log','a')
    log =  "Libvirt Monitoring: Domain %s(%s) with uuid %s  %s %s\n" % (dom.name(), dom.ID(),
								        dom.UUIDString(),
                                                                        eventToString(event),
                                                                        detailToString(event, detail))
    liblog.write(log)
    try:
    	XmlRpcClient.sendAsyncMonitoringLibvirtVMsInfo('callback','SUCCESS',[[dom.UUIDString(),dom.name()]],eventToString(event)) 
    except Exception as e:
	raise e
Example #7
0
def LifeCycleEventCallbacks(conn, dom, event, detail, opaque):
    liblog = open('/opt/ofelia/oxa/log/libvirtmonitor.log', 'a')
    log = "Libvirt Monitoring: Domain %s(%s) with uuid %s  %s %s\n" % (
        dom.name(), dom.ID(), dom.UUIDString(), eventToString(event),
        detailToString(event, detail))
    liblog.write(log)
    try:
        XmlRpcClient.sendAsyncMonitoringLibvirtVMsInfo(
            'callback', 'SUCCESS',
            [[dom.UUIDString(), dom.name()]], eventToString(event))
    except Exception as e:
        raise e
	def stopVM(id,vm):
		try:
			#Just try to stop
			XendManager.stopDomain(vm)
	
			XenProvisioningDispatcher.logger.info("VM named "+vm.name+" has been stopped.")
			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"SUCCESS","")
		except Exception as e:
			XenProvisioningDispatcher.logger.error(str(e))
			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"FAILED",str(e))
			return
Example #9
0
    def createVMfromImage(id, vm):
        pathToMountPoint = ""
        XenProvisioningDispatcher.logger.info(
            "Initiating creation process for VM: " + vm.name +
            " under project: " + vm.project_id + " and slice: " + vm.slice_id)
        try:
            #Clone HD
            HdManager.clone(vm)
            XenProvisioningDispatcher.logger.debug("HD cloned successfully...")

            #Mount copy
            pathToMountPoint = HdManager.mount(vm)
            XenProvisioningDispatcher.logger.debug("Mounting at:" +
                                                   pathToMountPoint)
            XenProvisioningDispatcher.logger.debug(
                "HD mounted successfully...")

            #Configure VM OS
            VMConfigurator.configureVmDisk(vm, pathToMountPoint)

            #Umount copy
            HdManager.umount(vm, pathToMountPoint)
            XenProvisioningDispatcher.logger.debug(
                "HD unmounted successfully...")

            #Synthesize config file
            VMConfigurator.createVmConfigurationFile(vm)
            XenProvisioningDispatcher.logger.debug(
                "XEN configuration file created successfully...")

            XenProvisioningDispatcher.logger.info("Creation of VM " + vm.name +
                                                  " has been successful!!")
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(id, "SUCCESS", "")
        except Exception as e:
            XenProvisioningDispatcher.logger.error(str(e))
            #Send async notification
            try:
                HdManager.umount(vm, pathToMountPoint)
            except:
                pass
            try:
                #Delete VM disc and conf file if the error is not due because
                #the VM already exists
                if not isinstance(e, VMalreadyExists):
                    XenProvisioningDispatcher.deleteVM(id, vm)
            except:
                pass
            XmlRpcClient.sendAsyncProvisioningActionStatus(
                id, "FAILED", str(e))
            return
	def hardStopVM(vmid, vm):
		try:
			# First stop domain
			KVMManager.stopDomain(vm)	
			HdManager.stopHook(vm)	
		
			KVMProvisioningDispatcher.logger.info("VM named " + vm.name + " has been stopped.")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		return
	def rebootVM(vmid, vm):
		try:
			# Just try to reboot
			HdManager.rebootHook(vm)
			KVMManager.rebootDomain(vm)
	
			KVMProvisioningDispatcher.logger.info("VM named " + vm.name + " has been rebooted.")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		return
Example #12
0
    def stopVM(id, vm):
        try:
            #Just try to stop
            XendManager.stopDomain(vm)

            XenProvisioningDispatcher.logger.info("VM named " + vm.name +
                                                  " has been stopped.")
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(id, "SUCCESS", "")
        except Exception as e:
            XenProvisioningDispatcher.logger.error(str(e))
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(
                id, "FAILED", str(e))
            return
	def createVMfromImage(vmid, vm):
		KVMProvisioningDispatcher.logger.info("XXX createVMfromImage start")
		pathToMountPoint = ""	
		KVMProvisioningDispatcher.logger.info("Initiating creation process for VM: " + vm.name
											+ " under project: " + vm.project_id
											+ " and slice: " + vm.slice_id)
		try:
			# Clone HD
			HdManager.clone(vm)
			KVMProvisioningDispatcher.logger.debug("HD cloned successfully...")
			
			# Mount copy
			pathToMountPoint = HdManager.mount(vm)
			KVMProvisioningDispatcher.logger.debug("Mounting at: " + pathToMountPoint)
			KVMProvisioningDispatcher.logger.debug("HD mounted successfully...")
			
			# Configure VM OS
			VMConfigurator.configureVmDisk(vm, pathToMountPoint)

			# Umount copy
			HdManager.umount(vm, pathToMountPoint)
			KVMProvisioningDispatcher.logger.debug("HD unmounted successfully...")
	
			# Synthesize config file
			VMConfigurator.createVmConfigurationFile(vm)
			KVMProvisioningDispatcher.logger.debug("KVM configuration file created successfully...")
			
			KVMProvisioningDispatcher.logger.info("Creation of VM " + vm.name + " has been successful!!")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			KVMProvisioningDispatcher.logger.error(traceback.format_exc())
			# Send async notification
			try:
				HdManager.umount(vm, pathToMountPoint)
			except:
				pass
			try:
				# Delete VM disc and conf file if the error is not due because
				# the VM already exists
				if not isinstance(e, VMalreadyExists):
					KVMProvisioningDispatcher.deleteVM(vmid, vm)
			except:
				pass
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		KVMProvisioningDispatcher.logger.info("XXX createVMfromImage end")
		return
	def startVM(vmid, vm):
		KVMProvisioningDispatcher.logger.info("XXX startVM start")
		try:
			# Trigger	
			HdManager.startHook(vm)	
			KVMManager.startDomain(vm)
	
			KVMProvisioningDispatcher.logger.info("VM named " + vm.name + " has been started.")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		KVMProvisioningDispatcher.logger.info("XXX startVM end")
		return
	def deleteVM(id,vm):
		try:
			try:
				#if it wasn't stopped, do it
				XendManager.stopDomain(vm)	
			except Exception as e:
				pass
			
			#Trigger Hd Deletion in Remote	
			HdManager.delete(vm)	

			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"SUCCESS","")
		except Exception as e:
			XenProvisioningDispatcher.logger.error(str(e))
			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"FAILED",str(e))
			return
Example #16
0
    def deleteVM(id, vm):
        try:
            try:
                #if it wasn't stopped, do it
                XendManager.stopDomain(vm)
            except Exception as e:
                pass

            #Trigger Hd Deletion in Remote
            HdManager.delete(vm)

            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(id, "SUCCESS", "")
        except Exception as e:
            XenProvisioningDispatcher.logger.error(str(e))
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(
                id, "FAILED", str(e))
            return
Example #17
0
	def processMonitoring(monitoring):

		for action in monitoring.action:
			server = action.server
			try:
				dispatcher = MonitoringDispatcher.__getMonitoringDispatcher(server.virtualization_type)	
			except Exception as e:
				XmlRpcClient.sendAsyncMonitoringActionStatus(action.id,"FAILED",str(e))
				MonitoringDispatcher.logger.error(str(e))	
				return

			try:
				#Send async notification
				XmlRpcClient.sendAsyncMonitoringActionStatus(action.id,"ONGOING","")
				MonitoringDispatcher.logger.debug("After sending ongoing")	
				MonitoringDispatcher.__dispatchAction(dispatcher,action,server)	
			except Exception as e:
				MonitoringDispatcher.logger.error(str(e))	
				raise e
Example #18
0
	def processProvisioning(provisioning):
		for action in provisioning.action:
			vm = action.server.virtual_machines[0]
			try:
				dispatcher = ProvisioningDispatcher.__getProvisioningDispatcher(vm.virtualization_type)	
			except Exception as e:
				XmlRpcClient.sendAsyncProvisioningActionStatus(action.id,"FAILED",str(e))
				ProvisioningDispatcher.logger.error(str(e))	
				return

			try:
				#Acquire VM lock
				VmMutexStore.lock(vm)
				#Send async notification
				XmlRpcClient.sendAsyncProvisioningActionStatus(action.id,"ONGOING","")
	
				ProvisioningDispatcher.__dispatchAction(dispatcher,action,vm)	
			except Exception as e:
				ProvisioningDispatcher.logger.error(str(e))
				raise e
			finally:
				#Release VM lock
				VmMutexStore.unlock(vm)