Script xalt_syshost_in_py
[hide private]
[frames] | no frames]

Source Code for Script script-xalt_syshost_in_py

  1  # -*- python -*- 
  2  # 
  3  # Git Version: @git@ 
  4  # 
  5  # user defined function 
  6  # this is only an example that works at a couple sites 
  7  # 
  8   
  9  #----------------------------------------------------------------------- 
 10  # XALT: A tool that tracks users jobs and environments on a cluster. 
 11  # Copyright (C) 2013-2014 University of Texas at Austin 
 12  # Copyright (C) 2013-2014 University of Tennessee 
 13  #  
 14  # This library is free software; you can redistribute it and/or modify 
 15  # it under the terms of the GNU Lesser General Public License as 
 16  # published by the Free Software Foundation; either version 2.1 of  
 17  # the License, or (at your option) any later version.  
 18  # 
 19  # This library is distributed in the hope that it will be useful, 
 20  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 21  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 22  # Lesser  General Public License for more details.  
 23  # 
 24  # You should have received a copy of the GNU Lesser General Public 
 25  # License along with this library; if not, write to the Free 
 26  # Software Foundation, Inc., 59 Temple Place, Suite 330, 
 27  # Boston, MA 02111-1307 USA 
 28  #----------------------------------------------------------------------- 
 29  from __future__ import print_function 
 30  import socket, platform 
 31   
 32  # must set this to True or False depending on your naming scheme 
 33  # unless you plan to do a manual mapping of all your machine names 
 34  # see below for description of level1 and level2 
 35  level1format = False 
 36   
37 -def map_syshost(nameA):
38 """ 39 Use the nameA array to report a system name 40 """ 41 42 nicsT = { 43 "kraken" : "kraken", 44 "aprun-darter" : "darter", 45 "kid" : "kids", 46 "kfs" : "keeneland", 47 "titan" : "titan", 48 "nid00026" : "mars", 49 "nid00027" : "mars", 50 "nid00043" : "mars", 51 "nid00053" : "mars", 52 "verne" : "verne", 53 "nautilus" : "nautilus", 54 "conseil" : "nautilus", 55 "arronax" : "nautilus", 56 "harpoon" : "nautilus", 57 } 58 result = None 59 60 for name in nameA: 61 for k in nicsT: 62 if (name.find(k,0) != -1): 63 result = nicsT[k] 64 return result 65 return result
66
67 -def level1_syshost(nameA):
68 """ 69 Returns the 1st level xx of the xx.yy.zz.ww hostname name. 70 Useful for naming conventions like 71 machine1.dept.institute.edu 72 where you want to return the machine name without the number. 73 74 use the platform.node result provided in nameA array 75 and strip off trailing numbers 76 77 """ 78 79 80 name = nameA[1].rstrip('1234567890') 81 return name
82
83 -def level2_syshost(nameA):
84 """ 85 Returns the 2nd level yy of the xx.yy.zz.ww hostname name. 86 Useful for naming conventions like 87 login1.machine.site.edu 88 where you want to return the machine name. 89 90 """ 91 92 maxN = 0 93 j = -1 94 i = -1 95 for name in nameA: 96 i = i + 1 97 hostA = name.split('.') 98 num = len(hostA) 99 if (num > maxN): 100 j = i 101 maxN = num 102 hostA = nameA[j].split('.') 103 104 idx = 1 105 if (len(hostA) < 2): 106 idx = 0 107 return hostA[idx]
108
109 -def main():
110 """ 111 This command tries to report the system name base on host name information. 112 It should return darter and not login1.darter. 113 """ 114 115 nameA = [ socket.getfqdn(), 116 platform.node() ] 117 118 syshost = map_syshost(nameA) 119 if (not syshost): 120 if (level1format): 121 syshost = level1_syshost(nameA) 122 else: 123 syshost = level2_syshost(nameA) 124 125 print(syshost)
126 127 128 if ( __name__ == '__main__'): main() 129