diff --git a/batchoar.py b/batchoar.py index 6b52d35d8ff56706c2250070feacedcc935f3fcc..ee906bae801b67ae89a53e9a7d856ff49fc4dac8 100755 --- a/batchoar.py +++ b/batchoar.py @@ -23,8 +23,10 @@ def argparser(): help="If True, reserves only cores with GPUs") parser.add_argument('-c', '--core', default=1, type=int, help="Number of cores to reserve") - parser.add_argument('-H', '--host', - help="Name of the host (SQL LIKE syntax accepted)") + parser.add_argument('-H', '--host', nargs="+", default=[], + help="Name of the hosts (SQL 'LIKE' syntax accepted)") + parser.add_argument('-I', '--ignore-host', nargs="+", default=[], + help="Name of the hosts to ignore (SQL 'NOT LIKE' syntax accepted)") parser.add_argument('-i', '--interactive', action="store_true", help="Launch job in interactive mode") parser.add_argument('-C', '--checkpoint', type=int, metavar="SECONDS", @@ -95,7 +97,7 @@ def load_jobs(yaml_in, args): yaml_jobs = yaml.load(yaml_in) var_names, var_tuples = load_variables(yaml_jobs["variables"]) - constants = yaml_jobs["constants"] + constants = yaml_jobs["constants"] if "constants" in yaml_jobs else {} flags = load_flags(yaml_jobs["flags"], args) try: precommand = yaml_jobs["environment"]["precommand"] @@ -142,6 +144,7 @@ def main(): anterior = anteriors.pop() oar_command = oargen.prepare_oarsub(args.gpu, args.host, args.core, args.time, + ignore_hosts=args.ignore_host, command=job, name=job_name, output_directory=args.directory, besteffort=args.besteffort, diff --git a/oargen.py b/oargen.py index 0b24f6d293c3fef7f4082b41d37365692b8ce032..4d273fa3e97af253e9676467ec8da8567b696536 100755 --- a/oargen.py +++ b/oargen.py @@ -27,8 +27,10 @@ def argparser(): help="If True, reserves only cores with GPUs") parser.add_argument('-c', '--core', default=1, type=int, help="Number of cores to reserve") - parser.add_argument('-H', '--host', - help="Name of the host (SQL LIKE syntax accepted)") + parser.add_argument('-H', '--host', nargs="+", default=[], + help="Name of the hosts (SQL 'LIKE' syntax accepted)") + parser.add_argument('-I', '--ignore-host', nargs="+", default=[], + help="Name of the hosts to ignore (SQL 'NOT LIKE' syntax accepted)") parser.add_argument('-i', '--interactive', action="store_true", help="Launch job in interactive mode") parser.add_argument('-C', '--checkpoint', type=int, metavar="SECONDS", @@ -42,7 +44,8 @@ def argparser(): return args -def prepare_oarsub(gpu, host, core, time, +def prepare_oarsub(gpu, hosts, core, time, + ignore_hosts=[], command=None, interactive=False, name=None, output_directory=None, @@ -55,8 +58,12 @@ def prepare_oarsub(gpu, host, core, time, properties += "(gpu IS NOT NULL)" else: properties += "(gpu IS NULL)" - if host is not None: - properties += " AND host LIKE '{}'".format(host) + if hosts: + for host in hosts: + properties += " AND host LIKE '{}'".format(host) + if ignore_hosts: + for host in ignore_hosts: + properties += " AND host NOT LIKE '{}'".format(host) properties += "" oar_cmd.append(properties)