Пример #1
0
	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) 
Пример #2
0
	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) 
Пример #3
0
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()
Пример #4
0
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()
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    def __init__(self, value, generic=False):
        # if generic is True, this means to use pbs_env() type in a
        # generic way, so that the PBS-related variables (e.g. PBS_O*)
        # are allowed to be modified.
        self._generic = generic
        if isinstance(value, (str, )):
            # temporarily replace "<esc_char>," with something we
            # don't expect to see: two etx <ascii code 3>
            # since ',' is used as a separator among env variables.
            # NOTE: We take care here of also catching "\\," which is
            #       legal as in:  DPATH=\\a\\b\\,MP_MSG_API=MPI\,LAPI
            #       which must break down to:
            #           v['DPATH'] = "\\a\\b\\"
            #	       v['MP_MSG_API'] = "MPI\,LAPI"
            if (sys.platform == "win32"):
                esc_char = "^"
            else:
                esc_char = "\\"
            double_stx = "\x02\x02"
            double_etx = "\x03\x03"
            value1 = value.replace(esc_char + esc_char,
                                   double_stx).replace(esc_char + ",",
                                                       double_etx)
            vals = value1.split(",")
            ev = {}
            for v in vals:
                # now restore "<esc_char>,"
                v1 = v.replace(double_etx,
                               esc_char + ",").replace(double_stx,
                                                       esc_char + esc_char)
                e = v1.split("=", 1)

                if len(e) == 2:

                    vue = e[1]
                    if isinstance(e[1], (str, )):
                        if (_pbs_v1.get_python_daemon_name() != "pbs_python") \
                                                 or (sys.platform != "win32"):
                            # replace \ with \\ if not used to escape special chars
                            # note: no need to do this under a Windows mom since
                            #       backslash is recognized as path character
                            vue = replace_char_not_before(e[1], \
                                '\\', '\\\\', [ ',', '\'', '\"', '\\'])
                    ev.update({e[0]: vue})
        else:
            ev = value
        super(pbs_env, self).__init__(ev)
Пример #8
0
    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)
Пример #9
0
    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)
Пример #10
0
 def __setitem__(self, name, value):
     """__setitem__"""
     # pbs builtin variables are off limits except under a PBS hook
     if name in pbs_env._attributes_readonly and \
         _pbs_v1.in_python_mode() and _pbs_v1.in_site_hook() and \
                                       not getattr(self, "_generic"):
         raise BadAttributeValueError("env variable '%s' is readonly" % (name,))
     v = value
     if isinstance(value, (str,)):
         if (_pbs_v1.get_python_daemon_name() != "pbs_python") \
                                              or (sys.platform != "win32"):
             # replace \ with \\ if not used to escape special chars
             # note: no need to do this on a Windows mom 
             #       since backslash is recognized as path character
             v = replace_char_not_before(value, '\\', '\\\\',
                                        [ ',', '\'', '\"', '\\'])
     super(pbs_env,self).__setitem__(name, v)
Пример #11
0
 def __setitem__(self, name, value):
     """__setitem__"""
     # pbs builtin variables are off limits except under a PBS hook
     if name in pbs_env._attributes_readonly and \
         _pbs_v1.in_python_mode() and _pbs_v1.in_site_hook() and \
                                       not getattr(self, "_generic"):
         raise BadAttributeValueError("env variable '%s' is readonly" % (name,))
     v = value
     if isinstance(value, (str,)):
         if (_pbs_v1.get_python_daemon_name() != "pbs_python") \
                                              or (sys.platform != "win32"):
             # replace \ with \\ if not used to escape special chars
             # note: no need to do this on a Windows mom 
             #       since backslash is recognized as path character
             v = replace_char_not_before(value, '\\', '\\\\',
                                        [ ',', '\'', '\"', '\\'])
     super(pbs_env,self).__setitem__(name, v)
