[haizea-commit] r600 - in branches/TP2.0: bin src/haizea/cli
haizea-commit at mailman.cs.uchicago.edu
haizea-commit at mailman.cs.uchicago.edu
Mon Jul 6 12:22:56 CDT 2009
Author: borja
Date: 2009-07-06 12:22:50 -0500 (Mon, 06 Jul 2009)
New Revision: 600
Added:
branches/TP2.0/bin/haizea-lwf2xml
Modified:
branches/TP2.0/src/haizea/cli/commands.py
Log:
Added haizea-lwf2xml command to convert from old LWF format to new XML format
Added: branches/TP2.0/bin/haizea-lwf2xml
===================================================================
--- branches/TP2.0/bin/haizea-lwf2xml (rev 0)
+++ branches/TP2.0/bin/haizea-lwf2xml 2009-07-06 17:22:50 UTC (rev 600)
@@ -0,0 +1,7 @@
+#!/usr/bin/python
+
+from haizea.cli import commands
+import sys
+
+c = commands.haizea_lwf2xml(sys.argv)
+c.run()
\ No newline at end of file
Property changes on: branches/TP2.0/bin/haizea-lwf2xml
___________________________________________________________________
Name: svn:executable
+ *
Modified: branches/TP2.0/src/haizea/cli/commands.py
===================================================================
--- branches/TP2.0/src/haizea/cli/commands.py 2009-07-03 17:07:07 UTC (rev 599)
+++ branches/TP2.0/src/haizea/cli/commands.py 2009-07-06 17:22:50 UTC (rev 600)
@@ -22,6 +22,8 @@
from haizea.common.config import ConfigException
from haizea.cli.optionparser import OptionParser, Option
from haizea.cli import Command
+from mx.DateTime import TimeDelta
+import xml.etree.ElementTree as ET
import haizea.common.defaults as defaults
import sys
import os
@@ -297,4 +299,113 @@
for lease_id in waitingtimes:
print ",".join([attrs, `lease_id`, `waitingtimes[lease_id].seconds`, `slowdowns[lease_id]`])
+class haizea_lwf2xml(Command):
+ """
+ Converts old Haizea LWF file into new XML-based LWF format
+ """
+
+ name = "haizea-lwf2xml"
+ def __init__(self, argv):
+ Command.__init__(self, argv)
+
+ self.optparser.add_option(Option("-i", "--in", action="store", type="string", dest="inf",
+ help = """
+ Input file
+ """))
+ self.optparser.add_option(Option("-o", "--out", action="store", type="string", dest="outf",
+ help = """
+ Output file
+ """))
+
+ def run(self):
+ self.parse_options()
+
+ infile = self.opt.inf
+ outfile = self.opt.outf
+
+ root = ET.Element("lease-workload")
+ root.set("name", infile)
+ description = ET.SubElement(root, "description")
+ time = TimeDelta(seconds=0)
+ id = 1
+ requests = ET.SubElement(root, "lease-requests")
+
+
+ infile = open(infile, "r")
+ for line in infile:
+ if line[0]!='#' and len(line.strip()) != 0:
+ fields = line.split()
+ submit_time = int(fields[0])
+ start_time = int(fields[1])
+ duration = int(fields[2])
+ real_duration = int(fields[3])
+ num_nodes = int(fields[4])
+ cpu = int(fields[5])
+ mem = int(fields[6])
+ disk = int(fields[7])
+ vm_image = fields[8]
+ vm_imagesize = int(fields[9])
+
+
+
+ lease_request = ET.SubElement(requests, "lease-request")
+ lease_request.set("arrival", str(TimeDelta(seconds=submit_time)))
+ if real_duration != duration:
+ realduration = ET.SubElement(lease_request, "realduration")
+ realduration.set("time", str(TimeDelta(seconds=realduration)))
+
+ lease = ET.SubElement(lease_request, "lease")
+ lease.set("id", `id`)
+
+
+ nodes = ET.SubElement(lease, "nodes")
+ node_set = ET.SubElement(nodes, "node-set")
+ node_set.set("numnodes", `num_nodes`)
+ res = ET.SubElement(node_set, "res")
+ res.set("type", "CPU")
+ if cpu == 1:
+ res.set("amount", "100")
+ else:
+ pass
+ res = ET.SubElement(node_set, "res")
+ res.set("type", "Memory")
+ res.set("amount", `mem`)
+
+ start = ET.SubElement(lease, "start")
+ if start_time == -1:
+ lease.set("preemptible", "true")
+ else:
+ lease.set("preemptible", "false")
+ exact = ET.SubElement(start, "exact")
+ exact.set("time", str(TimeDelta(seconds=start_time)))
+
+ duration_elem = ET.SubElement(lease, "duration")
+ duration_elem.set("time", str(TimeDelta(seconds=duration)))
+
+ software = ET.SubElement(lease, "software")
+ diskimage = ET.SubElement(software, "disk-image")
+ diskimage.set("id", vm_image)
+ diskimage.set("size", `vm_imagesize`)
+
+
+ id += 1
+ tree = ET.ElementTree(root)
+ print ET.tostring(root)
+ #tree.write("page.xhtml")
+#head = ET.SubElement(root, "head")
+
+#title = ET.SubElement(head, "title")
+#title.text = "Page Title"
+
+#body = ET.SubElement(root, "body")
+#body.set("bgcolor", "#ffffff")
+
+#body.text = "Hello, World!"
+
+# wrap it in an ElementTree instance, and save as XML
+#tree = ET.ElementTree(root)
+
+
+
+
More information about the Haizea-commit
mailing list