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