Exemple #1
0
    def launch(
        self,
        *,
        instance_name: str,
        image: str,
        cpus: str = None,
        mem: str = None,
        disk: str = None,
        remote: str = None,
    ) -> None:
        """Passthrough for running multipass launch.

        :param str instance_name: the name the launched instance will have.
        :param str image: the image to create the instance with.
        :param str cpus: amount of virtual CPUs to assign to the launched instance.
        :param str mem: amount of RAM to assign to the launched instance.
        :param str disk: amount of disk space the instance will see.
        :param str remote: the remote server to retrieve the image from.
        """
        if remote is not None:
            image = "{}:{}".format(remote, image)
        cmd = [self.provider_cmd, "launch", image, "--name", instance_name]
        if cpus is not None:
            cmd.extend(["--cpus", cpus])
        if mem is not None:
            cmd.extend(["--mem", mem])
        if disk is not None:
            cmd.extend(["--disk", disk])
        try:
            _run(cmd)
        except subprocess.CalledProcessError as process_error:
            raise errors.ProviderLaunchError(
                provider_name=self.provider_name, exit_code=process_error.returncode
            ) from process_error
Exemple #2
0
    def launch(self,
               *,
               hda: str,
               qcow2_drives: Sequence,
               project_9p_dev: str,
               ram: str = None,
               enable_kvm: bool = True) -> None:
        # TODO check for latest snapshot to launch for it instead of a cold
        #      boot.
        # TODO replace -nographic with a spinner and redirect to a log file.
        cmd = [
            "sudo",
            self.provider_cmd,
            "-m",
            ram,
            "-nographic",
            "-monitor",
            "telnet::{},server,nowait".format(self._telnet_port),
            "-hda",
            hda,
            "-fsdev",
            "local,id={},path={},security_model=none".format(
                self._PROJECT_DEV, project_9p_dev),
            "-device",
            "virtio-9p-pci,fsdev={},mount_tag={}".format(
                self._PROJECT_DEV, self._PROJECT_MOUNT),
            "-device",
            "e1000,netdev=net0",
            "-netdev",
            "user,id=net0,hostfwd=tcp::{}-:22".format(self._ssh_port),
        ]
        for drive in qcow2_drives:
            cmd.append("-drive")
            cmd.append("file={},if=virtio,format=qcow2".format(drive))
        if enable_kvm:
            cmd.append("-enable-kvm")

        # TODO we might want to spawn another thread here to keep an eye on
        #      the process. This is good enough for now.
        # TODO better encapsulation on setting the log file is needed.
        with open(".vm-builder.log", "w") as vm_builder_log:
            self._qemu_proc = _popen(cmd,
                                     stdout=vm_builder_log,
                                     stderr=vm_builder_log)
        # Check the immediate return code to make sure things haven't gone
        # wrong.
        proc_poll = self._qemu_proc.poll()
        if proc_poll is not None and proc_poll != 0:
            raise errors.ProviderLaunchError(provider_name=self.provider_name,
                                             exit_code=proc_poll)
        self._wait_for_ssh()
    def launch(self, *, instance_name: str, image: str, remote: str = None) -> None:
        """Passthrough for running multipass launch.

        :param str instance_name: the name the launched instance will have.
        :param str image: the image to create the instance with.
        :param str remote: the remote server to retrieve the image from.
        """
        if remote is not None:
            image = "{}:{}".format(remote, image)
        cmd = [self.provider_cmd, "launch", image, "--name", instance_name]
        try:
            _run(cmd)
        except subprocess.CalledProcessError as process_error:
            raise errors.ProviderLaunchError(
                provider_name=self.provider_name, exit_code=process_error.returncode
            ) from process_error