예제 #1
0
def generate(arguments):

    if arguments["clean"]:

        db = reservation_connect()
        reservations = Reservation.objects({})
        print "deleting:"
        for reservation in reservations:
            print reservation.label,
            reservation.delete()
        print

    elif arguments["--rst"]:

        print "generate"
        print 70 * "="
        print "\n::\n"
        lines = __doc__.split("\n")
        for line in lines:
            print "  ", line

    else:

        reservations = int(arguments["RESERVATIONS"])
        duration = int(arguments["DURATION"])
        server_string = arguments["SERVERS"]
        servers = hostlist.expand_hostlist(server_string)
        if arguments["START"] in ["now"]:
            first_time = datetime.datetime.now()
        else:
            first_time = timeparse(arguments("START"))

        print 70 * "="
        print "Servers:     ", servers
        print "Reservations:", reservations
        print "Duration:    ", duration
        print "First date:  ", first_time
        print 70 * "="

        db = reservation_connect()

        def random_delta(duration):
            r = randint(0, duration)
            return datetime.timedelta(seconds=timeparse("{0} h".format(r)))

        t_start = {}
        t_end = {}
        for s in xrange(0, len(servers)):
            t_start[s] = []
            t_end[s] = []

            t_start[s].append(first_time + random_delta(duration))
            t_end[s].append(t_start[s][0] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(1, reservations):
                t_start[s].append(t_end[s][n - 1] + random_delta(duration))
                t_end[s].append(t_start[s][n] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                print s, n, t_start[s][n], t_end[s][n]

        pprint("start: " + str(t_start))
        pprint("end  : " + str(t_end))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                entry = {
                    "cm_id": "cm_reservation-{0}-{1}".format(s, n),
                    "label": "exp-{0}-{1}".format(s, n),
                    "summary": "task-{0}-{1}".format(s, n),
                    "host": servers[s],
                    "user": "******",
                    "project": "fg82",
                    "start_time": str(t_start[s][n]),
                    "end_time": str(t_end[s][n]),
                }

                print entry
                r = Reservation(
                    cm_id=entry["cm_id"],
                    host=entry["host"],
                    label=entry["label"],
                    user=entry["user"],
                    summary=entry["summary"],
                    project=entry["project"],
                    start_time=entry["start_time"],
                    end_time=entry["end_time"],
                )
                r.save()

        print 70 * "A"
        reservations = Reservation.objects()
        print len(reservations)
        for reservation in reservations:
            pprint(reservation)
        print 70 * "B"

        for reservation in reservations:
            print reservation
예제 #2
0
def generate(arguments):

    if arguments['clean']:

        db = reservation_connect()
        reservations = Reservation.objects({})
        print "deleting:"
        for reservation in reservations:
            print reservation.label,
            reservation.delete()
        print

    elif arguments["--rst"]:

        print "generate"
        print 70 * "="
        print "\n::\n"
        lines = __doc__.split("\n")
        for line in lines:
            print "  ", line

    else:

        reservations = int(arguments["RESERVATIONS"])
        duration = int(arguments["DURATION"])
        server_string = arguments["SERVERS"]
        servers = hostlist.expand_hostlist(server_string)
        if arguments["START"] in ["now"]:
            first_time = datetime.datetime.now()
        else:
            first_time = timeparse(arguments("START"))

        print 70 * "="
        print "Servers:     ", servers
        print "Reservations:", reservations
        print "Duration:    ", duration
        print "First date:  ", first_time
        print 70 * "="

        db = reservation_connect()

        def random_delta(duration):
            r = randint(0, duration)
            return datetime.timedelta(seconds=timeparse("{0} h".format(r)))

        t_start = {}
        t_end = {}
        for s in xrange(0, len(servers)):
            t_start[s] = []
            t_end[s] = []

            t_start[s].append(first_time + random_delta(duration))
            t_end[s].append(t_start[s][0] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(1, reservations):
                t_start[s].append(t_end[s][n - 1] + random_delta(duration))
                t_end[s].append(t_start[s][n] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                print s, n, t_start[s][n], t_end[s][n]

        pprint("start: " + str(t_start))
        pprint("end  : " + str(t_end))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                entry = {
                    "cm_id": "cm_reservation-{0}-{1}".format(s, n),
                    "label": "exp-{0}-{1}".format(s, n),
                    "summary": "task-{0}-{1}".format(s, n),
                    "host": servers[s],
                    "user": "******",
                    "project": "fg82",
                    "start_time": str(t_start[s][n]),
                    "end_time": str(t_end[s][n]),
                }

                print entry
                r = Reservation(cm_id=entry["cm_id"],
                                host=entry["host"],
                                label=entry["label"],
                                user=entry["user"],
                                summary=entry["summary"],
                                project=entry["project"],
                                start_time=entry["start_time"],
                                end_time=entry["end_time"])
                r.save()

        print 70 * "A"
        reservations = Reservation.objects()
        print len(reservations)
        for reservation in reservations:
            pprint(reservation)
        print 70 * "B"

        for reservation in reservations:
            print reservation
예제 #3
0
def timeline_plot(out_filename):
    format = "svg"
    db = reservation_connect()


    reservations = Reservation.objects()

    hosts = set()
    times = set()

    data = []
    for reservation in reservations:
        hosts.add(reservation["host"])
        times.add(reservation["start_time"])
        times.add(reservation["start_time"])
        #print reservation
        data.append("{0} {1} {2} {3}".format(reservation.host,
                                            reservation.start_time.strftime("%Y/%m/%d.%H:%M"),
                                            reservation.end_time.strftime("%Y/%m/%d.%H:%M"),
                                            reservation.label)
            )

    # print hosts
    # print min(times)
    # print max(times)

    delta = max(times) - min(times)

    height = len(hosts) - 1
    if height <=1:
        height = 2

    script = \
    """
    #proc getdata
    data: {data}

    #proc areadef
       title: Cloudmesh Reservation
       rectangle: 1 1 10 {no_hosts}
       xscaletype: datetime YYYY/mm/dd.hh:mm
       #xrange: {tmin} {tmax}
       xautorange: datafield=2,3
       yscaletype: categories
       ycategories: {labels} 

    #proc xaxis
       stubs: datematic

    #proc yaxis
       stubs: categories

    #proc bars
       clickmapurl: @CGI?channel=@@1&starttime=@@2&endtime=@@3&title=@@4
       color: powderblue2
       axis: x
       locfield: 1
       segmentfields: 2 3
       labelfield: 4
       longwayslabel: yes
       labeldetails: size=6
    """.format(tmin=min(times).strftime("%Y/%m/%d.%H:%M"),
               tmax=max(times).strftime("%Y/%m/%d.%H:%M"),
               labels="\n\t" + "\n\t".join(hosts),
               data="\n\t" + "\n\t".join(data),
               no_hosts=height
               )


    #print script

    filename ="/tmp/ploticus.txt"    

    with open(filename, "w") as file:
        file.write(script)

    
    if sys.platform in ["darwin"]:
        ploticus = "/usr/local/bin/pl"
    else:
        ploticus = "/usr/bin/ploticus"
    
    command = "{ploticus} {filename} -{format} -o {out}.{format}".format(out=out_filename, filename=filename, format=format, ploticus=ploticus )

    os.system(command)
예제 #4
0
def timeline_plot(out_filename):
    format = "svg"
    db = reservation_connect()

    reservations = Reservation.objects()

    hosts = set()
    times = set()

    data = []
    for reservation in reservations:
        hosts.add(reservation["host"])
        times.add(reservation["start_time"])
        times.add(reservation["start_time"])
        #print reservation
        data.append("{0} {1} {2} {3}".format(
            reservation.host,
            reservation.start_time.strftime("%Y/%m/%d.%H:%M"),
            reservation.end_time.strftime("%Y/%m/%d.%H:%M"),
            reservation.label))

    # print hosts
    # print min(times)
    # print max(times)

    delta = max(times) - min(times)

    height = len(hosts) - 1
    if height <= 1:
        height = 2

    script = \
    """
    #proc getdata
    data: {data}

    #proc areadef
       title: Cloudmesh Reservation
       rectangle: 1 1 10 {no_hosts}
       xscaletype: datetime YYYY/mm/dd.hh:mm
       #xrange: {tmin} {tmax}
       xautorange: datafield=2,3
       yscaletype: categories
       ycategories: {labels} 

    #proc xaxis
       stubs: datematic

    #proc yaxis
       stubs: categories

    #proc bars
       clickmapurl: @CGI?channel=@@1&starttime=@@2&endtime=@@3&title=@@4
       color: powderblue2
       axis: x
       locfield: 1
       segmentfields: 2 3
       labelfield: 4
       longwayslabel: yes
       labeldetails: size=6
    """.format(tmin=min(times).strftime("%Y/%m/%d.%H:%M"),
               tmax=max(times).strftime("%Y/%m/%d.%H:%M"),
               labels="\n\t" + "\n\t".join(hosts),
               data="\n\t" + "\n\t".join(data),
               no_hosts=height
               )

    #print script

    filename = "/tmp/ploticus.txt"

    with open(filename, "w") as file:
        file.write(script)

    if sys.platform in ["darwin"]:
        ploticus = "/usr/local/bin/pl"
    else:
        ploticus = "/usr/bin/ploticus"

    command = "{ploticus} {filename} -{format} -o {out}.{format}".format(
        out=out_filename, filename=filename, format=format, ploticus=ploticus)

    os.system(command)