Shuts down if running, restores the snapshot and starts VM.
761169
public void loadSnapshot(String vm, String snapshotUuid) {
        if (!EnumSet.of(POWEROFF, SAVED).contains(vmState(vm))) {
            powerOff(vm);
        }
        execute("snapshot", vm, "restore", snapshotUuid);
        start(vm);
    }
234702
def stop(self):
        

        status = yield from self.get_status()
        if status != "inactive":
            try:
                yield from self._hypervisor.send('vm stop "{name}"'.format(name=self._name))
            except DynamipsError as e:
                log.warn("Could not stop {}: {}".format(self._name, e))
            self.status = "stopped"
            log.info('Router "{name}" [{id}] has been stopped'.format(name=self._name, id=self._id))
        if self._memory_watcher:
            self._memory_watcher.close()
            self._memory_watcher = None
        yield from self.save_configs()
331567
def start(self):
        

        with (yield from self._execute_lock):
            if self.is_running():
                # resume the VM if it is paused
                yield from self.resume()
                return

            if self._manager.config.get_section_config("Qemu").getboolean("monitor", True):
                try:
                    info = socket.getaddrinfo(self._monitor_host, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
                    if not info:
                        raise QemuError("getaddrinfo returns an empty list on {}".format(self._monitor_host))
                    for res in info:
                        af, socktype, proto, _, sa = res
                        # let the OS find an unused port for the Qemu monitor
                        with socket.socket(af, socktype, proto) as sock:
                            sock.bind(sa)
                            self._monitor = sock.getsockname()[1]
                except OSError as e:
                    raise QemuError("Could not find free port for the Qemu monitor: {}".format(e))

            # check if there is enough RAM to run
            self.check_available_ram(self.ram)

            command = yield from self._build_command()
            command_string = " ".join(shlex.quote(s) for s in command)
            try:
                log.info("Starting QEMU with: {}".format(command_string))
                self._stdout_file = os.path.join(self.working_dir, "qemu.log")
                log.info("logging to {}".format(self._stdout_file))
                with open(self._stdout_file, "w", encoding="utf-8") as fd:
                    fd.write("Start QEMU with {}\n\nExecution log:\n".format(command_string))
                    self.command_line = ' '.join(command)
                    self._process = yield from asyncio.create_subprocess_exec(*command,
                                                                              stdout=fd,
                                                                              stderr=subprocess.STDOUT,
                                                                              cwd=self.working_dir)

                yield from self._start_ubridge()
                for adapter_number, adapter in enumerate(self._ethernet_adapters):
                    nio = adapter.get_nio(0)
                    if nio:
                        yield from self.add_ubridge_udp_connection("QEMU-{}-{}".format(self._id, adapter_number),
                                                                   self._local_udp_tunnels[adapter_number][1],
                                                                   nio)

                log.info('QEMU VM "{}" started PID={}'.format(self._name, self._process.pid))
                self.status = "started"
                monitor_process(self._process, self._termination_callback)
            except (OSError, subprocess.SubprocessError, UnicodeEncodeError) as e:
                stdout = self.read_stdout()
                log.error("Could not start QEMU {}: {}\n{}".format(self.qemu_path, e, stdout))
                raise QemuError("Could not start QEMU {}: {}\n{}".format(self.qemu_path, e, stdout))

            yield from self._set_process_priority()
            if self._cpu_throttling:
                self._set_cpu_throttling()

            if "-enable-kvm" in command_string:
                self._hw_virtualization = True
        try:
            yield from self.start_wrap_console()
        except OSError as e:
            raise QemuError("Could not start QEMU console {}\n".format(e))
1215239
def start(self):
        
        self._assert_not_running()
        if self._configs.clear_log:
            self.clear_adb_log()
        self._start()
50226
def shutdown(self):
        
        vm = self.get_vm_failfast(self.config['name'])

        if vm.runtime.powerState == vim.VirtualMachinePowerState.poweredOff:
            print("%s already poweredOff" % vm.name)
        else:
            if self.guestToolsRunning(vm):
                timeout_minutes = 10
                print("waiting for %s to shutdown "
                      "(%s minutes before forced powerOff)" % (
                          vm.name,
                          str(timeout_minutes)
                      ))
                vm.ShutdownGuest()
                if self.WaitForVirtualMachineShutdown(vm,
                                                      timeout_minutes * 60):
                    print("shutdown complete")
                    print("%s poweredOff" % vm.name)
                else:
                    print("%s has not shutdown after %s minutes:"
                          "will powerOff" % (vm.name, str(timeout_minutes)))
                    self.powerOff()

            else:
                print("GuestTools not running or not installed: will powerOff")
                self.powerOff()
1026501
def stop(self):
        

        vm_state = yield from self._get_state()
        if vm_state == "poweroff":
            self.running = False
            return

        yield from self._execute("controlvm", [self._vmname, "acpipowerbutton"], timeout=3)
        trial = 120
        while True:
            try:
                vm_state = yield from self._get_state()
            # During a small amount of time the command will fail
            except GNS3VMError:
                vm_state = "running"
            if vm_state == "poweroff":
                break
            trial -= 1
            if trial == 0:
                yield from self._execute("controlvm", [self._vmname, "poweroff"], timeout=3)
                break
            yield from asyncio.sleep(1)

        log.info("GNS3 VM has been stopped")
        self.running = False
405412
def reload(self):
        

        result = yield from self._control_vm("reset")
        log.info("VirtualBox VM '{name}' [{id}] reloaded".format(name=self.name, id=self.id))
        log.debug("Reload result: {}".format(result))
1111760
public void restart() {
        sync.lock();

        try {

            stop();
            Thread.sleep(1000); // allow some time to release native resources
            start();

        } catch (InterruptedException e) {
            // ignore
        } finally {
            sync.unlock();
        }
    }
295026
def auto_idlepc(self, vm):
        

        yield from vm.set_idlepc("0x0")
        was_auto_started = False
        try:
            status = yield from vm.get_status()
            if status != "running":
                yield from vm.start()
                was_auto_started = True
                yield from asyncio.sleep(20)  # leave time to the router to boot
            validated_idlepc = None
            idlepcs = yield from vm.get_idle_pc_prop()
            if not idlepcs:
                raise DynamipsError("No Idle-PC values found")

            for idlepc in idlepcs:
                match = re.search(r"^0x[0-9a-f]{8}$", idlepc.split()[0])
                if not match:
                   continue
                yield from vm.set_idlepc(idlepc.split()[0])
                log.debug("Auto Idle-PC: trying idle-PC value {}".format(vm.idlepc))
                start_time = time.time()
                initial_cpu_usage = yield from vm.get_cpu_usage()
                log.debug("Auto Idle-PC: initial CPU usage is {}%".format(initial_cpu_usage))
                yield from asyncio.sleep(3)  # wait 3 seconds to probe the cpu again
                elapsed_time = time.time() - start_time
                cpu_usage = yield from vm.get_cpu_usage()
                cpu_elapsed_usage = cpu_usage - initial_cpu_usage
                cpu_usage = abs(cpu_elapsed_usage * 100.0 / elapsed_time)
                if cpu_usage > 100:
                    cpu_usage = 100
                log.debug("Auto Idle-PC: CPU usage is {}% after {:.2} seconds".format(cpu_usage, elapsed_time))
                if cpu_usage < 70:
                    validated_idlepc = vm.idlepc
                    log.debug("Auto Idle-PC: idle-PC value {} has been validated".format(validated_idlepc))
                    break

            if validated_idlepc is None:
                raise DynamipsError("Sorry, no idle-pc value was suitable")

        except DynamipsError:
            raise
        finally:
            if was_auto_started:
                yield from vm.stop()
        return validated_idlepc
394668
def start(name, call=None):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The instance action must be called with -a or --action.'
        )

    log.info("Starting machine: %s", name)
    vb_start_vm(name)
    machine = vb_get_machine(name)
    del machine["name"]
    return treat_machine_dict(machine)
