def __init__(self, pbs_obj_name, pbs_filter1, pbs_filter2, connect_server=None): self._caller = _pbs_v1.get_python_daemon_name() if self._caller == "pbs_python": if( connect_server == None ): self._connect_server = "localhost" sn = "" else: self._connect_server = connect_server sn = connect_server self.type = pbs_obj_name if _pbs_v1.use_static_data(): if( self.type == "jobs" ): self.bs=iter(_pbs_v1.get_job_static("", sn, "")) elif( self.type == "queues" ): self.bs=iter(_pbs_v1.get_queue_static("", sn)) elif( self.type == "vnodes" ): self.bs=iter(_pbs_v1.get_vnode_static("", sn)) elif( self.type == "resvs" ): self.bs=iter(_pbs_v1.get_resv_static("", sn)) else: _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG, "pbs_iter/init: Bad object iterator type %s" % (self.type)) return None return self.con=pbs_connect(self._connect_server) if self.con < 0: _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG,\ "pbs_iter: Unable to connect to server %s" % (connect_server)) return None if( self.type == "jobs" ): self.bs=pbs_statjob(self.con, pbs_filter2, None, None) elif( self.type == "queues" ): self.bs=pbs_statque(self.con, None, None, None) elif( self.type == "vnodes" ): self.bs=pbs_statvnode(self.con, None, None, None) elif( self.type == "resvs" ): self.bs=pbs_statresv(self.con, None, None, None) else: _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG, "pbs_iter/init: Bad object iterator type %s" % (self.type)) pbs_disconnect(self.con) self.con = -1 return None else: self.obj_name = pbs_obj_name self.filter1 = pbs_filter1 self.filter2 = pbs_filter2 # argument 1 below tells C function we're inside __init__ _pbs_v1.iter_nextfunc(self, 1, pbs_obj_name, pbs_filter1, pbs_filter2)
def server(): if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): return _pbs_v1.get_server_static() connect_server = _pbs_v1.get_pbs_server_name() return pbs_statobj("server", None, connect_server) else: return _pbs_v1.server()
def server(): if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): return _pbs_v1.get_server_static(); connect_server = _pbs_v1.get_pbs_server_name() return pbs_statobj("server", None, connect_server) else: return _pbs_v1.server()
def resv(self, resvid): """Return a resv object representing resvid""" if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_resv_static(resvid, sn) return pbs_statobj("resv", resvid, self._connect_server) else: return _pbs_v1.get_resv(resvid)
def resv(self, resvid): """Return a resv object representing resvid""" if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_resv_static(resvid, sn); return pbs_statobj("resv", resvid, self._connect_server) else: return _pbs_v1.get_resv(resvid)
def vnode(self, vname): """ vnode(strVname) strVname - PBS vnode name to query. Returns a vnode object representing vname """ if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_vnode_static(vname, sn) return pbs_statobj("vnode", vname, self._connect_server) else: return _pbs_v1.get_vnode(vname)
def vnode(self, vname): """ vnode(strVname) strVname - PBS vnode name to query. Returns a vnode object representing vname """ if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_vnode_static(vname, sn); return pbs_statobj("vnode", vname, self._connect_server) else: return _pbs_v1.get_vnode(vname)
def job(self, jobid): """ job(strJobid) strJobid - PBS jobid to query. Returns a job object representing jobid """ if jobid.find(".") == -1: jobid = jobid + "." + _pbs_v1.get_pbs_server_name() if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_job_static(jobid, sn, "") return pbs_statobj("job", jobid, self._connect_server) else: return _pbs_v1.get_job(jobid)
def job(self, jobid): """ job(strJobid) strJobid - PBS jobid to query. Returns a job object representing jobid """ if jobid.find(".") == -1: jobid = jobid + "." + _pbs_v1.get_pbs_server_name() if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_job_static(jobid, sn, ""); return pbs_statobj("job", jobid, self._connect_server) else: return _pbs_v1.get_job(jobid)
def queue(self, qname): """ queue(strQname) strQname - name of a PBS queue (without the @host part) to query. Returns a queue object representing the queue <queue name> that is managed by server s. """ if qname.find("@") != -1: raise AssertionError(\ "Got '%s', please specify a queue name only (no @)" % (qname,)) if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_queue_static(qname, sn) return pbs_statobj("queue", qname, self._connect_server) else: return _pbs_v1.get_queue(qname)
def job(self, jobid): """Return a job object representing jobid that belongs to queue""" if jobid.find(".") == -1: jobid = jobid + "." + _pbs_v1.get_pbs_server_name() if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server if self.name is None: qn = "" else: qn = self.name return _pbs_v1.get_job_static(jobid, sn, qn) return pbs_statobj("job", jobid, self._connect_server, self.name) else: return _pbs_v1.get_job(jobid, self.name)
def queue(self, qname): """ queue(strQname) strQname - name of a PBS queue (without the @host part) to query. Returns a queue object representing the queue <queue name> that is managed by server s. """ if qname.find("@") != -1: raise AssertionError(\ "Got '%s', please specify a queue name only (no @)" % (qname,)) if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server return _pbs_v1.get_queue_static(qname, sn); return pbs_statobj("queue", qname, self._connect_server) else: return _pbs_v1.get_queue(qname)
def job(self, jobid): """Return a job object representing jobid that belongs to queue""" if jobid.find(".") == -1: jobid = jobid + "." + _pbs_v1.get_pbs_server_name() if _pbs_v1.get_python_daemon_name() == "pbs_python": if _pbs_v1.use_static_data(): if self._connect_server is None: sn = "" else: sn = self._connect_server if self.name is None: qn = "" else: qn = self.name return _pbs_v1.get_job_static(jobid, sn, qn); return pbs_statobj("job", jobid, self._connect_server, self.name) else: return _pbs_v1.get_job(jobid, self.name)
def next(self): if self._caller == "pbs_python": if not hasattr(self, "bs") or self.bs == None: if not _pbs_v1.use_static_data(): pbs_disconnect(self.con) self.con = -1 raise StopIteration if _pbs_v1.use_static_data(): if (self.type == "jobs"): return _pbs_v1.get_job_static(self.bs.next(), self._connect_server, "") elif (self.type == "queues"): return _pbs_v1.get_queue_static( self.bs.next(), self._connect_server) elif (self.type == "resvs"): return _pbs_v1.get_resv_static(self.bs.next(), self._connect_server) elif (self.type == "vnodes"): return _pbs_v1.get_vnode_static( self.bs.next(), self._connect_server) else: _pbs_v1.logmsg( _pbs_v1.LOG_DEBUG, "pbs_iter/next: Bad object iterator type %s" % (self.type)) raise StopIteration return b = self.bs job = None _pbs_v1.set_c_mode() server_data_fp = _pbs_v1.get_server_data_fp() if (b): if (self.type == "jobs"): obj = _job(b.name, self._connect_server) header_str = "pbs.server().job(%s)" % (b.name, ) elif (self.type == "queues"): obj = _queue(b.name, self._connect_server) header_str = "pbs.server().queue(%s)" % (b.name, ) elif (self.type == "resvs"): obj = _resv(b.name, self._connect_server) header_str = "pbs.server().resv(%s)" % (b.name, ) elif (self.type == "vnodes"): obj = _vnode(b.name, self._connect_server) header_str = "pbs.server().vnode(%s)" % (b.name, ) else: _pbs_v1.logmsg( _pbs_v1.LOG_DEBUG, "pbs_iter/next: Bad object iterator type %s" % (self.type)) pbs_disconnect(self.con) self.con = -1 _pbs_v1.set_python_mode() raise StopIteration a = b.attribs while (a): n = a.name r = a.resource v = a.value if (self.type == "vnodes"): if (n == ATTR_NODE_state): v = _pbs_v1.str_to_vnode_state(v) elif (n == ATTR_NODE_ntype): v = _pbs_v1.str_to_vnode_ntype(v) elif (n == ATTR_NODE_Sharing): v = _pbs_v1.str_to_vnode_sharing(v) if (self.type == "jobs"): if n == ATTR_inter or n == ATTR_block or n == ATTR_X11_port: v = int(pbs_bool(v)) if (r): pr = getattr(obj, n) # if resource list does not exist, then set it if (pr == None): setattr(obj, n) pr = getattr(obj, n) if (pr == None): _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG, "pbs_statobj: missing %s" % (n)) a = a.next continue vo = getattr(pr, r) if (vo == None): setattr(pr, r, v) if server_data_fp: server_data_fp.write("%s.%s[%s]=%s\n" % (header_str, n, r, v)) else: # append value: # example: "select=1:ncpus=1,ncpus=1,nodect=1,place=pack" vl = [vo, v] setattr(pr, r, ",".join(vl)) if server_data_fp: server_data_fp.write( "%s.%s[%s]=%s\n" % (header_str, n, r, ",".join(vl))) else: vo = getattr(obj, n) if (vo == None): setattr(obj, n, v) if server_data_fp: server_data_fp.write("%s.%s=%s\n" % (header_str, n, v)) else: vl = [vo, v] setattr(obj, n, ",".join(vl)) if server_data_fp: server_data_fp.write( "%s.%s=%s\n" % (header_str, n, ",".join(vl))) a = a.next self.bs = b.next _pbs_v1.set_python_mode() return obj else: # argument 0 below tells C function we're inside next return _pbs_v1.iter_nextfunc(self, 0, self.obj_name, self.filter1, self.filter2)
def next(self): if self._caller == "pbs_python": if not hasattr(self, "bs") or self.bs == None: if not _pbs_v1.use_static_data(): pbs_disconnect(self.con) self.con = -1 raise StopIteration if _pbs_v1.use_static_data(): if( self.type == "jobs" ): return _pbs_v1.get_job_static(self.bs.next(), self._connect_server, "") elif( self.type == "queues" ): return _pbs_v1.get_queue_static(self.bs.next(), self._connect_server) elif( self.type == "resvs" ): return _pbs_v1.get_resv_static(self.bs.next(), self._connect_server) elif( self.type == "vnodes" ): return _pbs_v1.get_vnode_static(self.bs.next(), self._connect_server) else: _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG, "pbs_iter/next: Bad object iterator type %s" % (self.type)) raise StopIteration return b = self.bs job = None _pbs_v1.set_c_mode() server_data_fp = _pbs_v1.get_server_data_fp(); if(b): if( self.type == "jobs" ): _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG,\ "pbs_iter/next: pbs_python mode not supported by NAS local mod") pbs_disconnect(self.con) self.con = -1 _pbs_v1.set_python_mode() raise StopIteration elif( self.type == "queues" ): obj=_queue(b.name, self._connect_server) header_str = "pbs.server().queue(%s)" % (b.name,) elif( self.type == "resvs" ): obj=_resv(b.name, self._connect_server) header_str = "pbs.server().resv(%s)" % (b.name,) elif( self.type == "vnodes" ): obj=_vnode(b.name, self._connect_server) header_str = "pbs.server().vnode(%s)" % (b.name,) else: _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG, "pbs_iter/next: Bad object iterator type %s" % (self.type)) pbs_disconnect(self.con) self.con = -1 _pbs_v1.set_python_mode() raise StopIteration a=b.attribs while(a): n=a.name r=a.resource v=a.value if( self.type == "vnodes" ): if( n == ATTR_NODE_state ): v=_pbs_v1.str_to_vnode_state(v) elif( n == ATTR_NODE_ntype ): v=_pbs_v1.str_to_vnode_ntype(v) elif( n == ATTR_NODE_Sharing ): v=_pbs_v1.str_to_vnode_sharing(v) if( self.type == "jobs" ): if n == ATTR_inter or n == ATTR_block or n == ATTR_X11_port: v=int(pbs_bool(v)) if(r): pr=getattr(obj,n) # if resource list does not exist, then set it if( pr == None): setattr(obj,n) pr=getattr(obj,n) if (pr == None): _pbs_v1.logmsg(_pbs_v1.LOG_DEBUG, "pbs_statobj: missing %s" % (n)) a=a.next continue vo=getattr(pr, r) if( vo == None ): setattr(pr,r,v) if server_data_fp: server_data_fp.write("%s.%s[%s]=%s\n" %(header_str,n,r,v)) else: # append value: # example: "select=1:ncpus=1,ncpus=1,nodect=1,place=pack" vl=[vo, v] setattr(pr, r, ",".join(vl)) if server_data_fp: server_data_fp.write("%s.%s[%s]=%s\n" % (header_str, n,r,",".join(vl))) else: vo=getattr(obj,n) if( vo == None ): setattr(obj,n,v) if server_data_fp: server_data_fp.write("%s.%s=%s\n" %(header_str,n,v)) else: vl=[vo, v] setattr(obj, n, ",".join(vl)) if server_data_fp: server_data_fp.write("%s.%s=%s\n" % (header_str, n, ",".join(vl))) a=a.next self.bs=b.next _pbs_v1.set_python_mode() return obj else: # argument 0 below tells C function we're inside next return _pbs_v1.iter_nextfunc(self, 0, self.obj_name, self.filter1, self.filter2, self.ignore_fin, self.filter_user)