def waitForVmwareVmx(): """! Monitor vmware-vmx every 5 seconds to see if it is running """ vmx_conf_file_path = "%s/esxi.vmx" % Vsp.get_esxi_dir() proc_id = Vsp.get_vmx_proc_id(vmx_conf_file_path) while Vsp.is_process_running(proc_id): Logging.log(Logging.LOG_DEBUG, "vmware-vmx is still running") time.sleep(5) #We are here means the process has exited Logging.log(Logging.LOG_DEBUG, "vmware-vmx is not running")
def main(): """! Entry point of the wrapper, intialize logger and signal handler. Starts vmware-vmx and starts monitoring it """ Logging.log_init('vmware_vmx_wrapper', 'vmware_vmx_wrapper', 0, Logging.component_id(Logging.LCI_VSP), Logging.LOG_DEBUG, Logging.LOG_LOCAL0, Logging.LCT_SYSLOG) Logging.log(Logging.LOG_INFO, "vsp_vmware_vmx_wrapper started") signal.signal(signal.SIGINT, terminate_term_handler) signal.signal(signal.SIGTERM, terminate_term_handler) signal.signal(signal.SIGQUIT, terminate_quit_handler) signal.signal(signal.SIGUSR1, terminate_usr1_handler) #get the esxi dir esxi_dir = Vsp.get_esxi_dir() vmx_conf_file_path = "%s/%s" %(esxi_dir, ESXI_VMX_NAME) #Check if the vm configuration exists if not os.path.exists(vmx_conf_file_path): Logging.log(Logging.LOG_ERR, "VM configuration %s doesn't exist" % vmx_conf_file_path) sys.exit(1) # Check if vmware-vmx is already running. The fuction returns None if no # process_id exists or if there's multiple process_ids associated with # the vmx_conf. However, it's not possible to launch two running vmware_vmx # using the same vmx_conf. The chance this returns None b/c of multiple # process ids is almost nonexistant. proc_id = Vsp.get_vmx_proc_id(vmx_conf_file_path) #Start vmware-vmx if an instance has not been started if proc_id == None: # Clean up the "shutting down" file used for ESXi HPN dependency if os.path.exists(SHUTDOWN_MARKER): os.remove(SHUTDOWN_MARKER) cleanup_locks(esxi_dir) start_vmware_vmx(vmx_conf_file_path) #Get the new process id proc_id = Vsp.get_vmx_proc_id(vmx_conf_file_path) monitor_vmware_vmx(proc_id)
def stop_vmware_vmx(): """! Stop vmware-vmx. """ global g_shutdown_requested #We just use vmrun stop to terminate vm right now but this #will change when we handle graceful shutdown path = "%s/%s" % (Vsp.get_esxi_dir(), ESXI_VMX_NAME) Logging.log(Logging.LOG_INFO, "Stopping vm %s" % path) pobj = subprocess.Popen([vmrun_path, "stop", "%s" % path]) pobj.wait() g_shutdown_requested = True;