source: devel/5.X/resmom.py @ 327

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

some small improvements but no working rm interface

File size: 3.9 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  print default_mom_res
91  for res in default_mom_res:
92    print res
93    #addreq(id, res)
94    addreq_err(id, err, res) 
95    print err
96    #resp = getreq(id)
97    resp = getreq_err(err, id)
98    print "error: ", err
99
100    print resp,id
101    check_resp(d, resp)
102
103  # Do not proceed if we have an empty dictionary
104  #
105  if not d:
106    return
107
108  if d['arch' ] == 'linux':
109    for res in default_linux_res:
110      addreq(id, res)
111      resp = getreq(id)
112      check_resp(d, resp)
113
114def use_user_keywords(id, d, l):
115  for res in l:
116    if type(res) is types.StringType:
117      addreq(id, res)
118      resp = getreq(id)
119      check_resp(d, resp)
120    else:
121      raise TypeError, 'Expected a string got %s :%s' %(type(res), res) 
122
123def get_mom_values(id, list = None):
124  """
125  This function will query the mom with a default resmon keywords
126  and 'arch' depended keywords. Supported archs are:
127    linux
128    irix6
129  User can also supply their own list of keywords as second parameter.
130  arguments:
131    id   : connection number with mom daemon on a node
132    list : optional parameter. If supplied then use this. A list
133           of mom keywords.
134  """
135
136  d = {}
137  if not list:
138    use_default_keywords(id, d)
139  else:
140    use_user_keywords(id, d , list)
141     
142  return d
Note: See TracBrowser for help on using the repository browser.