Commit bdffe908 authored by Hejing Li's avatar Hejing Li
Browse files

host/base.py: fix class names

parent ab21c0b6
...@@ -23,19 +23,19 @@ ...@@ -23,19 +23,19 @@
import typing as tp import typing as tp
import io import io
from os import path from os import path
from simbricks.orchestration.experiment import experiment_environment as expenv import simbricks.orchestration.instantiation.base as instantiation
from simbricks.orchestration.system import base as base from simbricks.orchestration.system import base as base
from simbricks.orchestration.system.host import app
if tp.TYPE_CHECKING: if tp.TYPE_CHECKING:
from simbricks.orchestration.system import (eth, mem, pcie) from simbricks.orchestration.system import (eth, mem, pcie)
from simbricks.orchestration.system.host import disk_images from simbricks.orchestration.system.host import disk_images
from simbricks.orchestration.system.host import app
class Host(base.Component): class Host(base.Component):
def __init__(self, s: base.System): def __init__(self, s: base.System):
super().__init__(s) super().__init__(s)
self.ifs: list[base.Interface] = [] self.ifs: list[base.Interface] = []
self.applications: list['Application'] self.applications: list[app.Application]
def interfaces(self) -> list[base.Interface]: def interfaces(self) -> list[base.Interface]:
return self.pcie_ifs + self.eth_ifs + self.mem_ifs return self.pcie_ifs + self.eth_ifs + self.mem_ifs
...@@ -43,7 +43,7 @@ class Host(base.Component): ...@@ -43,7 +43,7 @@ class Host(base.Component):
def add_if(self, interface: base.Interface) -> None: def add_if(self, interface: base.Interface) -> None:
self.ifs.append(interface) self.ifs.append(interface)
def add_app(self, a: 'Application') -> None: def add_app(self, a: app.Application) -> None:
self.applications.append(a) self.applications.append(a)
...@@ -62,17 +62,17 @@ class FullSystemHost(Host): ...@@ -62,17 +62,17 @@ class FullSystemHost(Host):
class BaseLinuxHost(FullSystemHost): class BaseLinuxHost(FullSystemHost):
def __init__(self, s: base.System) -> None: def __init__(self, s: base.System) -> None:
super().__init__(s) super().__init__(s)
self.applications: list['BaseLinuxApplication'] = [] self.applications: list[app.BaseLinuxApplication] = []
self.load_modules = [] self.load_modules = []
self.kcmd_append = '' self.kcmd_append = ''
def add_app(self, a: 'BaseLinuxApplication') -> None: def add_app(self, a: app.BaseLinuxApplication) -> None:
self.applications.append(a) self.applications.append(a)
def _concat_app_cmds( def _concat_app_cmds(
self, self,
env: expenv.ExpEnv, inst: instantiation.Instantiation,
mapper: tp.Callable[['BaseLinuxApplication', expenv.ExpEnv], mapper: tp.Callable[['BaseLinuxApplication', instantiation.Instantiation],
list[str]] list[str]]
) -> list[str]: ) -> list[str]:
""" """
...@@ -81,18 +81,19 @@ class BaseLinuxHost(FullSystemHost): ...@@ -81,18 +81,19 @@ class BaseLinuxHost(FullSystemHost):
""" """
cmds = [] cmds = []
for app in self.applications: for app in self.applications:
cmds += mapper(app, env) cmds += mapper(app, inst)
return cmds return cmds
def run_cmds(self, env: expenv.ExpEnv) -> list[str]: def run_cmds(self, inst: instantiation.Instantiation) -> list[str]:
"""Commands to run on node.""" """Commands to run on node."""
return self._concat_app_cmds(env, app.LinuxApplication.run_cmds) return self._concat_app_cmds(inst, app.BaseLinuxApplication.run_cmds)
def cleanup_cmds(self, env: expenv.ExpEnv) -> list[str]: def cleanup_cmds(self, inst: instantiation.Instantiation) -> list[str]:
"""Commands to run to cleanup node.""" """Commands to run to cleanup node."""
return self._concat_app_cmds(env, app.LinuxApplication.cleanup_cmds) return self._concat_app_cmds(inst, app.BaseLinuxApplication.cleanup_cmds)
def config_files(self, env: expenv.ExpEnv) -> dict[str, tp.IO]: def config_files(self, inst: instantiation.Instantiation) -> dict[str, tp.IO]:
""" """
Additional files to put inside the node, which are mounted under Additional files to put inside the node, which are mounted under
`/tmp/guest/`. `/tmp/guest/`.
...@@ -102,27 +103,27 @@ class BaseLinuxHost(FullSystemHost): ...@@ -102,27 +103,27 @@ class BaseLinuxHost(FullSystemHost):
""" """
cfg_files = {} cfg_files = {}
for app in self.applications: for app in self.applications:
cfg_files |= self.app.config_files(env) cfg_files |= self.applications[0].config_files(inst)
return cfg_files return cfg_files
def prepare_pre_cp(self, env: expenv.ExpEnv) -> list[str]: def prepare_pre_cp(self, inst: instantiation.Instantiation) -> list[str]:
"""Commands to run to prepare node before checkpointing.""" """Commands to run to prepare node before checkpointing."""
self._concat_app_cmds(env, app.LinuxApplication.prepare_pre_cp) return self._concat_app_cmds(inst, app.BaseLinuxApplication.prepare_pre_cp)
def prepare_post_cp(self, env: expenv.ExpEnv) -> list[str]:
def prepare_post_cp(self, inst: instantiation.Instantiation) -> list[str]:
"""Commands to run to prepare node after checkpoint restore.""" """Commands to run to prepare node after checkpoint restore."""
return self._concat_app_cmds(env, app.LinuxApplication.prepare_post_cp) return self._concat_app_cmds(inst, app.BaseLinuxApplication.prepare_post_cp)
def _config_str(self, env: expenv.ExpEnv) -> str: def _config_str(self, inst: instantiation.Instantiation) -> str:
if env.create_cp: if inst.create_cp:
sim = env.exp.get_simulator(self)
cp_cmd = self.checkpoint_commands() cp_cmd = self.checkpoint_commands()
else: else:
cp_cmd = [] cp_cmd = []
es = self.prepare_pre_cp(env) + self.app.prepare_pre_cp(env) + \ es = self.prepare_pre_cp(inst) + self.applications[0].prepare_pre_cp(inst) + \
cp_cmd + \ cp_cmd + \
self.prepare_post_cp(env) + self.app.prepare_post_cp(env) + \ self.prepare_post_cp(inst) + self.applications[0].prepare_post_cp(inst) + \
self.run_cmds() + self.cleanup_cmds() self.run_cmds() + self.cleanup_cmds()
return '\n'.join(es) return '\n'.join(es)
...@@ -142,10 +143,10 @@ class LinuxHost(BaseLinuxHost): ...@@ -142,10 +143,10 @@ class LinuxHost(BaseLinuxHost):
super().__init__(sys) super().__init__(sys)
self.drivers: list[str] = [] self.drivers: list[str] = []
def cleanup_cmds(self, env: expenv.ExpEnv) -> list[str]: def cleanup_cmds(self, inst: instantiation.Instantiation) -> list[str]:
return super().cleanup_cmds(env) + ['poweroff -f'] return super().cleanup_cmds(inst) + ['poweroff -f']
def prepare_pre_cp(self, env: expenv.ExpEnv) -> list[str]: def prepare_pre_cp(self, inst: instantiation.Instantiation) -> list[str]:
"""Commands to run to prepare node before checkpointing.""" """Commands to run to prepare node before checkpointing."""
return [ return [
'set -x', 'set -x',
...@@ -153,9 +154,9 @@ class LinuxHost(BaseLinuxHost): ...@@ -153,9 +154,9 @@ class LinuxHost(BaseLinuxHost):
'export LANG=en_US', 'export LANG=en_US',
'export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:' + \ 'export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:' + \
'/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"' '/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"'
] + super().prepare_pre_cp(env) ] + super().prepare_pre_cp(inst)
def prepare_post_cp(self) -> tp.List[str]: def prepare_post_cp(self, inst) -> tp.List[str]:
l = [] l = []
for d in self.drivers: for d in self.drivers:
if d[0] == '/': if d[0] == '/':
...@@ -194,12 +195,15 @@ class I40ELinuxHost(LinuxHost): ...@@ -194,12 +195,15 @@ class I40ELinuxHost(LinuxHost):
super().__init__(sys) super().__init__(sys)
self.drivers.append('i40e') self.drivers.append('i40e')
def checkpoint_commands(self) -> list[str]:
return ['m5 checkpoint']
class CorundumLinuxHost(LinuxHost): class CorundumLinuxHost(LinuxHost):
def __init__(self, sys) -> None: def __init__(self, sys) -> None:
super().__init__(sys) super().__init__(sys)
self.drivers.append('/tmp/guest/mqnic.ko') self.drivers.append('/tmp/guest/mqnic.ko')
def config_files(self, env: expenv.ExpEnv) -> tp.Dict[str, tp.IO]: def config_files(self, inst: instantiation.Instantiation) -> tp.Dict[str, tp.IO]:
m = {'mqnic.ko': open('../images/mqnic/mqnic.ko', 'rb')} m = {'mqnic.ko': open('../images/mqnic/mqnic.ko', 'rb')}
return {**m, **super().config_files()} return {**m, **super().config_files()}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment