-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactoring
- Loading branch information
Showing
34 changed files
with
742 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Python lint | ||
|
||
on: | ||
- pull_request | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install Ruff | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install ruff | ||
- name: Run Ruff | ||
run: | | ||
ruff check . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
from VBoxWrapper import VirtualMachine | ||
|
||
from frameworks.decorators import vm_is_turn_on | ||
from .vm_data import VmData | ||
from .configs import VmConfig | ||
|
||
|
||
class VboxMachine: | ||
|
||
def __init__(self, name: str, config_path: str = None): | ||
self.vm_config = VmConfig(config_path=config_path) | ||
self.vm = VirtualMachine(name) | ||
self.name = name | ||
self.data = None | ||
|
||
@vm_is_turn_on | ||
def create_data(self): | ||
self.data = VmData( | ||
ip=self.vm.network.get_ip(), | ||
user=self.vm.get_logged_user(), | ||
name=self.name, | ||
local_dir=self.vm.get_parameter('CfgFile') | ||
) | ||
|
||
def run(self, headless: bool = True, status_bar: bool = False, timeout: int = 600): | ||
if self.vm.power_status(): | ||
self.vm.stop() | ||
|
||
self.vm.snapshot.restore() | ||
self.configurate() | ||
self.vm.run(headless=headless) | ||
self.vm.network.wait_up(status_bar=status_bar, timeout=timeout) | ||
self.vm.wait_logged_user(status_bar=status_bar, timeout=timeout) | ||
self.create_data() | ||
|
||
def configurate(self): | ||
self.vm.set_cpus(self.vm_config.cpus) | ||
self.vm.nested_virtualization(self.vm_config.nested_virtualization) | ||
self.vm.set_memory(self.vm_config.memory) | ||
self.vm.audio(self.vm_config.audio) | ||
self.vm.speculative_execution_control(self.vm_config.speculative_execution_control) | ||
|
||
def stop(self): | ||
self.vm.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
from .VboxMachine import VboxMachine | ||
from .configs import VmConfig | ||
|
||
__all__ = [VboxMachine, VmConfig] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from .vm_config import VmConfig | ||
|
||
__all__ = [VmConfig] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
from rich import print | ||
from pydantic import BaseModel, conint | ||
from host_tools import singleton | ||
|
||
|
||
class SystemConfigModel(BaseModel): | ||
""" | ||
A Pydantic model for validating the system configuration parameters. | ||
Attributes: | ||
cpus (int): The number of CPUs allocated for the system. Must be an integer >= 1. | ||
memory (int): The amount of memory in MB. Must be an integer >= 512. | ||
""" | ||
|
||
cpus: conint(ge=1) | ||
memory: conint(ge=512) | ||
audio: bool | ||
nested_virtualization: bool | ||
speculative_execution_control: bool | ||
|
||
|
||
@singleton | ||
class VmConfig: | ||
""" | ||
Configuration class for system settings. | ||
Attributes: | ||
cpus (int): The number of CPUs allocated for the system. | ||
memory (int): The amount of memory in MB. | ||
""" | ||
def __init__(self, config_path: str): | ||
self.config_path = config_path | ||
self._config = self._load_config(self.config_path) | ||
self.cpus = self._config.cpus | ||
self.memory = self._config.memory | ||
self.audio = self._config.audio | ||
self.nested_virtualization = self._config.nested_virtualization | ||
self.speculative_execution_control = self._config.speculative_execution_control | ||
|
||
@staticmethod | ||
def _load_config(file_path: str) -> SystemConfigModel: | ||
""" | ||
Loads the system configuration from a JSON file and returns a SystemConfigModel instance. | ||
:param file_path: The path to the configuration JSON file. | ||
:return: An instance of SystemConfigModel containing the loaded configuration. | ||
""" | ||
with open(file_path, 'r') as f: | ||
return SystemConfigModel(**json.load(f)) | ||
|
||
def display_config(self): | ||
""" | ||
Displays the loaded system configuration. | ||
""" | ||
print( | ||
f"[green]|INFO| System Configuration:\n" | ||
f" CPUs: {self.cpus}\n" | ||
f" Memory: {self.memory}MB\n" | ||
f" Audio Enabled: {self.audio}\n" | ||
f" Nested Virtualization: {self.nested_virtualization}\n" | ||
f" Speculative Execution Control: {self.speculative_execution_control}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class VmData: | ||
user: str | ||
ip: str | ||
name: str | ||
local_dir: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
from .VboxMachine import VboxMachine, VmConfig | ||
from .console import MyConsole | ||
from .report import Report | ||
|
||
__all__ = [ | ||
VboxMachine, | ||
MyConsole, | ||
Report, | ||
VmConfig | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from .decorators import * | ||
from .decorators import vm_data_created, vm_is_turn_on, retry | ||
|
||
__all__ = ['vm_data_created', 'vm_is_turn_on', 'retry'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from .report import Report | ||
|
||
__all__ = [Report] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.