1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 CLI utility functions
23 """
24
25 import sys
26
27
28 from ClusterShell.NodeUtils import GroupResolverConfigError
29 try:
30 from ClusterShell.NodeSet import NodeSet
31 except GroupResolverConfigError, exc:
32 print >> sys.stderr, \
33 "ERROR: ClusterShell node groups configuration error:\n\t%s" % exc
34 sys.exit(1)
35
36 (KIBI, MEBI, GIBI, TEBI) = (1024.0, 1024.0 ** 2, 1024.0 ** 3, 1024.0 ** 4)
37
39 """
40 Format numerical `value` to display it using human readable unit with
41 binary prefix like (KiB, MiB, GiB, ...).
42 """
43 if value >= TEBI:
44 fmt = "%.2f TiB" % (value / TEBI)
45 elif value >= GIBI:
46 fmt = "%.2f GiB" % (value / GIBI)
47 elif value >= MEBI:
48 fmt = "%.2f MiB" % (value / MEBI)
49 elif value >= KIBI:
50 fmt = "%.2f KiB" % (value / KIBI)
51 else:
52 fmt = "%d B" % value
53 return fmt
54
56 """Compare 2 nodesets by their length (we want larger nodeset
57 first) and then by first node."""
58 len_cmp = cmp(len(ns2), len(ns1))
59 if not len_cmp:
60 smaller = NodeSet.fromlist([ns1[0], ns2[0]])[0]
61 if smaller == ns1[0]:
62 return -1
63 else:
64 return 1
65 return len_cmp
66
68 """Convenience function to compare 2 (buf, nodeset) tuples by their
69 nodeset length (we want larger nodeset first) and then by first
70 node."""
71
72 return nodeset_cmp(bn1[1], bn2[1])
73