Best Python code snippet using lisa_python
platform.py
Source:platform.py  
...366                    self.vm_disks_dir, f"{node_context.vm_name}-data-{i}.qcow2"367                )368                data_disk.size_gib = node_space.disk.data_disk_size369                node_context.data_disks.append(data_disk)370    def _create_domain_and_attach_logger(371        self,372        libvirt_conn: libvirt.virConnect,373        node_context: NodeContext,374    ) -> None:375        # Start the VM in the paused state.376        # This gives the console logger a chance to connect before the VM starts377        # for real.378        assert node_context.domain379        node_context.domain.createWithFlags(libvirt.VIR_DOMAIN_START_PAUSED)380        # Attach the console logger381        node_context.console_logger = QemuConsoleLogger()382        node_context.console_logger.attach(383            libvirt_conn, node_context.domain, node_context.console_log_file_path384        )385        # Start the VM.386        node_context.domain.resume()387    # Create all the VMs.388    def _create_nodes(389        self,390        environment: Environment,391        log: Logger,392        lv_conn: libvirt.virConnect,393    ) -> None:394        self.host_node.shell.mkdir(Path(self.vm_disks_dir), exist_ok=True)395        for node in environment.nodes.list():396            node_context = get_node_context(node)397            self._create_node(398                node,399                node_context,400                environment,401                log,402                lv_conn,403            )404    def _create_node(405        self,406        node: Node,407        node_context: NodeContext,408        environment: Environment,409        log: Logger,410        lv_conn: libvirt.virConnect,411    ) -> None:412        # Create required directories and copy the required files to the host413        # node.414        if node_context.os_disk_source_file_path:415            source_exists = self.host_node.tools[Ls].path_exists(416                path=node_context.os_disk_base_file_path, sudo=True417            )418            if not source_exists:419                self.host_node.shell.copy(420                    Path(node_context.os_disk_source_file_path),421                    Path(node_context.os_disk_base_file_path),422                )423        # Create cloud-init ISO file.424        self._create_node_cloud_init_iso(environment, log, node)425        # Create OS disk from the provided image.426        self._create_node_os_disk(environment, log, node)427        # Create data disks428        self._create_node_data_disks(node)429        # Create libvirt domain (i.e. VM).430        xml = self._create_node_domain_xml(environment, log, node, lv_conn)431        node_context.domain = lv_conn.defineXML(xml)432        self._create_domain_and_attach_logger(433            lv_conn,434            node_context,435        )436    # Delete all the VMs.437    def _delete_nodes(self, environment: Environment, log: Logger) -> None:438        # Delete nodes.439        for node in environment.nodes.list():440            self._delete_node(node, log)441        # Delete VM disks directory.442        try:443            self.host_node.shell.remove(Path(self.vm_disks_dir), True)444        except Exception as ex:445            log.warning(f"Failed to delete VM files directory: {ex}")446    def _delete_node_watchdog_callback(self) -> None:...ch_platform.py
Source:ch_platform.py  
...129        xml = ET.tostring(domain, "unicode")130        return xml131    def _get_domain_undefine_flags(self) -> int:132        return 0133    def _create_domain_and_attach_logger(134        self,135        libvirt_conn: libvirt.virConnect,136        node_context: NodeContext,137    ) -> None:138        assert node_context.domain139        node_context.domain.createWithFlags(0)140        node_context.console_logger = QemuConsoleLogger()141        node_context.console_logger.attach(142            libvirt_conn, node_context.domain, node_context.console_log_file_path143        )144    # Create the OS disk.145    def _create_node_os_disk(146        self, environment: Environment, log: Logger, node: Node147    ) -> None:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
