Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/aleph/vm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class VmExecution:
systemd_manager: SystemDManager | None

persistent: bool = False
mapped_ports: dict[int, dict] = {} # Port redirect to the VM
mapped_ports: dict[int, dict] # Port redirect to the VM
record: ExecutionRecord | None = None

async def fetch_port_redirect_config_and_setup(self):
Expand All @@ -108,8 +108,7 @@ async def fetch_port_redirect_config_and_setup(self):
try:
port_forwarding_settings = await get_user_settings(message.address, "port-forwarding")
vm_port_forwarding = port_forwarding_settings.get(self.vm_hash, {}) or {}
if "ports" in ports_requests:
ports_requests = vm_port_forwarding.get("ports", {})
ports_requests = vm_port_forwarding.get("ports", {})
except Exception:
logger.info("Could not fetch the port redirect settings for user %s", message.address, exc_info=True)

Expand Down
2 changes: 1 addition & 1 deletion src/aleph/vm/network/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def add_port_redirect_rule(
"match": {
"op": "==",
"left": {"meta": {"key": "iifname"}},
"right": interface.device_name,
"right": settings.NETWORK_INTERFACE,
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion src/aleph/vm/orchestrator/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@
async def get_execution_records() -> Iterable[ExecutionRecord]:
"""Get the execution records from the database."""
async with AsyncSessionMaker() as session: # Use AsyncSession in a context manager
result = await session.execute(select(ExecutionRecord)) # Use execute for querying
result = await session.execute(

Check warning on line 117 in src/aleph/vm/orchestrator/metrics.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/orchestrator/metrics.py#L117

Added line #L117 was not covered by tests
select(ExecutionRecord).order_by(ExecutionRecord.time_defined.desc())
) # Use execute for querying
executions = result.scalars().all()
await session.commit()
return executions
Expand Down
14 changes: 11 additions & 3 deletions src/aleph/vm/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from aleph.vm.vm_type import VmType

from .models import ExecutableContent, VmExecution
from .network.firewall import setup_nftables_for_vm

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -263,7 +264,7 @@
continue

vm_id = saved_execution.vm_id

logger.info(f"Loading execution {vm_hash} for VM {vm_id}")

Check warning on line 267 in src/aleph/vm/pool.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/pool.py#L267

Added line #L267 was not covered by tests
message_dict = json.loads(saved_execution.message)
original_dict = json.loads(saved_execution.original_message)

Expand All @@ -284,14 +285,19 @@
if saved_execution.gpus
else []
)
execution.mapped_ports = saved_execution.mapped_ports or {}

mapped_ports = saved_execution.mapped_ports if saved_execution.mapped_ports else {}

Check warning on line 289 in src/aleph/vm/pool.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/pool.py#L289

Added line #L289 was not covered by tests
# Ensure the key are int and not string. They get converted when serialized in the db
for k, v in mapped_ports.items():
execution.mapped_ports[int(k)] = v

Check warning on line 292 in src/aleph/vm/pool.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/pool.py#L292

Added line #L292 was not covered by tests

# Load and instantiate the rest of resources and already assigned GPUs
await execution.prepare()
if self.network:
vm_type = VmType.from_message_content(execution.message)
tap_interface = await self.network.prepare_tap(vm_id, vm_hash, vm_type)

# Activate ndp_proxy for existing interface if needed
# Activate ndp_proxy for existing interfaces if needed
if self.network.ndp_proxy and self.network.interface_exists(vm_id):
ipv6_gateway = tap_interface.host_ipv6
await self.network.ndp_proxy.add_range(
Expand All @@ -300,6 +306,8 @@
update_service=False,
)
logger.debug(f"Re-added ndp_proxy rule for existing interface {tap_interface.device_name}")
# Ensure the routing table and rule for the VM are present
setup_nftables_for_vm(vm_id, interface=tap_interface)

Check warning on line 310 in src/aleph/vm/pool.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/pool.py#L310

Added line #L310 was not covered by tests
else:
tap_interface = None

Expand Down