Package park :: Package util :: Module _torque

Source Code for Module park.util._torque

  1  # 
  2  #         OpenPBS (Portable Batch System) v2.3 Software License 
  3  # 
  4  # Copyright (c) 1999-2000 Veridian Information Solutions, Inc. 
  5  # All rights reserved. 
  6  # 
  7  # --------------------------------------------------------------------------- 
  8  # For a license to use or redistribute the OpenPBS software under conditions 
  9  # other than those described below, or to purchase support for this software, 
 10  # please contact Veridian Systems, PBS Products Department ("Licensor") at: 
 11  # 
 12  #    www.OpenPBS.org  +1 650 967-4675                  sales@OpenPBS.org 
 13  #                        877 902-4PBS (US toll-free) 
 14  # --------------------------------------------------------------------------- 
 15  # 
 16  # This license covers use of the OpenPBS v2.3 software (the "Software") at 
 17  # your site or location, and, for certain users, redistribution of the 
 18  # Software to other sites and locations.  Use and redistribution of 
 19  # OpenPBS v2.3 in source and binary forms, with or without modification, 
 20  # are permitted provided that all of the following conditions are met. 
 21  # After December 31, 2001, only conditions 3-6 must be met: 
 22  # 
 23  # 1. Commercial and/or non-commercial use of the Software is permitted 
 24  #    provided a current software registration is on file at www.OpenPBS.org. 
 25  #    If use of this software contributes to a publication, product, or 
 26  #    service, proper attribution must be given; see www.OpenPBS.org/credit.html 
 27  # 
 28  # 2. Redistribution in any form is only permitted for non-commercial, 
 29  #    non-profit purposes.  There can be no charge for the Software or any 
 30  #    software incorporating the Software.  Further, there can be no 
 31  #    expectation of revenue generated as a consequence of redistributing 
 32  #    the Software. 
 33  # 
 34  # 3. Any Redistribution of source code must retain the above copyright notice 
 35  #    and the acknowledgment contained in paragraph 6, this list of conditions 
 36  #    and the disclaimer contained in paragraph 7. 
 37  # 
 38  # 4. Any Redistribution in binary form must reproduce the above copyright 
 39  #    notice and the acknowledgment contained in paragraph 6, this list of 
 40  #    conditions and the disclaimer contained in paragraph 7 in the 
 41  #    documentation and/or other materials provided with the distribution. 
 42  # 
 43  # 5. Redistributions in any form must be accompanied by information on how to 
 44  #    obtain complete source code for the OpenPBS software and any 
 45  #    modifications and/or additions to the OpenPBS software.  The source code 
 46  #    must either be included in the distribution or be available for no more 
 47  #    than the cost of distribution plus a nominal fee, and all modifications 
 48  #    and additions to the Software must be freely redistributable by any party 
 49  #    (including Licensor) without restriction. 
 50  # 
 51  # 6. All advertising materials mentioning features or use of the Software must 
 52  #    display the following acknowledgment: 
 53  # 
 54  #     "This product includes software developed by NASA Ames Research Center, 
 55  #     Lawrence Livermore National Laboratory, and Veridian Information 
 56  #     Solutions, Inc. 
 57  #     Visit www.OpenPBS.org for OpenPBS software support, 
 58  #     products, and information." 
 59  # 
 60  # 7. DISCLAIMER OF WARRANTY 
 61  # 
 62  # THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ANY EXPRESS 
 63  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
 64  # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT 
 65  # ARE EXPRESSLY DISCLAIMED. 
 66  # 
 67  # IN NO EVENT SHALL VERIDIAN CORPORATION, ITS AFFILIATED COMPANIES, OR THE 
 68  # U.S. GOVERNMENT OR ANY OF ITS AGENCIES BE LIABLE FOR ANY DIRECT OR INDIRECT, 
 69  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 70  # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 71  # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 72  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 73  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 74  # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 75  # 
 76  # This license will be governed by the laws of the Commonwealth of Virginia, 
 77  # without reference to its choice of law rules. 
 78  # 
 79   
 80  # Wrapped by Paul Kienzle 
 81  # This wrapper is public domain 
 82   
 83  import os 
 84  import sys 
 85  from ctypes import * 
 86   
