source: devel/5.X/resmom.py

Last change on this file was 335, checked in by bas, 9 years ago

finally version of pbs_python to 5.X, still no working rm interface

File size: 3.7 KB
Line 
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#
12import string
13import types
14
15# Default linux resources to get from the mom
16#
17default_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#
31default_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
41default_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
58def 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
85def use_default_keywords(id, d):
86  """
87  Get the default values from the mom daemon
88  """
89  err = 0
90  for res in default_mom_res:
91    addreq(id, res)
92    resp = getreq(id)
93    check_resp(d, resp)
94
95  # Do not proceed if we have an empty dictionary
96  #
97  if not d:
98    return
99
100  if d['arch' ] == 'linux':
101    for res in default_linux_res:
102      addreq(id, res)
103      resp = getreq(id)
104      check_resp(d, resp)
105
106def use_user_keywords(id, d, l):
107  for res in l:
108    if type(res) is types.StringType:
109      addreq(id, res)
110      resp = getreq(id)
111      check_resp(d, resp)
112    else:
113      raise TypeError, 'Expected a string got %s :%s' %(type(res), res) 
114
115def get_mom_values(id, list = None):
116  """
117  This function will query the mom with a default resmon keywords
118  and 'arch' depended keywords. Supported archs are:
119    linux
120    irix6
121  User can also supply their own list of keywords as second parameter.
122  arguments:
123    id   : connection number with mom daemon on a node
124    list : optional parameter. If supplied then use this. A list
125           of mom keywords.
126  """
127
128  d = {}
129  if not list:
130    use_default_keywords(id, d)
131  else:
132    use_user_keywords(id, d , list)
133     
134  return d
Note: See TracBrowser for help on using the repository browser.