Revision 632
Added by Borja Sotomayor almost 15 years ago
commands.py | ||
---|---|---|
16 | 16 |
# limitations under the License. # |
17 | 17 |
# -------------------------------------------------------------------------- # |
18 | 18 |
|
19 |
from haizea.resourcemanager.rm import ResourceManager
|
|
19 |
from haizea.core.manager import Manager
|
|
20 | 20 |
from haizea.common.utils import generate_config_name, unpickle |
21 |
from haizea.resourcemanager.configfile import HaizeaConfig, HaizeaMultiConfig
|
|
21 |
from haizea.core.configfile import HaizeaConfig, HaizeaMultiConfig
|
|
22 | 22 |
from haizea.common.config import ConfigException |
23 | 23 |
from haizea.cli.optionparser import OptionParser, Option |
24 | 24 |
from haizea.cli import Command |
25 |
from mx.DateTime import TimeDelta |
|
26 |
import xml.etree.ElementTree as ET |
|
25 | 27 |
import haizea.common.defaults as defaults |
26 | 28 |
import sys |
27 | 29 |
import os |
... | ... | |
108 | 110 |
|
109 | 111 |
daemon = not self.opt.foreground |
110 | 112 |
|
111 |
rm = ResourceManager(config, daemon, pidfile)
|
|
113 |
manager = Manager(config, daemon, pidfile)
|
|
112 | 114 |
|
113 |
rm.start()
|
|
115 |
manager.start()
|
|
114 | 116 |
elif self.opt.stop: # Stop Haizea |
115 | 117 |
# Based on code in: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 |
116 | 118 |
try: |
... | ... | |
297 | 299 |
for lease_id in waitingtimes: |
298 | 300 |
print ",".join([attrs, `lease_id`, `waitingtimes[lease_id].seconds`, `slowdowns[lease_id]`]) |
299 | 301 |
|
302 |
class haizea_lwf2xml(Command): |
|
303 |
""" |
|
304 |
Converts old Haizea LWF file into new XML-based LWF format |
|
305 |
""" |
|
306 |
|
|
307 |
name = "haizea-lwf2xml" |
|
300 | 308 |
|
309 |
def __init__(self, argv): |
|
310 |
Command.__init__(self, argv) |
|
311 |
|
|
312 |
self.optparser.add_option(Option("-i", "--in", action="store", type="string", dest="inf", |
|
313 |
help = """ |
|
314 |
Input file |
|
315 |
""")) |
|
316 |
self.optparser.add_option(Option("-o", "--out", action="store", type="string", dest="outf", |
|
317 |
help = """ |
|
318 |
Output file |
|
319 |
""")) |
|
320 |
|
|
321 |
def run(self): |
|
322 |
self.parse_options() |
|
323 |
|
|
324 |
infile = self.opt.inf |
|
325 |
outfile = self.opt.outf |
|
326 |
|
|
327 |
root = ET.Element("lease-workload") |
|
328 |
root.set("name", infile) |
|
329 |
description = ET.SubElement(root, "description") |
|
330 |
time = TimeDelta(seconds=0) |
|
331 |
id = 1 |
|
332 |
requests = ET.SubElement(root, "lease-requests") |
|
333 |
|
|
334 |
|
|
335 |
infile = open(infile, "r") |
|
336 |
for line in infile: |
|
337 |
if line[0]!='#' and len(line.strip()) != 0: |
|
338 |
fields = line.split() |
|
339 |
submit_time = int(fields[0]) |
|
340 |
start_time = int(fields[1]) |
|
341 |
duration = int(fields[2]) |
|
342 |
real_duration = int(fields[3]) |
|
343 |
num_nodes = int(fields[4]) |
|
344 |
cpu = int(fields[5]) |
|
345 |
mem = int(fields[6]) |
|
346 |
disk = int(fields[7]) |
|
347 |
vm_image = fields[8] |
|
348 |
vm_imagesize = int(fields[9]) |
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
lease_request = ET.SubElement(requests, "lease-request") |
|
353 |
lease_request.set("arrival", str(TimeDelta(seconds=submit_time))) |
|
354 |
if real_duration != duration: |
|
355 |
realduration = ET.SubElement(lease_request, "realduration") |
|
356 |
realduration.set("time", str(TimeDelta(seconds=real_duration))) |
|
357 |
|
|
358 |
lease = ET.SubElement(lease_request, "lease") |
|
359 |
lease.set("id", `id`) |
|
360 |
|
|
361 |
|
|
362 |
nodes = ET.SubElement(lease, "nodes") |
|
363 |
node_set = ET.SubElement(nodes, "node-set") |
|
364 |
node_set.set("numnodes", `num_nodes`) |
|
365 |
res = ET.SubElement(node_set, "res") |
|
366 |
res.set("type", "CPU") |
|
367 |
if cpu == 1: |
|
368 |
res.set("amount", "100") |
|
369 |
else: |
|
370 |
pass |
|
371 |
res = ET.SubElement(node_set, "res") |
|
372 |
res.set("type", "Memory") |
|
373 |
res.set("amount", `mem`) |
|
374 |
|
|
375 |
start = ET.SubElement(lease, "start") |
|
376 |
if start_time == -1: |
|
377 |
lease.set("preemptible", "true") |
|
378 |
else: |
|
379 |
lease.set("preemptible", "false") |
|
380 |
exact = ET.SubElement(start, "exact") |
|
381 |
exact.set("time", str(TimeDelta(seconds=start_time))) |
|
382 |
|
|
383 |
duration_elem = ET.SubElement(lease, "duration") |
|
384 |
duration_elem.set("time", str(TimeDelta(seconds=duration))) |
|
385 |
|
|
386 |
software = ET.SubElement(lease, "software") |
|
387 |
diskimage = ET.SubElement(software, "disk-image") |
|
388 |
diskimage.set("id", vm_image) |
|
389 |
diskimage.set("size", `vm_imagesize`) |
|
390 |
|
|
391 |
|
|
392 |
id += 1 |
|
393 |
tree = ET.ElementTree(root) |
|
394 |
print ET.tostring(root) |
|
395 |
#tree.write("page.xhtml") |
|
396 |
#head = ET.SubElement(root, "head") |
|
397 |
|
|
398 |
#title = ET.SubElement(head, "title") |
|
399 |
#title.text = "Page Title" |
|
400 |
|
|
401 |
#body = ET.SubElement(root, "body") |
|
402 |
#body.set("bgcolor", "#ffffff") |
|
403 |
|
|
404 |
#body.text = "Hello, World!" |
|
405 |
|
|
406 |
# wrap it in an ElementTree instance, and save as XML |
|
407 |
#tree = ET.ElementTree(root) |
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
Also available in: Unified diff
Merged TP2.0/0.9 branch into trunk.