Пример #12
0
    def __init__(self,value,generic=False):
        # if generic is True, this means to use pbs_env() type in a
        # generic way, so that the PBS-related variables (e.g. PBS_O*)
        # are allowed to be modified.
        self._generic = generic
        if isinstance(value,(str,)):
            # temporarily replace "<esc_char>," with something we
            # don't expect to see: two etx <ascii code 3>
            # since ',' is used as a separator among env variables.
            # NOTE: We take care here of also catching "\\," which is
            #       legal as in:  DPATH=\\a\\b\\,MP_MSG_API=MPI\,LAPI
            #       which must break down to:
            #           v['DPATH'] = "\\a\\b\\"
            #	       v['MP_MSG_API'] = "MPI\,LAPI"
            if (sys.platform == "win32"):
                 esc_char = "^"
            else: 
                 esc_char = "\\"
            double_stx="\x02\x02"
            double_etx="\x03\x03"
            value1 = value.replace(esc_char + esc_char, double_stx).replace(esc_char + ",", double_etx)
            vals = value1.split(",")
            ev = {}
            for v in vals:
                # now restore "<esc_char>,"
                v1 = v.replace(double_etx, esc_char + ",").replace(double_stx, esc_char + esc_char)
                e = v1.split("=",1)

                if len(e) == 2:

                    vue = e[1]
                    if isinstance(e[1], (str,)):
                        if (_pbs_v1.get_python_daemon_name() != "pbs_python") \
                                                 or (sys.platform != "win32"):
                            # replace \ with \\ if not used to escape special chars
                            # note: no need to do this under a Windows mom since
                            #       backslash is recognized as path character
                            vue = replace_char_not_before(e[1], \
                                '\\', '\\\\', [ ',', '\'', '\"', '\\'])
                    ev.update({e[0] : vue})
        else:
            ev = value
        super(pbs_env,self).__init__(ev)
Пример #13
0
    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)
Пример #14
0
    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)
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
    def __setattr__(self, nameo, value):
        """__setattr__"""

        name = nameo
        if (nameo == "_readonly"):
            if _pbs_v1.in_python_mode() and \
                    hasattr(self, "_readonly") and not value:
                raise BadResourceValueError("_readonly can only be set to True!")
        elif (nameo != "_has_value") and (nameo != "_is_entity"):
            # _has_value is a special, resource attribute that tells if a
            # resource instance is already holding its value (i.e. value
            # is not cached somewhere else).
            # _is_entity is also a special attribute that tells if the
            # resource instance is an entity resource type. 

            # resource names in PBS are case insensitive,
            # so do caseless matching here.
            found = False
            namel = nameo.lower()
            for resc in pbs_resource.attributes:
                rescl = resc.lower()
                if namel == rescl:
                   # Need to use the matched name stored in PBS Python resource
	           # table, to avoid resource ambiguity later on.
                   name = resc
                   found = True

            if not found:

                if _pbs_v1.in_python_mode():
                    # if attribute name not found,and executing inside Python script
                    if _pbs_v1.get_python_daemon_name() != "pbs_python":
                        # we're in a server hook  
                        raise UnsetResourceNameError("resource attribute '%s' not found" % (name,)) 

                    # we're in a mom hook, so no longer raising an exception here since if
                    # it's an unknown resource, we can now tell server to
                    # automatically add a custom resource.
                    if not self._attributes_unknown.has_key(self):
                        self._attributes_unknown[self] = {}
                    # add the current attribute name to the "unknown" list
                    self._attributes_unknown[self].update({name : None})
                else:
                    if not self._attributes_unknown.has_key(self):
                        self._attributes_unknown[self] = {}
                    # add the current attribute name to the "unknown" list
                    self._attributes_unknown[self].update({name : None})

        super(pbs_resource,self).__setattr__(name, value)

        # attributes that are set in python mode will be reflected in
        # _attributes_hook_set dictionary.
        # For example, 
        # _attributes_hook_set[<pbs_resource object>]=['walltime', 'mem']
        # if 'walltime' or 'mem' has been assigned a value within the hook
        # script, or been unset.
        if _pbs_v1.in_python_mode():
            if not self._attributes_hook_set.has_key(self):
                self._attributes_hook_set[self] = {}
            # using a dictionary value as easier to search for keys
            self._attributes_hook_set[self].update({name : None})
