Commit f81b06e7 authored by Jonas Kaufmann's avatar Jonas Kaufmann Committed by Antoine Kaufmann
Browse files

add exemplary doc strings in module experiments and nodeconfig

parent aef7d4e3
......@@ -22,30 +22,33 @@
import os
import asyncio
from simbricks.simulators import HostSim, NetSim, PCIDevSim
import simbricks.utils.graphlib as graphlib
from collections import defaultdict
import simbricks.exectools as exectools
import simbricks.proxy
import shlex
import time
import itertools
import json
import traceback
import typing as tp
class Experiment(object):
name = None
timeout = None
name: str
"""This experiment's name."""
timeout: int
# TODO Add docstring
checkpoint = False
# TODO Add docstring
no_simbricks = False
# TODO Add docstring
def __init__(self, name):
def __init__(self, name: str):
self.name = name
self.hosts = []
self.pcidevs = []
self.networks = []
self.hosts: tp.List[HostSim] = []
self.pcidevs: tp.List[PCIDevSim] = []
self.networks: tp.List[NetSim] = []
self.metadata = {}
def add_host(self, sim):
def add_host(self, sim: HostSim):
for h in self.hosts:
if h.name == sim.name:
raise Exception('Duplicate host name')
......@@ -54,13 +57,13 @@ class Experiment(object):
def add_nic(self, sim):
self.add_pcidev(sim)
def add_pcidev(self, sim):
def add_pcidev(self, sim: PCIDevSim):
for d in self.pcidevs:
if d.name == sim.name:
raise Exception('Duplicate pcidev name')
self.pcidevs.append(sim)
def add_network(self, sim):
def add_network(self, sim: NetSim):
for n in self.networks:
if n.name == sim.name:
raise Exception('Duplicate net name')
......
......@@ -22,17 +22,45 @@
import tarfile
import io
import pathlib
class AppConfig(object):
"""Manages the application to be run on a simulated host."""
def run_cmds(self, node):
return []
def prepare_pre_cp(self):
return []
def prepare_post_cp(self):
return []
def config_files(self):
return {}
def strfile(self, s):
return io.BytesIO(bytes(s, encoding='UTF-8'))
class NodeConfig(object):
"""Manages the configuration for a node."""
sim = 'qemu'
"""Name of simulator to run."""
ip = '10.0.0.1'
"""IP address."""
prefix = 24
"""IP prefix."""
cores = 1
"""Number of cores to be simulated."""
memory = 8 * 1024
"""Amount of system memory in MB."""
disk_image = 'base'
app = None
"""Disk image to use."""
app: AppConfig = None
"""App to be run on simulated host."""
mtu = 1500
"""Networking MTU."""
def config_str(self):
if self.sim == 'qemu':
......@@ -61,7 +89,7 @@ class NodeConfig(object):
cfg_f.close()
# add additional config files
for (n,f) in self.config_files().items():
for (n, f) in self.config_files().items():
f_i = tarfile.TarInfo('guest/' + n)
f_i.mode = 0o777
f.seek(0, io.SEEK_END)
......@@ -97,23 +125,6 @@ class NodeConfig(object):
return io.BytesIO(bytes(s, encoding='UTF-8'))
class AppConfig(object):
def run_cmds(self, node):
return []
def prepare_pre_cp(self):
return []
def prepare_post_cp(self):
return []
def config_files(self):
return {}
def strfile(self, s):
return io.BytesIO(bytes(s, encoding='UTF-8'))
class LinuxNode(NodeConfig):
ifname = 'eth0'
......
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