Пример #1
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     if ProcessUtil.process_runs(pid_filepath):
         logging.warning('Apparently, VM process is already running. '
                         'Check %s ' % pid_filepath)
         machine.change_state(VM_HAS_FAILED)
         # TODO: kill the VM?
         return
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)
     # Put info into vnc target file.
     vnc_target_path = self.get_vnc_target_path(machine)
     with open(vnc_target_path, 'w+') as vnc_target:
         try:
             cmd = get_cmd_from_ps(needle=machine.disk_filename)
         except KeyError as error:
             logger.error('Failed to find VNC port of the vm: %s' % machine)
             logger.exception(error)
             return
         match = re.search(r'-vnc localhost:(\d+)', cmd, re.MULTILINE)
         local_vnc_port = 5900 + int(match.group(1))
         # e.g 'test: localhost:5901'
         vnc_info = '%s: localhost:%s' % (machine.name, local_vnc_port)
         logger.info('Writing into VNC target file: %s' % vnc_info)
         vnc_target.write(vnc_info + "\n")
Пример #2
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     if ProcessUtil.process_runs(pid_filepath):
         logging.warning('Apparently, VM process is already running. '
                         'Check %s ' % pid_filepath)
         machine.change_state(VM_HAS_FAILED)
         # TODO: kill the VM?
         return
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)
     # Put info into vnc target file.
     vnc_target_path = self.get_vnc_target_path(machine)
     with open(vnc_target_path, 'w+') as vnc_target:
         try:
             cmd = get_cmd_from_ps(needle=machine.disk_filename)
         except KeyError as error:
             logger.error('Failed to find VNC port of the vm: %s' % machine)
             logger.exception(error)
             return
         match = re.search(r'-vnc localhost:(\d+)', cmd, re.MULTILINE)
         local_vnc_port = 5900 + int(match.group(1))
         # e.g 'test: localhost:5901'
         vnc_info = '%s: localhost:%s' % (machine.name, local_vnc_port)
         logger.info('Writing into VNC target file: %s' % vnc_info)
         vnc_target.write(vnc_info + "\n")
Пример #3
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     #output = invoke(command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     assert not ProcessUtil.process_runs(pid_filepath)
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)
Пример #4
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     #output = invoke(command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     if ProcessUtil.process_runs(pid_filepath):
         logging.warning('Apparently, VM process is already running. '
                         'Check %s ' % pid_filepath)
         machine.change_state(VM_HAS_FAILED)
         # TODO: kill the VM?
         return
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)
Пример #5
0
 def check_heartbeat(self):
     '''
     Check every pid that is tracked by picostack if the respective
     machine is actually running? If not, then stop the machine and remove
     the pid file.
     '''
     instances = VmInstance.objects.filter(current_state=VM_IS_RUNNING)
     if not instances.exists():
         logger.info('No machines are running to check the heartbeat..')
         return
     for machine in instances:
         pid_filepath = self.get_pid_file(machine)
         if ProcessUtil.process_runs(pid_filepath):
             logger.info('Heart beat of "%s" is OK - still running' %
                         machine.name)
             continue
         logging.warning('DB contains a running VM entry with no '
                         'corresponding process.')
         logging.info('Stopping the machine "%s" and removing pid files ' %
                      machine.name)
         machine.change_state(VM_IS_TERMINATING)
         self.stop_machine(machine)
Пример #6
0
 def check_heartbeat(self):
     '''
     Check every pid that is tracked by picostack if the respective
     machine is actually running? If not, then stop the machine and remove
     the pid file.
     '''
     instances = VmInstance.objects.filter(current_state=VM_IS_RUNNING)
     if not instances.exists():
         logger.info('No machines are running to check the heartbeat..')
         return
     for machine in instances:
         pid_filepath = self.get_pid_file(machine)
         if ProcessUtil.process_runs(pid_filepath):
             logger.info('Heart beat of "%s" is OK - still running' %
                         machine.name)
             continue
         logging.warning('DB contains a running VM entry with no '
                         'corresponding process.')
         logging.info('Stopping the machine "%s" and removing pid files ' %
                      machine.name)
         machine.change_state(VM_IS_TERMINATING)
         self.stop_machine(machine)