346970
@Override
    public void run() {
        try {
            shutdown();
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, "Error during shutdown", ex);
        }
    }
595632
def initiate_shutdown(self):
        
        # Windows does not provide SIGKILL, go with SIGTERM then.
        sig = getattr(signal, "SIGKILL", signal.SIGTERM)
        # reloader active
        if is_running_from_reloader():
            os.kill(os.getpid(), sig)
        # python 2.7
        self.server._BaseServer__shutdown_request = True
        # python 2.6
        self.server._BaseServer__serving = False
587394
def reboot(vm_):
    '''
    
    '''
    with _get_xapi_session() as xapi:
        vm_uuid = _get_label_uuid(xapi, 'VM', vm_)
        if vm_uuid is False:
            return False
        try:
            xapi.VM.clean_reboot(vm_uuid)
            return True
        except Exception:
            return False
1034444
void start(Future<DataPort> dataPortFuture) {
        this.startStopLock.lock();
        try {
            this.dataPortFuture = dataPortFuture;
            this.running.set(true);
            this.outgoing.resume();
            this.reconnectOutgoing.resume();
            this.stopped = connection.getExecutor().submit(this, Boolean.TRUE);
        } finally {
            this.startStopLock.unlock();
        }
    }
57472
def shutdown(self):
        ''''''
        if self._proxy:
            os.sync()
            self._proxy(*self._args)
4587
def start(name, call=None):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The start action must be called with -a or --action.'
        )

    log.info('Starting node %s', name)

    return vm_action(name, kwargs={'action': 'resume'}, call=call)
383967
def pause(vm_):
    '''
    
    '''
    with _get_xapi_session() as xapi:
        vm_uuid = _get_label_uuid(xapi, 'VM', vm_)
        if vm_uuid is False:
            return False
        try:
            xapi.VM.pause(vm_uuid)
            return True
        except Exception:
            return False