1 | # PBS python interface |
---|
2 | # Author: Bas van der Vlies <bas.vandervlies@surfsara.nl> |
---|
3 | # Date : 27 Feb 2002 |
---|
4 | # Desc. : This is python wrapper class for getting the resource |
---|
5 | # mom values. |
---|
6 | # |
---|
7 | # CVS info |
---|
8 | # $Id: resmom.py,v 1.6 2002/10/21 14:14:47 sscpbas Exp $ |
---|
9 | # $Date: 2002/10/21 14:14:47 $ |
---|
10 | # $Revision: 1.6 $ |
---|
11 | # |
---|
12 | import string |
---|
13 | import types |
---|
14 | |
---|
15 | # Default linux resources to get from the mom |
---|
16 | # |
---|
17 | default_linux_res = [ |
---|
18 | "availmem", # available memory size in KB |
---|
19 | "ideal_load", # static ideal_load value |
---|
20 | "loadave", # the current load average |
---|
21 | "max_load", # static max_load value |
---|
22 | "ncpus", # number of cpus |
---|
23 | "physmem", # physical memory size in KB |
---|
24 | "resi", # resident memory size for a pid or session in KB |
---|
25 | "totmem", # total memory size in KB |
---|
26 | "walltime", # wall clock time for a pid |
---|
27 | ] |
---|
28 | |
---|
29 | # Default irix6 resources to get from the mom |
---|
30 | # |
---|
31 | default_irix6_res = [ |
---|
32 | "availmem", # available memory size in KB |
---|
33 | "loadave", # the current load average |
---|
34 | "ncpus", # number of cpus |
---|
35 | "physmem", # physical memory size in KB |
---|
36 | "resi", # resident memory size for a pid or session in KB |
---|
37 | "walltime", # wall clock time for a pid |
---|
38 | "quota", # quota information (sizes in KB) |
---|
39 | ] |
---|
40 | |
---|
41 | default_mom_res = [ |
---|
42 | "arch", # the architecture of the machine |
---|
43 | "uname", # the architecture of the machine |
---|
44 | "cput", # cpu time for a pid or session |
---|
45 | "idletime", # seconds of idle time |
---|
46 | "mem", # memory size for a pid or session in KB |
---|
47 | "sessions", # list of sessions in the system |
---|
48 | "pids", # list of pids in a session |
---|
49 | "nsessions", # number of sessions in the system |
---|
50 | "nusers", # number of users in the system |
---|
51 | "size", # size of a file or filesystem |
---|
52 | "host", # Name of host on which job should be run |
---|
53 | "nodes", # Number and/or type of nodes to be reserved for exclusive use by the job |
---|
54 | "other", # Allows a user to specify site specific information |
---|
55 | "software", # Allows a user to specify software required by the job |
---|
56 | ] |
---|
57 | |
---|
58 | def check_resp(dict, str): |
---|
59 | """ |
---|
60 | Check the daemon response. If we have no permission to |
---|
61 | query the values then we got a 'None' response. Else |
---|
62 | if we supplied a keyword that does not exits we get a |
---|
63 | '?' response |
---|
64 | """ |
---|
65 | if not str: |
---|
66 | return |
---|
67 | |
---|
68 | ## Value can contain the '=' char :-( |
---|
69 | # |
---|
70 | l = string.split(str, '=') |
---|
71 | key = string.strip(l[0]) |
---|
72 | if len(l) > 2: |
---|
73 | val = string.strip( '='.join(l[1:]) ) |
---|
74 | else: |
---|
75 | val = string.strip(l[1]) |
---|
76 | |
---|
77 | key = string.strip(key) |
---|
78 | val = string.strip(val) |
---|
79 | |
---|
80 | # Did we got a valid response |
---|
81 | # |
---|
82 | if not val[0] == '?': |
---|
83 | dict[key] = val |
---|
84 | |
---|
85 | def use_default_keywords(id, d): |
---|
86 | """ |
---|
87 | Get the default values from the mom daemon |
---|
88 | """ |
---|
89 | for res in default_mom_res: |
---|
90 | addreq(id, res) |
---|
91 | resp = getreq(id) |
---|
92 | check_resp(d, resp) |
---|
93 | |
---|
94 | # Do not proceed if we have an empty dictionary |
---|
95 | # |
---|
96 | if not d: |
---|
97 | return |
---|
98 | |
---|
99 | if d['arch' ] == 'linux': |
---|
100 | for res in default_linux_res: |
---|
101 | addreq(id, res) |
---|
102 | resp = getreq(id) |
---|
103 | check_resp(d, resp) |
---|
104 | |
---|
105 | def use_user_keywords(id, d, l): |
---|
106 | for res in l: |
---|
107 | if type(res) is types.StringType: |
---|
108 | addreq(id, res) |
---|
109 | resp = getreq(id) |
---|
110 | check_resp(d, resp) |
---|
111 | else: |
---|
112 | raise TypeError, 'Expected a string got %s :%s' %(type(res), res) |
---|
113 | |
---|
114 | def get_mom_values(id, list = None): |
---|
115 | """ |
---|
116 | This function will query the mom with a default resmon keywords |
---|
117 | and 'arch' depended keywords. Supported archs are: |
---|
118 | linux |
---|
119 | irix6 |
---|
120 | User can also supply their own list of keywords as second parameter. |
---|
121 | arguments: |
---|
122 | id : connection number with mom daemon on a node |
---|
123 | list : optional parameter. If supplied then use this. A list |
---|
124 | of mom keywords. |
---|
125 | """ |
---|
126 | |
---|
127 | d = {} |
---|
128 | if not list: |
---|
129 | use_default_keywords(id, d) |
---|
130 | else: |
---|
131 | use_user_keywords(id, d , list) |
---|
132 | |
---|
133 | return d |
---|