Beispiel #1
0
def __kill_reservation(args):
    try:
        pyslurm.reservation().delete(args.RESERVATION_ID)
    except ValueError as value_error:
        print("Reservation ({0}) delete failed - {1}".format(
            args.RESERVATION_ID, value_error.args[0]))
    else:
        print("Reservation {0} deleted".format(args.RESERVATION_ID))
def test_reservation_scontrol():
    """Reservation: Compare scontrol values to PySlurm values."""
    test_resv_info = pyslurm.reservation().get()["resv_test"]
    sctl_dict = scontrol_show('reservation', 'resv_test')

    assert_equals(test_resv_info["node_list"], sctl_dict["Nodes"])
    assert_equals(test_resv_info["node_cnt"], int(sctl_dict["NodeCnt"]))
    assert_equals(",".join(test_resv_info["users"]), sctl_dict["Users"])
Beispiel #3
0
def test_reservation_update():
    """Reservation: Test reservation().update()."""
    resv_update = {
        "name": "resv_test",
        "duration": 8000
    }
    rc = pyslurm.reservation().update(resv_update)
    assert_equals(rc, 0)
Beispiel #4
0
def test_reservation_scontrol():
    """Reservation: Compare scontrol values to PySlurm values."""
    test_resv_info = pyslurm.reservation().get()["resv_test"]
    sctl_dict = scontrol_show("reservation", "resv_test")

    assert test_resv_info["node_list"] == sctl_dict["Nodes"]
    assert test_resv_info["node_cnt"] == int(sctl_dict["NodeCnt"])
    assert ",".join(test_resv_info["users"]) == sctl_dict["Users"]
Beispiel #5
0
def test_reservation_get():
    """Reservation: Test reservation().get()."""
    resv = pyslurm.reservation().get()

    assert isinstance(resv, dict)
    assert resv["resv_test"]["licenses"] == {"matlab": "1"}
    assert resv["resv_test"]["users"] == ["root", "slurm"]

    start = resv["resv_test"]["start_time"]
    end = resv["resv_test"]["end_time"]

    assert end - start == 600 * 60
def get(id, limit=100):
    handler = pyslurm.reservation()
    all_reservations = handler.get()
    try:
        reservation = handler.find_id(str(id))
    except Exception as e:
        resp = {"code": 500, "message": str(e)}
        return resp, 500
    if len(reservation.keys()) < 1:
        return NoContent, 204
    reservation['name'] = str(id)
    return dict(reservation), 200
Beispiel #7
0
def test_reservation_get():
    """Reservation: Test reservation().get()."""
    resv = pyslurm.reservation().get()

    assert_true(isinstance(resv, dict))
    assert_equals(resv["resv_test"]["licenses"], {"matlab": "1"})
    assert_equals(resv["resv_test"]["users"], ["root", "slurm"])

    start = resv["resv_test"]["start_time"]
    end = resv["resv_test"]["end_time"]

    assert_equals(end - start, 600 * 60)
Beispiel #8
0
def test_reservation_scontrol():
    """Reservation: Compare scontrol values to PySlurm values."""
    test_resv_info = pyslurm.reservation().get()["resv_test"]
    sctl = subprocess.Popen(["scontrol", "-d", "show", "reservation", "resv_test"],
                            stdout=subprocess.PIPE).communicate()
    sctl_stdout = sctl[0].strip().decode("UTF-8", "replace").split()
    sctl_dict = dict((value.split("=")[0], value.split("=")[1])
                     for value in sctl_stdout)

    assert_equals(test_resv_info["node_list"], sctl_dict["Nodes"])
    assert_equals(test_resv_info["node_cnt"], int(sctl_dict["NodeCnt"]))
    assert_equals(",".join(test_resv_info["users"]), sctl_dict["Users"])
Beispiel #9
0
def test_reservation_create():
    """Reservation: Test reservation().create()."""
    resv_test = {
        "node_cnt": 1,
        "users": 'root,slurm',
        "start_time": int(time.time()),
        "duration": 600,
        "licenses": "matlab:1",
        "name": "resv_test"
    }
    r = pyslurm.reservation().create(resv_test)
    assert_equals(r, "resv_test")
Beispiel #10
0
def search(limit=100):
    reservations = []
    handler = pyslurm.reservation()
    try:
        all_reservations = handler.get()
    except Exception as e:
        resp = {"code": 500, "message": str(e)}
        return resp, 500
    if len(all_reservations.values()) < 1:
        return NoContent, 204
    for this_res_name in all_reservations.keys():
        all_reservations[str(this_res_name)]['name'] = str(this_res_name)
        reservations.append(all_reservations[str(this_res_name)])
    return reservations[0:limit], 200
Beispiel #11
0
def get_all_reservations(partition):
    r = pyslurm.reservation()
    res = r.get()
    keys = r.find("partition", partition)

    reservations = []

    for key in keys:
        tmp = r.find_id(key)
        tmp["name"] = key
        tmp["start_time"] = parse_time(tmp["start_time"])
        tmp["end_time"] = parse_time(tmp["end_time"])
        reservations.append(tmp)

    return reservations
Beispiel #12
0
def __create_reservation(args):
    epoch_now = int(time.time())

    res = pyslurm.reservation()
    res_dict = pyslurm.create_reservation_dict()
    res_dict["node_cnt"] = 1
    res_dict["users"] = os.environ['USER']
    res_dict["partition"] = args.partition
    res_dict["start_time"] = epoch_now
    res_dict["duration"] = args.time
    res_dict["name"] = "res_test"

    reservation_id = res.create(res_dict)
    if args.quiet:
        print(reservation_id)
    else:
        print("Reservation succesful. Reservation ID is %s." % reservation_id)
