]> mj.ucw.cz Git - bex.git/blob - lib/BEX/Config.pm
bls: Added a new utility for listing known machines and group
[bex.git] / lib / BEX / Config.pm
1 # Batch EXecutor 2.0 -- Configuration
2 # (c) 2011 Martin Mares <mj@ucw.cz>
3
4 use strict;
5 use warnings;
6
7 package BEX::Config;
8
9 # This file specifies default values, which can be overridden in BEX.cf
10
11 # A hash of all known machines and groups
12 # 'name' => { Option => ... }   for a machine; options:
13 #       Host => 'name'                  Host name to use in ssh, ping, ...
14 # 'name' => ['a','b','c']       for a group containing specified machines/subgroups
15 our %machines = (
16 );
17
18
19 # A file whose contents should be prepended before the job. Should start with the "#!" line.
20 our $job_prolog = 'prolog';
21
22 # A file whose contents should be appended to the job
23 our $job_epilog = 'epilog';
24
25 # Keep history of successfully completed jobs
26 our $keep_history = 1;
27
28 # Before we try to connect to a host, ping it to check if it's alive
29 our $ping_hosts = 1;
30
31 # Whenever we want to run a job on a machine, we must obtain a lock.
32 # Available locking schemes are:
33 #       none - no locking takes place (dangerous!)
34 #       job - obtain exclusive access to the job, other jobs on the same
35 #             host can run in parallel
36 #       host - obtain exclusive access to the host, other hosts can run
37 #       queue - obtain exclusive access to the whole queue
38 our $locking_scheme = 'host';
39
40 # Maximum number of simultaneously running jobs in `bprun'
41 our $max_parallel_jobs = 5;
42
43 # When a job fails, skip all other jobs on the same host
44 # (however, when locking_scheme is set to `job', another instance of `brun'
45 # still could run such jobs in parallel)
46 our $skip_on_fail = 0;
47
48 # How we run ssh (including options)
49 our $ssh_command = "ssh";
50
51 # Various utility functions
52
53 sub parse_machine_list(@);
54
55 sub parse_machine_list(@) {
56         my %set = ();
57         for my $m (@_) {
58                 if ($m eq '*') {
59                         for my $mm (keys %machines) {
60                                 if (ref($machines{$mm}) eq 'HASH') {
61                                         $set{$mm} = 1;
62                                 }
63                         }
64                         next;
65                 }
66                 my $op = 1;
67                 if ($m =~ s{^!}{}) { $op = 0; }
68                 my $v = $machines{$m};
69                 if (!defined $v) {
70                         die "Unknown machine or class: $m\n";
71                 } elsif (ref($v) eq 'HASH') {
72                         $set{$m} = $op;
73                 } elsif (ref($v) eq 'ARRAY') {
74                         for my $mm (parse_machine_list(@$v)) {
75                                 $set{$mm} = $op;
76                         }
77                 }
78         }
79         return sort grep { $set{$_} } keys %set;
80 }
81
82 sub host_name($) {
83         my ($mach) = @_;
84         return $machines{$mach}->{'Host'} // $mach;
85 }
86
87 require 'BEX.cf';
88
89 42;