Script xalt_syshost_in_py
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 from __future__ import print_function
30 import socket, platform
31
32
33
34
35 level1format = False
36
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
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
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
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