Beispiel #13
0
def get_reservation(partition, res_id):
    r = pyslurm.reservation()
    res = r.get()
    keys = r.find("partition", partition)

    found = False

    for key in keys:
        if key == res_id:
            res[res_id]['name'] = key
            res[res_id]["start_time"] = parse_time(res[res_id]["start_time"])
            res[res_id]["end_time"] = parse_time(res[res_id]["end_time"])
            found = True
            break

    if found:
        return res[res_id]
    else:
        return create_dict()
Beispiel #14
0
def reservations():
    a = pyslurm.reservation()
    res_dict = a.get()
    resnodes = {}
    # for the purposes of backfill, we're only interested in the next res on a node,
    # and don't care if it's whole node or 1 core.
    # this will be incorrect for currently active res's that aren't whole node.
    for r, v in res_dict.items():
        if "node_list" in v.keys() and v["node_list"] is not None:
            for n in expandSlurmNodeList(v["node_list"]):
                if n in resnodes.keys():
                    tprev = resnodes[n]
                    if v["start_time"] < tprev:
                        resnodes[n] = v["start_time"]
                else:
                    resnodes[n] = v["start_time"]
    # print('resnodes.keys()', resnodes.keys())
    # print('resnodes', resnodes)
    return resnodes
Beispiel #15
0
    def create_reservation(self, num_machines, time, partition=None):
        if num_machines < 1:
            raise InvalidNumMachinesException(
                "Number of machines must be at least one.")

        epoch_now = int(time.time())

        res = pyslurm.reservation()
        res_dict = pyslurm.create_reservation_dict()
        res_dict["node_cnt"] = 1
        res_dict["users"] = os.environ['USER']
        if partition:
            res_dict["partition"] = partition
        res_dict["start_time"] = epoch_now
        res_dict["duration"] = time
        res_dict["name"] = "res_test"

        reservation_id = res.create(res_dict)
        return reservation_id
Beispiel #16
0
def get_reservations():

    reservations = get_from_cache(pyslurm.reservation().get,
                                  'get_reservations')
    return filter_entities('reservations', reservations)
Beispiel #17
0
def test_reservation_delete():
    """Reservation: Test reservation().delete()."""
    delete = pyslurm.reservation().delete("resv_test")
    count = pyslurm.reservation().get()
    assert_equals(delete, 0)
    assert_equals(len(count), 0)
Beispiel #18
0
def get_reservations():

    reservations = pyslurm.reservation().get()
    return reservations
Beispiel #19
0
def test_reservation_count():
    """Reservation: Test reservation count."""
    resv = pyslurm.reservation().get()
    assert_equals(len(resv), 1)
Beispiel #20
0
def get_reservations():
    if mocking:
        return mock('reservations.json')

    reservations = pyslurm.reservation().get()
    return reservations
Beispiel #21
0
def create_reservation(res_dict):
    r = pyslurm.reservation()
    print(res_dict)
    res_id = r.create(res_dict)
    return res_id
Beispiel #22
0
#!/usr/bin/env python

import pyslurm
import sys
import string
import time
import datetime

dstring = "2013-12-31T18:00:00"
dpattern = "%Y-%m-%dT%H:%M:%S"
start_epoch = int(time.mktime(time.strptime(dstring, dpattern)))

a = pyslurm.reservation()
res_dict = pyslurm.create_reservation_dict()
res_dict["node_cnt"] = 1
res_dict["users"] = "root"
res_dict["start_time"] = start_epoch
res_dict["duration"] = 600

resid = a.create(res_dict)
rc = pyslurm.slurm_get_errno()
if rc != 0:
	print "Failed - Error : %s" % pyslurm.slurm_strerror(pyslurm.slurm_get_errno())
	#sys.exit(-1)
else:
	print "Success - Created reservation %s\n" % resid

res_dict = a.get()
if res_dict.has_key(resid):

	date_fields = [ 'end_time', 'start_time' ]
Beispiel #23
0
def update_reservation(res_dict):
    r = pyslurm.reservation()
    return r.update(res_dict)
Beispiel #24
0
def delete_reservation(res_id, reason):
    r = pyslurm.reservation()
    return r.delete(res_id)
Beispiel #25
0
                    else:
                        ddate = pyslurm.epoch2date(value[res_key])
                        print("\t{0:<20} : {1}".format(res_key, ddate))
                else:
                    print("\t{0:<20} : {1}".format(res_key, value[res_key]))

        print('{0:*^80}'.format(''))

        now = int(time.time())
        resvState = "INACTIVE"

        if value['start_time'] <= now and value['end_time'] >= now:
            resvState = "ACTIVE"

        print("\t%-20s : %s\n" % ("state", resvState))


if __name__ == "__main__":

    try:
        a = pyslurm.reservation()
        res_dict = a.get()

        if len(res_dict) > 0:
            display(res_dict)
            print("Res IDs - {0}".format(a.ids()))
        else:
            print("No reservations found !")
    except ValueError as e:
        print("Error - {0}".format(e.args[0]))
Beispiel #26
0
def get_reservations():

    reservations = pyslurm.reservation().get()
    return reservations
Beispiel #27
0
def get_reservations():
    reservations = pyslurm.reservation().get()
    return jsonify(reservations)
Beispiel #28
0
def get_reserved_nodes(reservation_name):
    reservation = pyslurm.reservation().get()[reservation_name]
    return set(hostlist.expand_hostlist(reservation['node_list']))
Beispiel #29
0
def get_reservations():
    if mocking:
        return mock('reservations.json')

    reservations = pyslurm.reservation().get()
    return reservations
Beispiel #30
0
def test_reservation_delete():
    """Reservation: Test reservation().delete()."""
    delete = pyslurm.reservation().delete("resv_test")
    count = pyslurm.reservation().get()
    assert delete == 0
    assert len(count) == 0