blob: 7c705fbe01e7e265ea2bbc92bc8da11c77894f56 (
plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/env python
'''This script updates to fully qualified hostnames for 0.6.11'''
__revision__ = '$Revision:$'
from ConfigParser import ConfigParser
from elementtree.ElementTree import XML, tostring
from socket import gethostbyname
from sys import argv
from glob import glob
from os import system
if __name__ == '__main__':
hostcache = {}
if len(argv) > 1:
domainlist = argv[-1].split(':')
else:
domainlist = ['mcs.anl.gov']
cf = ConfigParser()
cf.read(['/etc/bcfg2.conf'])
metadata = XML(open(cf.get('server', 'metadata') + '/metadata.xml').read())
for client in metadata.findall('.//Client'):
if client.get('name').count('.') == 0:
for dom in domainlist:
print "resolving name %s.%s..." % (client.get('name'), dom),
try:
hostinfo = gethostbyname(client.get('name') + '.' + dom)
hostcache[client.get('name')] = dom
client.set('name', "%s.%s" % (client.get('name'), dom))
print ""
break
except:
print "FAILED"
continue
print hostinfo
open(cf.get('server', 'metadata') + '/metadata.xml.new'), 'w').write(tostring(metadata))
sshdir = cf.get('server', 'repository') + '/SSHbase/'
for key in glob(sshdir + "*key.H_*"):
hostname = key.split('.H_')[1]
if not hostcache.has_key(hostname):
for dom in domainlist:
try:
hostinfo = gethostbyname(hostname + '.' + dom)
hostcache[hostname] = dom
break
except:
continue
if hostcache.has_key(hostname):
system("mv %s %s.%s" % (key, key, hostcache[hostname]))
|