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 add_to_namespace('processes', processes)
33
34
35
36
37
38 -def ifelse(predicate, if_true, if_false):
39 """Returns C{if_true} if C{predicate} is true, C{if_false} otherwise.
40 Both C{if_true} and C{if_false} are evaluated unconditionally.
41 (This function is provided because the Python equivalent, the if expression,
42 is not present prior to release 2.5.)
43 """
44 if predicate:
45 return if_true
46 else:
47 return if_false
48
49 add_to_namespace('ifelse', ifelse)
50
51
52
53
54
56 """Returns the value of C{cluster_name}'s C{hosts} configuration value,
57 as specified in C{.oshrc}. Returns a map containing entries
58 in which the key is the node's name, and the value is the node's
59 IP address or DNS name.
60 """
61 map = {}
62 cluster = cluster_named(cluster_name)
63 if cluster:
64 for host in cluster.hosts:
65 map[host.name] = host.address
66 return map
67 else:
68 return None
69
70 add_to_namespace('hosts', hosts)
71