Пример #20
0
    def __setattr__(self, nameo, value):
        """__setattr__"""

        name = nameo
        if (nameo == "_readonly"):
            if _pbs_v1.in_python_mode() and \
                    hasattr(self, "_readonly") and not value:
                raise BadResourceValueError("_readonly can only be set to True!")
        elif (nameo != "_has_value") and (nameo != "_is_entity"):
            # _has_value is a special, resource attribute that tells if a
            # resource instance is already holding its value (i.e. value
            # is not cached somewhere else).
            # _is_entity is also a special attribute that tells if the
            # resource instance is an entity resource type. 

            # resource names in PBS are case insensitive,
            # so do caseless matching here.
            found = False
            namel = nameo.lower()
            for resc in pbs_resource.attributes:
                rescl = resc.lower()
                if namel == rescl:
                   # Need to use the matched name stored in PBS Python resource
	           # table, to avoid resource ambiguity later on.
                   name = resc
                   found = True

            if not found:

                if _pbs_v1.in_python_mode():
                    # if attribute name not found,and executing inside Python script
                    if _pbs_v1.get_python_daemon_name() != "pbs_python":
                        # we're in a server hook  
                        raise UnsetResourceNameError("resource attribute '%s' not found" % (name,)) 

                    # we're in a mom hook, so no longer raising an exception here since if
                    # it's an unknown resource, we can now tell server to
                    # automatically add a custom resource.
                    if not self._attributes_unknown.has_key(self):
                        self._attributes_unknown[self] = {}
                    # add the current attribute name to the "unknown" list
                    self._attributes_unknown[self].update({name : None})
                else:
                    if not self._attributes_unknown.has_key(self):
                        self._attributes_unknown[self] = {}
                    # add the current attribute name to the "unknown" list
                    self._attributes_unknown[self].update({name : None})

        super(pbs_resource,self).__setattr__(name, value)

        # attributes that are set in python mode will be reflected in
        # _attributes_hook_set dictionary.
        # For example, 
        # _attributes_hook_set[<pbs_resource object>]=['walltime', 'mem']
        # if 'walltime' or 'mem' has been assigned a value within the hook
        # script, or been unset.
        if _pbs_v1.in_python_mode():
            if not self._attributes_hook_set.has_key(self):
                self._attributes_hook_set[self] = {}
            # using a dictionary value as easier to search for keys
            self._attributes_hook_set[self].update({name : None})
Пример #21
0
(server,queue,job,resv, etc.)
"""
from _base_types import (PbsAttributeDescriptor, PbsReadOnlyDescriptor,
                         pbs_resource, pbs_bool, _LOG,
                         )
import _pbs_v1
from _pbs_v1 import (_event_accept, _event_reject,
                    _event_param_mod_allow, _event_param_mod_disallow,
                    iter_nextfunc)

from _exc_types import *

NAS_mod = 0

try:
        if _pbs_v1.get_python_daemon_name() == "pbs_python":
            from _pbs_ifl import *
            from pbs_ifl import *
except:
        pass

# Set global hook_config_filename parameter.
hook_config_filename = None
try:
    import os

    if "PBS_HOOK_CONFIG_FILE" in os.environ:
        hook_config_filename = os.environ["PBS_HOOK_CONFIG_FILE"]
except:
    pass
Пример #22
0
    PbsAttributeDescriptor,
    PbsReadOnlyDescriptor,
    pbs_resource,
    pbs_bool,
    _LOG,
)
import _pbs_v1
from _pbs_v1 import (_event_accept, _event_reject, _event_param_mod_allow,
                     _event_param_mod_disallow, iter_nextfunc)

from _exc_types import *

NAS_mod = 0

try:
    if _pbs_v1.get_python_daemon_name() == "pbs_python":
        from _pbs_ifl import *
        from pbs_ifl import *
except:
    pass

# Set global hook_config_filename parameter.
hook_config_filename = None
try:
    import os

    if "PBS_HOOK_CONFIG_FILE" in os.environ:
        hook_config_filename = os.environ["PBS_HOOK_CONFIG_FILE"]
except:
    pass