From 031cdc38878686d7ae5532f3968e2b4d428ab7cd Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 9 May 2018 15:50:51 +0200 Subject: elements: Allow exporting to DMS YAML This allows for exporting the experiment to a YAML format which is parsable by the DMS. --- rumba/elements/experimentation.py | 9 +++++++++ rumba/elements/topology.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/rumba/elements/experimentation.py b/rumba/elements/experimentation.py index 9890975..2c6f478 100644 --- a/rumba/elements/experimentation.py +++ b/rumba/elements/experimentation.py @@ -521,6 +521,15 @@ class Experiment(object): end = time.time() logger.info("Swap-out took %.2f seconds", end - start) + def to_dms_yaml(self, filename, clean=True): + mode = 'w' + if not clean: + mode += '+' + with open(filename, mode) as f: + for node in self.nodes: + f.write("---\n") + node.to_dms_yaml(f) + f.write("...\n") class Executor: __metaclass__ = abc.ABCMeta diff --git a/rumba/elements/topology.py b/rumba/elements/topology.py index c47d541..46f24c2 100644 --- a/rumba/elements/topology.py +++ b/rumba/elements/topology.py @@ -654,6 +654,24 @@ class Node(object): def __neq__(self, other): return not self == other + def to_dms_yaml(self, buffer): + buffer.write("node: %s\n" % (self.name)) + buffer.write("registrations:\n") + + for dif in self.dif_registrations: + if isinstance(dif, NormalDIF): + buffer.write(" - %s:\n" % (dif.name)) + for reg in self.dif_registrations[dif]: + tp = "normal" + nm = reg.name + if isinstance(reg, ShimEthDIF): + tp = "eth" + for member in reg.members: + if member.name is not self.name: + nm = member.name + buffer.write(" - %sdifid: %s, diftype: %s, " + "diftype_number: 1%s\n" % ("{", nm, tp, "}")) + def add_dif(self, dif): """ Adds a DIF to the list. -- cgit v1.2.3