1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """This module contains miscellaneous functions builtin to osh.
19 See also the C{osh.process} module for other builtins.
20 """
21
22 import config
23 from core import add_to_namespace
24 from cluster import cluster_named
25
26
27
28
29
30 from process import processes
31
32
33
34
35
36 -def ifelse(predicate, if_true, if_false):
37 """Returns C{if_true} if C{predicate} is true, C{if_false} otherwise.
38 Both C{if_true} and C{if_false} are evaluated unconditionally.
39 (This function is provided because the Python equivalent, the if expression,
40 is not present prior to release 2.5.)
41 """
42 if predicate:
43 return if_true
44 else:
45 return if_false
46
47
48
49
50
52 """Returns the value of C{cluster_name}'s C{hosts} configuration value,
53 as specified in C{.oshrc}. Returns a map containing entries
54 in which the key is the node's name, and the value is the node's
55 IP address or DNS name.
56 """
57 cluster = cluster_named(cluster_name)
58 map = {}
59 for host in cluster.hosts:
60 map[host.name] = host.address
61 return map
62
63
64
65 add_to_namespace('processes', processes)
66 add_to_namespace('ifelse', ifelse)
67 add_to_namespace('hosts', hosts)
68