87 -class TorqueLibError(Exception): pass
88
89 -def find_torque():
90 """ 91 Load the library whereever it may be. 92 """ 93 # PBSLIB takes precedence 94 if 'PBSLIB' in os.environ: 95 file = os.environ['PBSLIB'] 96 if not os.path.isfile(file): 97 raise TorqueLibError, \ 98 "PBS library PBSLIB=%s does not exist"%(file) 99 files = [file] 100 else: 101 files = [] 102 103 # Default names and locations to look for the library are system dependent 104 filedir = os.path.dirname(__file__) 105 if sys.platform in ('win32','cygwin'): 106 files += [filedir+"/libtorque.dll"] 107 else: 108 if sys.platform in ('darwin'): 109 lib = 'libtorque.dylib' 110 ldenv = 'DYLD_LIBRARY_PATH' 111 else: 112 lib = 'libtorque.so' 113 ldenv = 'LD_LIBRARY_PATH' 114 # Search the load library path as well as the standard locations 115 ldpath = [p for p in os.environ.get(ldenv,'').split(':') if p != ''] 116 stdpath = [ '/usr/local/lib', '/usr/lib'] 117 files += [os.path.join(p,lib) for p in [filedir]+ldpath+stdpath] 118 119 # Given a list of files, try loading the first one that is available. 120 for file in files: 121 if not os.path.isfile(file): continue 122 try: 123 return cdll[file] 124 except: 125 raise TorqueLibError, \ 126 "PBS library %s could not be loaded: %s"%(file,sys.exc_info()[0]) 127 raise TorqueLibError, "PBS library missing; set PBSLIB or move it to one of:\n %s"%("\n ".join(files))
128 129 130 torque = find_torque() 131 132 133 # The remainder of this file is a pretty direct translation of pbs_ifl.h 134
135 -class attrl(Structure): pass
136 attrl._fields_ = [("next",POINTER(attrl)), 137 ("name",c_char_p), 138 ("resouce",c_char_p), 139 ("value", c_char_p), 140 ("batch_op", c_int), 141 ] 142 attropl = attrl 143
144 -class batch_status(Structure): pass
145 batch_status._fields_ = [("next",POINTER(batch_status)), 146 ("name",c_char_p), 147 ("attribs",POINTER(attrl)), 148 ("text",c_char_p), 149 ] 150
151 -class batch_op:
152 (SET,UNSET,INCR,DECR, 153 EQ,NE,GE,GT,LE,LT, 154 DFLT) = [c_int(i) for i in range(11)]
155 - def byname(self, name):
156 return getattr(self, name.upper())
157 158 159 # Attribute Names used by user commands 160 ATTR_user = [ 161 "Execution_Time", 162 "Checkpoint", 163 "Error_Path", 164 "group_list", 165 "Hold_Types", 166 "Join_Path", 167 "Keep_Files", 168 "Resource_List", 169 "Mail_Points", 170 "Output_Path", 171 "Priority", 172 "destination", 173 "Rerunable", 174 "job_array_request", 175 "job_array_id", 176 "User_List", 177 "Variable_List", 178 "Account_Name", 179 "Mail_Users", 180 "Job_Name", 181 "Shell_Path_List", 182 "depend", 183 "interactive", 184 "stagein", 185 "stageout", 186 ] 187 188 # additional job and general attribute names 189 ATTR_job = [ 190 "ctime", 191 "exec_host", 192 "mtime", 193 "qtime", 194 "session_id", 195 "euser", 196 "egroup", 197 "hashname", 198 "hop_count", 199 "security", 200 "sched_hint", 201 "substate", 202 "Job_Name", 203 "Job_Owner", 204 "resources_used", 205 "job_state", 206 "queue", 207 "server", 208 "max_running", 209 "max_report", 210 "total_jobs", 211 "comment", 212 "cookie", 213 "queue_rank", 214 "alt_id", 215 "etime", 216 "exit_status", 217 "forward_x11", 218 "submit_args", 219 "tokens", 220 "net_counter", 221 "umask", 222 "start_time", 223 "start_count", 224 "checkpoint_dir", # user specified directory for checkpoint files 225 "checkpoint_name", # user specified name of checkpoint file 226 ] 227 228 # additional queue attributes names 229 ATTR_queue = [ 230 "acl_group_enable", 231 "acl_groups", 232 "acl_host_enable", 233 "acl_hosts", 234 "acl_user_enable", 235 "acl_users", 236 "alt_router", 237 "checkpoint_min", 238 "enabled", 239 "from_route_only", 240 "hostlist", # TORQUE only 241 "kill_delay", 242 "max_group_run", 243 "max_queuable", 244 "max_user_queuable", 245 "max_user_run", 246 "queue_type", 247 "resources_assigned", 248 "resources_default", 249 "resources_max", 250 "resources_min", 251 "restartable", # TORQUE only 252 "rendezvous_retry", 253 "route_destinations", 254 "route_held_jobs", 255 "route_waiting_jobs", 256 "route_retry_time", 257 "route_lifetime", 258 "reserved_expedite", 259 "reserved_sync", 260 "started", 261 "state_count", 262 "number_jobs", 263 "acl_logic_or", 264 "acl_group_sloppy", 265 "keep_completed", 266 "disallowed_types", 267 ] 268 269 # additional server attributes names 270 271 # NOTE: steps for adding new attribute described in ??? 272 # - create #define ATTR_* in include/pbs_ifl.h 273 # - insert SRV_ATR_* in include/server.h 274 # - add SRV_ATR_* in include/qmgr_svr_public.h 275 # - insert structure in server/svr_attr_def.c 276 # NOTE: structure must be in same relative position as SRV_ATR_* 277 # - insert usage code in proper location 278 ATTR_server = [ 279 "acl_roots", 280 "managers", 281 "default_queue", 282 "default_node", 283 "location_servers", 284 "log_events", 285 "log_file", 286 "log_level", 287 "mail_from", 288 "node_pack", 289 "node_suffix", 290 "operators", 291 "query_other_jobs", 292 "resources_cost", 293 "resources_available", 294 "scheduler_iteration", 295 "scheduling", 296 "server_state", 297 "system_cost", 298 "node_ping_rate", 299 "node_check_rate", 300 "tcp_timeout", 301 "job_stat_rate", 302 "poll_jobs", 303 "down_on_error", 304 "disable_server_id_check", 305 "job_nanny", 306 "owner_purge", 307 "queue_centric_limits", 308 "mom_job_sync", 309 "mail_domain", 310 "pbs_version", 311 "submit_hosts", 312 "allow_node_submit", 313 "allow_proxy_user", 314 "auto_node_np", 315 "server_name", 316 "log_file_max_size", 317 "log_file_roll_depth", 318 "next_job_number", 319 "extra_resc", 320 "sched_version", 321 ] 322 323 # additional node "attributes" names 324 ATTR_node = [ 325 "state", 326 "np", 327 "properties", 328 "ntype", 329 "jobs", 330 "status", 331 "note", 332 ] 333 334 335 # various attribute values 336 337 CHECKPOINT_UNSPECIFIED="u" 338 NO_HOLD="n" 339 NO_JOIN="n" 340 NO_KEEP="n" 341 MAIL_AT_ABORT="a" 342 343 344 DELDELAY = "deldelay=" 345 DELPURGE = "delpurge=" 346 EXECQUEONLY = "exec_queue_only" 347 RERUNFORCE = "force" 348 349 USER_HOLD = "u" 350 OTHER_HOLD = "o" 351 SYSTEM_HOLD = "s" 352 353 # node-attribute values (state,ntype) 354 ND = [ 355 "free", 356 "offline", 357 "down", 358 "reserve", 359 "job-exclusive", 360 "job-sharing", 361 "busy", 362 "state-unknown", 363 "time-shared", 364 "cluster", 365 ] 366 367 # queue disallowed types 368 Q_DT = [ 369 "batch", 370 "interactive", 371 "rerunable", 372 "nonrerunable", 373 ] 374 375 #constant related to sum of string lengths for above strings 376 MAX_ENCODE_BFR = 100 377 378 MGR_CMD_CREATE = 0 379 MGR_CMD_DELETE = 1 380 MGR_CMD_SET = 2 381 MGR_CMD_UNSET = 3 382 MGR_CMD_LIST = 4 383 MGR_CMD_PRINT = 5 384 MGR_CMD_ACTIVE = 6 385 386 MGR_OBJ_NONE = -1 387 MGR_OBJ_SERVER = 0 388 MGR_OBJ_QUEUE = 1 389 MGR_OBJ_JOB = 2 390 MGR_OBJ_NODE = 3 391 392 # Misc defines for various requests 393 394 MSG_OUT = 1 395 MSG_ERR = 2 396 397 SHUT_SIG = -1 398 SHUT_IMMEDIATE = 0 399 SHUT_DELAY = 1 400 SHUT_QUICK = 2 401 402 SIG_RESUME = "resume" 403 SIG_SUSPEND = "suspend" 404 405 PBS_MAXHOSTNAME = 64 # max host name length 406 MAXPATHLEN = 1024 # max path name length 407 MAXNAMLEN = 255 408 MAX_NOTE = 256 # max node note length 409 MAX_NOTE_STR = "256" # max node note length as a string literal (this MUST match MAX_NOTE) 410 411 PBS_MAXUSER = 16 # max user name length 412 PBS_MAXGRPN = 16 # max group name length 413 PBS_MAXQUEUENAME = 15 # max queue name length 414 PBS_MAXSERVERNAME = PBS_MAXHOSTNAME # max server name length 415 PBS_MAXJOBARRAYLEN = 6 # number of characters allowed in jobarray portion of job id, including '-' 416 PBS_MAXSEQNUM = 8 # max sequence number length 417 PBS_MAXPORTNUM = 5 # udp/tcp port numbers max=16 bits 418 PBS_MAXJOBARRAY = 99999 419 PBS_MAXSVRJOBID = (PBS_MAXSEQNUM + PBS_MAXSERVERNAME + PBS_MAXPORTNUM + PBS_MAXJOBARRAYLEN + 2 ) # server job id size 420 PBS_MAXCLTJOBID = (PBS_MAXSVRJOBID + PBS_MAXSERVERNAME + PBS_MAXPORTNUM + PBS_MAXJOBARRAYLEN + 2) # client job id size 421 PBS_MAXDEST = 1024 # destination size -- increased from 256 422 PBS_MAXROUTEDEST = (PBS_MAXQUEUENAME + PBS_MAXSERVERNAME + PBS_MAXPORTNUM + 2) # destination size 423 PBS_USE_IFF = 1 # pbs_connect() to call pbs_iff 424 PBS_INTERACTIVE = 1 # Support of Interactive jobs 425 PBS_TERM_BUF_SZ = 80 # Interactive term buffer size 426 PBS_TERM_CCA = 6 # Interactive term cntl char array 427 428 # magic number used to determine version of pbs job quick save struct 429 # the magic number is split into 4 8-bit chunks. the first 8 bits are 430 # unused. the second b bits represent the major version number 431 # third 8 bits are the minor version, and the final 8 bits are the 432 # bug fix version. we write the torque version that the job qs struct 433 # was last changed in this constant writing them as if they are two 434 # digit decimal numbers. all that really matters is that we assign a 435 # unique value for each change in the ji_qs struct and that it can't 436 # be confused with data at the start of a ji_qs struct from before 437 # torque version 2.2.0 438 PBS_QS_VERSION = 0x00020300 439 440 ## someday the PBS_*_PORT definition will go away and only the 441 ## PBS_*_SERVICE_NAME form will be used, maybe 442 443 PBS_BATCH_SERVICE_NAME = "pbs" 444 PBS_BATCH_SERVICE_PORT = 15001 445 PBS_BATCH_SERVICE_NAME_DIS = "pbs_dis" # new DIS port 446 PBS_BATCH_SERVICE_PORT_DIS = 15001 # new DIS port 447 PBS_MOM_SERVICE_NAME = "pbs_mom" 448 PBS_MOM_SERVICE_PORT = 15002 449 PBS_MANAGER_SERVICE_NAME = "pbs_resmon" 450 PBS_MANAGER_SERVICE_PORT = 15003 451 PBS_SCHEDULER_SERVICE_NAME = "pbs_sched" 452 PBS_SCHEDULER_SERVICE_PORT = 15004 453 454 455 resource_t = c_int 456 457 RESOURCE_T_NULL = resource_t(0) 458 RESOURCE_T_ALL = resource_t(-1) 459 460 # extern int pbs_errno; # error number 461 _pbs_errno = c_int.in_dll(torque, "pbs_errno")
462 -def pbs_errno(): return _pbs_errno.value
463 # extern char *pbs_server; # server attempted to connect | connected to 464 465 # extern char *avail(int connect,char *resc); 466 avail = torque.avail 467 avail.restype = c_char_p 468 avail.argtypes = [c_int,c_char_p] 469 # Deprecated. See pbs_rescquery 470 471 # extern int pbs_asyrunjob(int c,char *jobid,char *location,char *extend); 472 pbs_asyrunjob = torque.pbs_asyrunjob 473 pbs_asyrunjob.argtypes = [c_int, c_char_p, c_char_p, c_char_p] 474 475 # extern int pbs_runjob(int c,char *jobid,char *location,char *extend); 476 pbs_runjob = torque.pbs_runjob 477 pbs_runjob.argtypes = [c_int, c_char_p, c_char_p, c_char_p] 478 479 # extern int pbs_alterjob(int connect,char *job_id,struct attrl *attrib,char *extend); 480 pbs_alterjob = torque.pbs_alterjob 481 pbs_alterjob.argtypes = [c_int, c_char_p, POINTER(attrl), c_char_p] 482 483 #extern int pbs_connect(char *server) 484 pbs_connect = torque.pbs_connect 485 pbs_connect.argtypes = [c_char_p] 486 487 #extern int pbs_query_max_connections(); 488 pbs_query_max_connections = torque.pbs_query_max_connections 489 pbs_query_max_connections.argtypes = [] 490 491 #extern char *pbs_default(void) 492 pbs_default = torque.pbs_default 493 pbs_default.argtypes = [] 494 495 # From pbs_error.h 496 #extern char * pbs_strerror(int errno) 497 pbs_strerror = torque.pbs_strerror 498 pbs_strerror.restype = c_char_p 499 pbs_strerror.argtypes = [c_int] 500 501 #extern int pbs_deljob(int connect,char *job_id,char *extend) 502 pbs_deljob = torque.pbs_deljob 503 pbs_deljob.argtypes = [c_int, c_char_p, c_char_p] 504 505 #extern int pbs_disconnect(int connect) 506 pbs_disconnect = torque.pbs_disconnect 507 pbs_disconnect.argtypes = [c_int] 508 509 # extern char * 510 # pbs_submit (int connect, struct attropl *attrib, char *script, 511 # char *destination, char *extend); 512 pbs_submit = torque.pbs_submit 513 pbs_submit.restype = c_char_p 514 pbs_submit.argtypes = [c_int, POINTER(attropl), c_char_p, c_char_p, c_char_p] 515 516 517 518 _ = """ 519 extern char *pbs_geterrmsg(int connect) 520 extern int pbs_holdjob(int connect,char *job_id,char *hold_type,char *extend) 521 extern char *pbs_locjob(int connect,char *job_id,char *extend) 522 523 extern char *pbs_fbserver(void) 524 extern int csv_length( char *str ) 525 extern char *csv_nth( char *str, int n ) 526 extern char *pbs_get_server_list(void) 527 528 extern int 529 pbs_manager (int connect, int command, int obj_type, char *obj_name, 530 struct attropl *attrib, char *extend); 531 532 extern int 533 pbs_movejob(int connect, char *job_id, char *destination, char *extend) 534 535 extern int 536 pbs_msgjob (int connect, char *job_id, int file, char *message, 537 char *extend); 538 539 extern int 540 pbs_orderjob(int connect, char *job1, char *job2, char *extend) 541 542 extern int 543 pbs_rescquery (int connect, char **rlist, int nresc, int *avail, 544 int *alloc, int *resv, int *down); 545 546 extern int 547 pbs_rescreserve(int connect, char **rlist, int nresc, resource_t *phandle) 548 549 extern int 550 pbs_rescrelease(int connect, resource_t rhandle) 551 552 extern int 553 pbs_rerunjob(int connect, char *job_id, char *extend) 554 555 extern int 556 pbs_rlsjob(int connect, char *job_id, char *hold_type, char *extend) 557 558 extern char ** 559 pbs_selectjob(int connect, struct attropl *select_list, char *extend) 560 561 extern int 562 pbs_sigjob(int connect, char *job_id, char *signal, char *extend) 563 564 extern void 565 pbs_statfree( struct batch_status *stat ) 566 567 extern struct batch_status * 568 pbs_statdest(int connect, char *id, char *extend) 569 570 extern struct batch_status * 571 pbs_statjob(int connect, char *id, struct attrl *attrib, char *extend) 572 573 extern struct batch_status * 574 pbs_selstat(int connect, struct attropl *select_list, char *extend) 575 576 extern struct batch_status * 577 pbs_statque(int connect, char *id, struct attrl *attrib, char *extend) 578 579 extern struct batch_status * 580 pbs_statserver(int connect, struct attrl *attrib, char *extend) 581 582 extern struct batch_status * 583 pbs_statnode(int connect, char *id, struct attrl *attrib, char *extend) 584 585 extern int 586 pbs_terminate(int connect, int manner, char *extend) 587 588 extern int 589 totpool(int connect, int update) 590 591 extern int 592 usepool(int connect, int update) 593 """ 594
595 -def demo():
596 c = pbs_connect(None) 597 pbs_disconnect(c)
598 599 if __name__ == "__main__": 600 demo() 601